616 Commits

Author SHA1 Message Date
Rob Kiefer
30d1483adb Prepare the repo for next development cycle 2017-11-30 11:33:43 -05:00
Rob Kiefer
00c979112d Release 0.7.1 (on master) 2017-11-30 11:33:43 -05:00
Matvey Arye
72b612cb7a Fix migration script 2017-11-30 11:33:43 -05:00
Matvey Arye
2c2aba8fad Fix installchecklocal
Remove user from regression tests so that the local test will work.
The tests itself will still be run with the appropriate user because
of the logic in runner.sh.
2017-11-27 16:28:51 -05:00
Matvey Arye
8b772be994 Change time handling in drop_chunks for TIMESTAMP times
This PR fixes the handling of drop_chunks when the hypertable's
time field is a TIMESTAMP or DATE field. Previously, such
hypertables needed drop_chunks to be given a timestamptz in UTC.
Now, drop_chunks can take a DATE or TIMESTAMP. Also, the INTERVAL
version of drop_chunks correctly handles these cases.

A consequence of this change is that drop_chunks cannot be called
on multiple tables (with table_name = NULL or schema_name = NULL)
if the tables have different time column types.
2017-11-27 16:17:42 -05:00
Rob Kiefer
66396fb81e Add build support for Windows
Windows 64-bit binaries should now be buildable using the cmake
build system either from the command line or from Visual Studio.

Previous issues regarding unresolved symbols have been resolved
with compatibility header files to properly export symbols or
getting GUCs via normal APIs.
2017-11-27 12:04:44 -05:00
Erik Nordström
c7cc9114b4 Do not append-optimize plans with result relations (DELETE/UPDATE)
Plans that have a result relation set (DELETE or UPDATE) should
not optimize subplans that contain append nodes. This is because
the PostgreSQL must turn such plans on an inheritance table into
a set of similar plans on each subtable (i.e., it needs to apply
UPDATE and DELETE to each subtable and not just the parent).

Optimizing such plans with, e.g., ConstraintAwareAppend makes
the planner believe it only needs to do the DELETE or UPDATE
on the root table, which means rows in subtables won't be affected.
2017-11-27 17:40:08 +01:00
Erik Nordström
e1a0e819cf Refactor and fix cache invalidation
TimescaleDB cache invalidation happens as a side effect of doing a
full SQL statement (INSERT/UPDATE/DELETE) on a catalog table (via
table triggers). However, triggers aren't invoked when using
PostgreSQL's internal catalog API for updates, since PostgreSQL's
catalog tables don't have triggers that require full statement
parsing, planning, and execution.

Since we are now using the regular PostgreSQL catalog update API for
some TimescaleDB catalog operations, we need to do cache invalidation
also on such operations.

This change adds cache invalidation when updating catalogs using the
internal (C) API and also makes the cache invalidation more fine
grained. For instance, caches are no longer invalidated on some
INSERTS that do not affect the validity of objects already in the
cache, such as adding a new chunk.
2017-11-27 17:33:10 +01:00
Erik Nordström
7b299fa05f Handle empty append plans in ConstraintAwareAppend
Append plans that are empty (no children) are replaced at planning-
time with a Result plan node that returns nothing. Such Result nodes
occur typically when querying outside the time range covered by chunks.
However, the ConstraintAwareAppend plan node did not handle the
case of a Result child node, instead expecting either an Append or
MergeAppend node. This is now fixed so that encountering a Result node
means doing nothing.
2017-11-27 17:24:15 +01:00
Erik Nordström
1e947da456 Permission fixes and allow SET ROLE
This change reduces the usage of SECURITY DEFINER on SQL
functions and fixes related permissions issues. It also
properly checks hypertable permissions relative the current_user
instead of the session_user, which otherwise breaks SET ROLE,
among other things.
2017-11-27 15:55:26 +01:00
Erik Nordström
a2b78aea1b Fix reindex test
The reindex test outputs the OID of a cloned index. This OID might
change with the state of the database, added tests, etc., causing
frequent test failures. The test is now updated to output the name of
the index instead of the OID.
2017-11-22 16:14:10 +01:00
Erik Nordström
33b260225e Fix pgindent on first CMake run
This changes the order in which subdirectories are processed in the
top-level CMakeLists.txt file, so that dependencies from the scripts/
dir are set when processing the src/ dir. Otherwise, the `pgindent`
target won't be enabled on the first CMake run.
2017-11-22 15:57:23 +01:00
Rob Kiefer
32b90e5e03 Prepare the repo for next development cycle 2017-11-21 23:52:59 -05:00
Rob Kiefer
f0d69f6084 Release 0.7.0 0.7.0 2017-11-21 14:37:57 -05:00
Matvey Arye
13e1cb5343 Add reindex function
reindex allows you to reindex the indexes of only certain chunks,
filtering by time. This is a common use case because a user may
want to reindex chunks after they are no longer getting new data once.

reindex also has a recreate option which will not use REINDEX
but will rather CREATE INDEX a new index and then
DROP INDEX / RENAME new_index to old_name. This approach has advantages
in terms of blocking reads for a much shorter period of time. However,
it does more work and will use more disk space during the operation.
2017-11-21 14:08:57 -05:00
jwdeitch
6594018e32 Handle when create_hypertable is invoked on partitioned table
- create_hypertable will raise exception on invocation
2017-11-21 12:28:16 -05:00
Matvey Arye
818bdbc31b Add coverity testing 2017-11-20 15:18:56 -05:00
Erik Nordström
5d0cbc12fd Recurse CLUSTER command to chunks
Clustering a table means reordering it according to an index.
This operation requires an exclusive lock and extensive
processing time. On large hypertables with many chunks, CLUSTER
risks blocking a lot of operations by holding locks for a long time.
This is alleviated by processing each chunk in a new transaction,
ensuring locks are only held on one chunk at a time.
2017-11-20 20:15:43 +01:00
Matvey Arye
9c7191e898 Change TIMESTAMP partitioning to be completely tz-independent
Previously, for timezones w/o tz. The range_end and range_start were
defined as UTC, but the constraints on the table were written as as
the local time at the time of chunk creation. This does not work well
if timezones change over the life of the hypertable.

This change removes the dependency on local time for all timestamp
partitioning. Namely, the range_start and range_end remain as UTC
but the constraints are now always written in UTC too. Since old
constraints correctly describe the data currently in the chunks, the
update script to handle this change changes range_start and range_end
instead of the constraints.

Fixes #300.
2017-11-20 09:27:30 -05:00
Erik Nordström
741b25662e Mark IMMUTABLE functions as PARALLEL SAFE
Functions marked IMMUTABLE should also be parallel safe, but
aren't by default. This change marks all immutable functions
as parallel safe and removes the IMMUTABLE definitions on
some functions that have been wrongly labeled as IMMUTABLE.

If functions that are IMMUTABLE does not have the PARALLEL SAFE
label, then some standard PostgreSQL regression tests will fail
(this is true for PostgreSQL >= 10).
2017-11-17 20:24:30 +01:00
Erik Nordström
2ffb30d990 Make aggregate serialize and deserialize functions STRICT
Aggregate functions that have serialize and deserialize support
functions (histogram, last, first, etc.) should have these
support functions marked STRICT.

PostgreSQL's regular test suite will fail when the timescaledb
module is loaded without these functions being marked STRICT.
2017-11-17 20:24:30 +01:00
Olof Rensfelt
c552410f69 Add build target to run the standard PostgreSQL regression tests
To verify that PostgreSQL operations on regular tables are unaffected by
the TimescaleDB extension, the regular PostgreSQL regression tests can be
run with the TimescaleDB extension loaded.

To enable the build target (`pginstallcheck`), one needs to set the
CMake `PG_SOURCE_DIR` variable to point to the PostgreSQL source code, which
needs to have at least the regression test suite compiled.

The PostgreSQL tests suite will run on every Travis build.
2017-11-17 20:24:30 +01:00
Matvey Arye
291050b395 Change DATE partitioning to be completely tz-independent
The insert logic in time_value_to_internal was not tz independent,
causing problems with date in some timezones. This is now fixed.

Fixes #306.
2017-11-17 12:08:40 -05:00
Erik Nordström
ca0968aaa0 Make all partitioning functions take anyelement argument
All partitioning functions now has the signature `int func(anyelement)`.
This cleans up some special handling that was necessary to support
the legacy partitioning function that expected text input.
2017-11-17 17:59:16 +01:00
Erik Nordström
0497744803 Fix compilation warning in copy code
This change fixes a compilation warning in the
copy code that was introduced with an earlier
refactoring PR.
2017-11-17 09:49:19 +01:00
Erik Nordström
e6936cbfa5 Make warnings into errors in Travis build
Builds will now fail in Travis if a warning is
raised.
2017-11-17 09:49:19 +01:00
Erik Nordström
69d7d5800c Add pgindent target to format C source
The C source files can now be formatted with pgindent using
a new CMake build target.

The location of pgindent and dependencies are auto-discovered
by CMake or can be overridden on the command line.
2017-11-17 09:43:04 +01:00
Matvey Arye
a4e1e32d02 Change range_start and range_end semantics
We now use INT64_MAX and INT64_MIN as the max and min values for
dimension_slice ranges. If a dimension_slice has a range_start of
INT64_MIN or the range_end is INT64_MAX, we remove the corresponding
check constraint on the chunk since it signifies that this end of the
range is infinite. Closed ranges now always have INT64_MIN as range_end
of first slice and range_end of INT64_MAX for the last slice.
Also, points corresponding to INT64_MAX are always
put in the same slice as INT64_MAX-1 to avoid problems with the
semantics that coordinate < range_end.
2017-11-14 08:00:10 -08:00
Matvey Arye
2dfbc829b0 Fix off-by-one error on range-end
A hash function can have the value 2147483647, so range_end has to be
2147483648.
2017-11-14 08:00:10 -08:00
Matvey Arye
5be7521a0b Implement changes suggested by coverity analysis 2017-11-13 11:31:16 -05:00
Matvey Arye
959034642e Remove code related to COPY TO statements
Refactor the copy code to get rid of the NOT is_from path. This
removes a lot of confusing dead code.
2017-11-13 11:25:39 -05:00
Erik Nordström
500563ffe5 Add support for PostgreSQL 10
The extension now works with PostgreSQL 10, while
retaining compatibility with version 9.6.

PostgreSQL 10 has numerous internal changes to functions and
APIs, which necessitates various glue code and compatibility
wrappers to seamlessly retain backwards compatiblity with older
versions.

Test output might also differ between versions. In particular,
the psql client generates version-specific output with `\d` and
EXPLAINs might differ due to new query optimizations. The test
suite has been modified as follows to handle these issues. First,
tests now use version-independent functions to query system
catalogs instead of using `\d`. Second, changes have been made to
the test suite to be able to verify some test outputs against
version-dependent reference files.
2017-11-10 09:44:20 +01:00
Erik Nordström
bd36e6d020 Move SQL source file lists to CMakeLists.txt
SQL source files that are joined together were
previously listed in the `load_order.txt` and
`extra_extension_files.txt` files. These SQL file list
were then read by CMake. However, since no dependencies
existed on these list files in Make targets, the project
was not automatically rebuilt if the lists were updated.

This change moves the lists directly to the CMakeLists.txt
file, ensuring that the project is properly rebuilt every
time the lists are updated.
2017-11-10 09:37:45 +01:00
Rob Kiefer
10fa207a12 Prepare the repo for next development cycle 2017-11-07 21:16:58 -05:00
Rob Kiefer
325556e6ac Release 0.6.1 2017-11-07 21:16:58 -05:00
Matvey Arye
73f0d75882 Fix EXPLAIN for ConstraintAware and MergeAppend
This fixes a bug with an explain for ConstraintAware plans
when all chunks were excluded and a MergeAppend was used.
The problem was that the EXPLAIN output for MergeAppend nodes
expected at least one child to print the sorting column info.
When all chunks were excluded there are no children. This
PR removes all child execution states from the ConstraintAware
node when all chunks are excluded.
2017-11-06 15:57:08 -05:00
Erik Nordström
bc595c1826 Use per-chunk memory context for cached chunks
The chunk cache needs to free chunk memory as
it evicts chunks from the cache. This was previously
done by pfree:ing the chunk memory, but this didn't
account for sub-allocated objects, like the chunk's
hypercube. This lead to some chunk objects remaining
in the cache's memory context, thus inflating memory
usage, although the objects were no longer associated
with a chunk.

This change adds a per-chunk memory context in the cache
that allows all chunk memory to be easily freed when
the cache entry is evicted or when the chunk cache
is destroyed.
2017-11-06 14:38:12 +01:00
Olof Rensfelt
201a948452 Check that time dimensions are set as NOT NULL.
Add check that time dimensions are set as NOT NULL in the
main table that a hypertable is created from. If it is not
set, the constraint will be added.
2017-11-02 09:12:15 +01:00
Erik Nordström
1dd1e4f001 Do not convert tuples on insert unless needed
When inserting tuples into a chunk, the tuples are converted to chunk
table format if the chunk's attributes differ from the parent
table's. This can happen if, e.g., the parent table has had one of its
columns removed, leading to a garbage attribute that is not inherited
by new chunks.

Unfortunately, PostgreSQL compares the typeid of tuples to decide if
tuple conversion is needed, while also creating a new typeid for every
table (including child tables). This results in tuple conversion
occurring between a parent and a child table, even if not strictly
needed.

This optimization adds an extra check that avoids tuple conversion
when not needed. Note that this updated check is also in recent
PostgreSQL versions (>= PG10), so it won't strictly be needed when
running on those versions.
2017-10-31 14:11:19 +01:00
Erik Nordström
5de6abfa85 Fix assertion assignment bug
This fixes two assertion statements in the subspace store. The first
fix is for an assigment that occurred in the assertion instead of an
equality comparison. The other is just a cleanup to remove an
unnecessary if-statement.
2017-10-31 14:11:19 +01:00
Erik Nordström
dd64b2a894 Limit growth of range table during chunk inserts
Everytime a new chunk insert state is created, a new range table entry
is also created in the executor's range table. This change ensures
that a range table entry is reused in case one already exists for a
chunk that has been closed and reopened again in the same transaction.
This can happen if the chunk insert state is evicted from its
associated cache due to out-of-order inserts. Thus, this will limit
the growth of the range table to at most the number of chunks in the
hypertable.
2017-10-31 14:11:19 +01:00
Erik Nordström
4532650411 Allow setting partitioning function
Users might want to implement their own partitioning function
or use the legacy one included with TimescaleDB. This change
adds support for setting the partitioning function in
create_hypertable() and add_dimension().
2017-10-31 10:20:52 +01:00
Erik Nordström
4a0a0d8253 Fix column type change on plain tables
A recent change blocked changing types of space-partitioned hypertable
columns. However, this blocking should not apply to regular tables,
which otherwise causes a crash. This change fixes this issue by
properly checking that the the table is a hypertable.
2017-10-30 14:54:37 +01:00
Erik Nordström
cf009cc584 Avoid string conversion in hash partitioning
Hash partitioning previously relied on coercing (casting) values to
strings before calculating a hash value, including creating CHECK
constraints with casts. This approach is fairly suboptimal from a
performance perspective and might have issues related to different
character encodings depending on system.

Hash partitioning now instead uses a partitioning function that takes
an anyelement type that calls type-dependent hash functions internal
to PostgreSQL. This should provide more efficient hashing both by
avoiding unnecessary string conversions and by using more optimal
type-specific hash functions.

Support for the previous hash partitioning function is preserved for
backwards compatibility. Hypertables created with the previous
function will continue to use to old hashing strategy, while new
tables will default to the updated hash partitioning.

For safety, this change also blocks changing types on hash-partitioned
columns, since it seems hard to guarantee the same hash result between
different types.
2017-10-25 15:30:56 +02:00
Erik Nordström
2ba1a40a9f Fix issue with creating expression indexes
When creating an index on a chunk based on a index on a hypertable, it
is necessary to adjust the attribute numbers of referenced columns in
case the hypertable and the chunk have different number of attributes
(this can happen, e.g., due to removing columns on the hypertable that
aren't inherited by a newly created chunk). This adjustment was
handled for regular indexes, but not expression indexes, causing an
error to be raised. This change adds the proper handling of expression
indexes.
2017-10-25 10:03:30 +02:00
Matvey Arye
d8e384bff5 Fix memory leak due to constraint expressions.
By default, Postgres places constraint expressions on the query memory
context. However, these expressions only apply to individual chunks
and cannot be re-used across chunks. Placing them on the
chunk_insert_state context (created as part of this PR) allow these
expressions to be freed along with the insert state of individual
chunks.
2017-10-24 11:31:19 -04:00
Matvey Arye
81510987d0 Improve update testing by adding a rerun test
The rerun test recreates the hypertable in the newest version
of the extension. This allows us to test correctness of the data
in the catalog.
2017-10-24 11:26:04 -04:00
Matvey Arye
c420c11e44 Create a catalog entry for constraint-backed indexes
This change makes our catalog more in-line with the pg catalog.
It also will simplify a lot of other code.
2017-10-24 11:26:04 -04:00
Matvey Arye
ec746d1ef8 Add ability to run regression test locally 2017-10-24 11:19:38 -04:00
Matvey Arye
44f9fec2fa Add analyze to parallel test for stability 2017-10-24 11:19:38 -04:00