16 Commits

Author SHA1 Message Date
Sven Klemm
0477f40fb8 Remove PG 9.6 and PG10 test output
This patch removes PG 9.6 and PG 10 test output files and merges the
output files where PG11 output does not differ from PG12 output.
Removing code support for these versions will be in a subsequent patch.
2020-06-01 12:39:35 +02:00
Brian Rowe
54c9256256 Add version specific golden files to some tests
This change moves the custom_type, ddl, ddl_single, insert, and
partition tests under test/sql, as well as the move and reorder
tests under /tsl/test/sql to our test template framework.  This
allows them to have different golden files for different version of
Postgres.

With the exception of the reorder test, all of these tests produced
new output in PG12 which only differed by the exclusion of append
nodes from plan explanations (this exclusion  is a new feature of
PG12).  The reorder test had some of these modified plans, but also
included a test using a table with OIDs, which is not valid in PG12.
This test was modified to allow the table creation to fail, and we
captured the expected output in the new golden file for PG12.
2020-04-14 23:12:15 +02:00
Sven Klemm
f89fd07c5b Remove year from SQL file license text
This changes the license text for SQL files to be identical
with the license text for C files.
2019-01-13 23:30:22 +01:00
Sven Klemm
787cc0470e Replace hardcoded database name from regression tests
Replace hardcoded database name from regression tests with :TEST_DBNAME
Remove creation of database single_2 from test runner and add it to
bgw_launcher and loader test since no other tests used those
use SQL comments in test scripts
2018-12-28 19:26:27 +01:00
David Kohn
5aa1edac15 Refactor compatibility functions and code to support PG11
Introduce PG11 support by introducing compatibility functions for
any whose signatures have changed in PG11. Additionally, refactor
the structure of the compatibility functions found in compat.h by
breaking them out by function (or small set of similar functions)
so that it is easier to see what changed between versions and maintain
changes as more versions are supported.

In general, the philosophy has been to try for forward compatibility
wherever possible, so that we use the latest versions of function interfaces
where we can or where reasonably convenient and mimic the behavior
in older versions as much as possible.
2018-12-12 11:42:33 -05:00
Erik Nordström
e4a4f8e2f8 Add support for functions on open (time) dimensions
TimescaleDB has always supported functions on closed (space)
dimension, i.e., for hash partitioning. However, functions have not
been supported on open (time) dimensions, instead requiring columns to
have a supported time type (e.g, integer or timestamp). This restricts
the tables that can be time partitioned. Tables with custom "time"
types, which can be transformed by a function expression into a
supported time type, are not supported.

This change generalizes partitioning so that both open and closed
dimensions can have an associated partitioning function that
calculates a dimensional value. Fortunately, since we already support
functions on closed dimensions, the changes necessary to support this
on any dimension are minimal. Thus, open dimensions now support an
(optional) partitioning function that transforms the input type to a
supported time type (e.g., integer or timestamp type). Any indexes on
such dimensional columns become expression indexes.

Tests have been added for chunk expansion and the hashagg and sort
transform optimizations on tables that are using a time partitioning
function.

Currently, not all of these optimizations are well supported, but this
could potentially be fixed in the future.
2018-12-12 10:14:31 +01:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Amy Tai
46564c1e06 Handle ALTER SCHEMA RENAME properly
Previously, we did not intercept the ALTER SCHEMA [name] RENAME command, which meant all Timescale catalog tables that store a schema name were not getting updated properly. This caused problems when users tried to drop a hypertable in a renamed schema, but also would have also caused problems with other commands (which we now add tests for in this PR).
2018-10-12 16:25:22 -04:00
Joshua Lockerman
9ba2e81935 Fix segfault with custom partition types
Postgres assumes that exprs will live for the entire duration of the SQL
expression that they are created from and stores pointers into them
based on that assumption. As a memory usage optimization our INSERT
dynamically creats chunk constraints which live for only an individual
chunk insert, causing segfaults when postgres tries to read through the
cleaned up memory. To fix this we now free the per_tuple_exprcontext
_before_ deleting a chunk insert state memory context, ensuring the
segfaulting callback is called on a valid state.
2018-08-08 12:29:35 -04:00
Narek Galstyan
a97f2affef Add support for custom hypertable dimension types
Previously, if a hypertable dimension type did not have a default
hash function, create_hypertable would throw an error.
However, this should not be the case if a custom partitioning
function is provided.
This commit addresses the issue making sure that arbitrary
custom types can be used as partitioning dimensions as long
as a valid partitioning function is provided.
Fixes #470.
2018-08-06 13:01:39 -04:00
Narek Galstyan
ed379c3dd8 Validate existing indexes before adding a new dimension
If the argument column of add_dimension is not in all
of hypertable indexes that have UNIQUE, PRIMARY KEY
or EXCLUSION constraints, then add_dimension call
should fail.
This commit enforces the above.
2018-08-03 11:30:22 -04:00
Erik Nordström
77b00356c4 Enforce IMMUTABLE partitioning functions
This adds a simple check to enforce that partitioning functions
are IMMUTABLE. This is a requirement since a partitioning function
must always return the same value given the same input.
2018-08-02 20:45:10 +02:00
Erik Nordström
0e79df4ac3 Fix handling of custom SQL-based partitioning functions
Previously, when the FmgrInfo was initialized for partitioning
functions, the type information was cached in the fn_extra
field. However, the contract for fn_extra is that it is to be set by
the called function and not prior to its invokation. Setting fn_extra
prior to function invokation is an issue for custom partitioning
functions implemented in SQL, as the SQL call manager expects to use
fn_extra for its own cache.

This change avoids setting fn_extra prior to function invokation, and
instead information is cached in fn_extra within our provided
partitioning functions.

The native partitioning functions now also support nested functions,
i.e., the input to the function is the output of another function.
2018-02-22 17:38:09 +01: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
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
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