2839 Commits

Author SHA1 Message Date
Nikhil
762053431e Implement drop_chunk_replica API
This function drops a chunk on a specified data node. It then removes
the metadata about the datanode, chunk association on the access node.

This function is meant for internal use as part of the "move chunk"
functionality.

If only one chunk replica remains then this function refuses to drop it
to avoid data loss.
2021-07-29 16:53:12 +03:00
Ruslan Fomkin
404f1cdbad Create chunk table from access node
Creates a table for chunk replica on the given data node. The table
gets the same schema and name as the chunk. The created chunk replica
table is not added into metadata on the access node or data node.

The primary goal is to use it during copy/move chunk.
2021-07-29 16:53:12 +03:00
Ruslan Fomkin
fac03f8882 Drop inherit from chunk table to hypertable
When an empty chunk table is created, it is not associated with its
hypertable in metadata, however it was inheriting from the hypertable.
This commit removes inheritance, so the chunk table is completely
standalone and cannot affect queries on the hypertable.

In future, this fix of dropping inherit can be replaced with the chunk
table creation, which does not create inheritance in the first place.
Since it is larger amount of work, it was considered now.
2021-07-29 16:53:12 +03:00
Ruslan Fomkin
34e99a1c23 Return error for NULL input to create_chunk_table
Gives errors if any argument of create_chunk_table is NULL instead of
being STRICT. Utilizes newly added macros for this.
2021-07-29 16:53:12 +03:00
Ruslan Fomkin
28ccecbe7c Create an empty chunk table
Adds an internal API function to create an empty chunk table according
the given hypertable for the given chunk table name and dimension
slices. This functions creates a chunk table inheriting from the
hypertable, so it guarantees the same schema. No TimescaleDB's
metadata is updated.

To be able to create the chunk table in a tablespace attached to the
hyeprtable, this commit allows calculating the tablespace id without
the dimension slice to exist in the catalog.

If there is already a chunk, which collides on dimension slices, the
function fails to create the chunk table.

The function will be used internally in multi-node to be able to
replicate a chunk from one data node to another.
2021-07-29 16:53:12 +03:00
Sven Klemm
ded8e82ebb Fix downgrade files for 2.3.1
The cagg rebuild was required for a fix introduced in 2.3.1 but
was not removed from reverse-dev.sql when that version got released.
2021-07-28 17:08:13 +02:00
Dmitry Simonenko
bad2fc14e2 Fix remote_txn_heal_data_node() for multiple DB's
Since pg_prepared_xacts is shared between databases, the healing
function tried to resolve prepared transactions created by other
distributed databases.

This change makes the healing function to work only with current
database.

Fix #3433
2021-07-26 16:44:04 +03:00
Markos Fountoulakis
3a8f396bc7 Remove check from relcache invalidation callback
The timescaledb extension checking code uses syscache lookups to
determine whether the proxy table exists. Doing syscache lookups
inside the invalidation callback context was corrupting the syscache.
For this reason, we remove this callback.
2021-07-25 13:27:50 +03:00
gayyappan
0277ed7461 Verify compressed chunk validity for insert path
When a insert into a compressed chunk is blocked by a
concurrent recompress_chunk, the latter process could move
the storage for the compressed chunk. Verify validity of
the compressed chunk before proceeding to acquire locks.

Fixes #3400
2021-07-22 15:18:42 -04:00
Mats Kindahl
637fe3275b Fix targetlist for cagg views
If the names for entries in the targetlist for the direct and partial
views of the continuous aggregate does not match the attribute names in
the tuple descriptor for the result tuple of the user view an error
will be generated. This commit fixes this by setting the targetlist
resource names of the columns in the direct and partial view to the
corresponding attribute name of the user view relation tuple
descriptor.

Fixes #3051
Fixes #3405
2021-07-21 20:01:49 +02:00
Aleksander Alekseev
00e4a91082 Improve test coverage of time_bucket_ng()
Also make the code more explicit about handling 'infinity' values.
2021-07-21 14:30:58 +03:00
Nikhil
768ff54ae2 Add perl module files to PG install
We have added additional functionality in timescaledb extension to
use in tap tests. Install these perl files in the PG installation
directory so that external modules (the current "forge_ext" extension
as an example) can use this functionality without having to have an
additional dependency on the timescaledb extension source code. Note
that these perl files should be installed only if PG installation has
the relevant "${PG_PKGLIBDIR}/pgxs/src/test/perl" subdirectory.

Also rejig the configuration directory variable that's used for the
tap tests so that external modules can specify their own locations by
using their own values for it (the current variable was tightly tied to
timescaledb source code location).
2021-07-21 14:09:28 +05:30
Aleksander Alekseev
99f7a2122f Support seconds, minutes, and hours in time_bucket_ng()
As a future replacement for time_bucket(), time_bucket_ng()
should support seconds, minutes, and hours. This patch adds
this support. The implementation is the same as for
time_bucket(). Timezones are not yet supported.
2021-07-20 12:34:57 +03:00
Sven Klemm
78a21f412b Adjust copy code to PG14 changes
PG14 changes initialization of ResultRelInfo, removes
es_num_result_relations and changes es_result_relations into an
array index by rangetable index.

https://github.com/postgres/postgres/commit/1375422c78
2021-07-12 18:47:09 +02:00
Sven Klemm
d607e3d714 Adjust ReindexTable calls to PG14 changes
PG14 removes the concurrent variable from ReindexStmt and turns
it into an option instead.
PG14 adds an isTopLevel argument to ReindexTable.

https://github.com/postgres/postgres/commit/844c05abc3
https://github.com/postgres/postgres/commit/a6642b3ae0
2021-07-12 18:47:09 +02:00
Sven Klemm
c49a0b3e8e Adjust cluster_rel and vacuum_set_xid_limits calls to PG14 changes
PG14 adds an isTopLevel argument to cluster_rel and
vacuum_set_xid_limits.

https://github.com/postgres/postgres/commit/a7212be8b9
2021-07-12 18:47:09 +02:00
Sven Klemm
c270891a4e Fix segfault for RelOptInfo without fdw_private
In nested function invocations hypertable expansion would not work
correctly and a hypertable would not be expanded by timescaledb
code but by postgres table inheritance leading to fdw_private
not being properly initialized.

Fixes #3391
2021-07-12 14:08:05 +02:00
Aleksander Alekseev
2f69e4b207 Ignore debug_notice test during sanitizer runs
This test sometimes fails because it generates extra "rehashing
catalog cache" debug messages, which is not very helpful.
2021-07-12 13:59:47 +03:00
Mats Kindahl
b5ffc71071 Post-release steps for release 2.3.1
Add 2.3.1 to the update tests and update the downgrade target for the
downgrade version. This commit also fixes two issues that were fixed in
the release branch:

1. Drop `_timescaledb_internal.refresh_continuous_aggregate`
2. Update the changelog to match the release branch.
2021-07-08 14:31:01 +02:00
Mats Kindahl
0e505dd553 Fix version modifier
The variable `VERSION_MOD` is used by `config.h`.
2021-07-05 09:59:15 +02:00
Dmitry Simonenko
994640858b Fix fall-through warning in debug_point_enable() 2021-07-05 10:34:22 +03:00
Mats Kindahl
072b9682c7 Fix regex that matches version
The regex expected a trailing version like `-rc1` or `-dev` but only
the non-dash part was optional. This correct the regex to ensure that
the entire trailing part is optional.
2021-07-02 16:09:54 +02:00
Dmitry Simonenko
40d2bf17b6 Add support for error injections
Rework debug waitpoint functionality to produce an error in
case if the waitpoint is enabled.

This update introduce a controlled way to simulate errors
scenarios during testing.
2021-07-02 16:43:36 +03:00
Aleksander Alekseev
a1a789be8e Allow to use experimental functions in caggs
Current implementation of caggs can't find a bucketing function
if it's declared in the experimental schema. This patch fixes it.

Also the patch adds `debug_notice` test to IGNORE list on AppVeyor.
The corresponding test generates an extra "DEBUG: rehashing catalog
cache" message which is not critical. It seems to be stable on Linux.
2021-07-02 14:44:11 +03:00
Mats Kindahl
06433f6228 Release 2.3.1
**Bugfixes**
* #3279 Add some more randomness to chunk assignment
* #3288 Fix failed update with parallel workers
* #3300 Improve trigger handling on distributed hypertables
* #3304 Remove paths that reference parent relids for compressed chunks
* #3305 Fix pull_varnos miscomputation of relids set
* #3310 Generate downgrade script
* #3314 Fix heap buffer overflow in hypertable expansion
* #3317 Fix heap buffer overflow in remote connection cache.
* #3327 Make aggregate in caggs fully qualified
* #3327 Make aggregates in caggs fully qualified
* #3336 Fix pg_init_privs objsubid handling
* #3345 Fix SkipScan distinct column identification
* #3355 Fix heap buffer overflow when renaming compressed hypertable columns.
* #3367 Improve DecompressChunk qual pushdown
* #3377 Fix bad use of repalloc

**Thanks**
* @db-adrian for reporting an issue when accessing cagg view through postgres_fdw
* @fncaldas and @pgwhalen for reporting an issue accessing caggs when public is not in search_path
* @fvannee, @mglonnro and @ebreijo for reporting an issue with the upgrade script
* @fvannee for reporting a performance regression with SkipScan
2021-07-02 09:12:38 +02:00
Mats Kindahl
a58ebdb3b4 Split update and downgrade version
During an update, it is not possible to run the downgrade scripts until
the release has been tagged, but the update scripts can be run. This
means that we need to split the previous version into two different
fields: one for running the update tests and one for running the
downgrade tests.
2021-07-01 16:05:31 +02:00
Mats Kindahl
cb7fffe0ce Fix bad use of repalloc
In contrast to `realloc`, the PostgreSQL function `repalloc` does not
accept a NULL pointer and fall back on `palloc`. For that reason it is
necessary to check if the pointer is NULL and either use `palloc` or
`repalloc`.
2021-07-01 09:27:27 +02:00
davidkohn88
bfd92ab822 Use CREATE OR REPLACE AGGREGATE
From PG12 on, CREATE OR REPLACE is supported for aggregates,
therefore, since we have dropped support for PG11, we can avoid
going through the rigamarole of having our aggregates in a separate
file from the functions we define to support them. Nor do we need to
handle aggregates separately from other functions as their creation
is now idempotent.
2021-07-01 07:40:46 +02:00
Sven Klemm
ff5d7e42bb Adjust code to PG14 reltuples changes
PG14 changes the initial value of pg_class.reltuples to -1 to allow
differentiating between an empty relation and a relation where
ANALYZE has not yet run.

https://github.com/postgres/postgres/commit/3d351d916b
2021-06-29 16:35:35 +02:00
Mats Kindahl
e28b9d0d60 Export variables to docker-build
This commit export the `GENERATE_DOWNGRADE_SCRIPT` and `PG_VERSION`
variables from `test_downgrade_to_tag.sh` to `docker-build.sh`.
2021-06-29 09:42:35 +02:00
Mats Kindahl
a3e8fd0497 Always define 'format' target
If `clang-format` is not found `CLANG_FORMAT` will be set to a false
value, which will prevent the `format` target from being defined if
`cmake-format` is not installed.

This commit fixes that by always creating a `format` target since
`clang-format` is always created even if `CLANG_FORMAT` is false.

We do not redefine `CLANG_FORMAT` to a non-false value since it is
expected to contain a path to an executable and if set to a true value
that is not a path it could be used in a way that leads to strange
errors.
2021-06-28 14:37:47 +02:00
Sven Klemm
45a7abc4de Improve DecompressChunk qual pushdown
Allow pushdown of RelabelType expressions into the scan below the
DecompressChunk node. When using varchar columns as segmentby
columns constraints on those columns would not be pushed down
because postgres would inject RelabelType nodes that where not
accepted as valid expression for pushdown leading to bad performance
because the filter could only be applied after decompression.

Fixes #3351
2021-06-25 17:33:33 +02:00
Aleksander Alekseev
e57155fdc0 time_bucket_ng() may be IMMUTABLE depending on arguments.
This function is IMMUTABLE when it doesn't accept timestamptz arguments,
and STABLE otherwise. See the comments in sql/time_bucket_ng.sql for
more details.
2021-06-25 12:36:14 +03:00
Markos Fountoulakis
20db06891a Fix ABI breakage test in CI
Add the files that had been missing from the docker environment since
the introduction of the downgrade scripts.
2021-06-25 12:13:54 +03:00
Sven Klemm
4aba9a348b Adjust test_utils.h includes to postgres changes
PG14 changes xact.h to no longer include fmgr.h which is needed
for PG_FUNCTION_ARGS definition. This patch includes fmgr.h
explicitly to no longer rely on the indirect include.

https://github.com/postgres/postgres/commit/3941eb6341
2021-06-24 14:10:25 +02:00
Sven Klemm
f23233055d Adjust process_utility to PG14 field renames
PG14 renames field relkind for CreateTableAsStmt and AlterTableStmt
to objtype.

https://github.com/postgres/postgres/commit/cc35d8933a
2021-06-24 14:10:25 +02:00
Sven Klemm
51531e36d0 Allow building against PG14 and add it to CI
This patch adds a new EXPERIMENTAL flag to cmake allowing skipping
the check for a compatible postgres version. It also adds macros
needed for PG14 support.
2021-06-24 14:10:25 +02:00
Markos Fountoulakis
4a599baf34 Fix memory overflow
Fix heap buffer overflow in hypertable expansion.
2021-06-24 12:39:02 +03:00
Mats Kindahl
15b46818ea Generate downgrade script
This commit add functions and code to generate a downgrade script from
the current version to the previous version. This requires execution
from a Git repository since it retrieves the prolog and epilog for the
"downgrade" file from the version given by `update_from_version` in the
`version.config` file.

The commit adds several CMake functions that simplifies the composition
of script files, but these are not used to generate the update scripts.
A potential improvement is to use the scripts to also generate the
update scripts.

This commit supports generating a downgrade script from the
current version to the previous version. Other versions are handled
using a variable containing file names of reverse update
scripts and  the source and target version is extracted from the file
names, which is assumed to be of the form
`<source-version>--<target-version>.sql`.

In addition to adding support for generating downgrade scripts, the
commit adds a downgrade test file that tests a release in a similar way
to the update script and adds it as a workflow.
2021-06-24 11:10:25 +02:00
Sven Klemm
41261e4e58 Stabilize timestamp_limits test output
Remove the chunk name completely from output as the name might have
different length leading to different output as table headers are
adjusted to the length of the field values.
2021-06-23 19:32:46 +02:00
Sven Klemm
77e8f019d1 Fix SkipScan distinct column identification
The SkipScan code assumed the first entry in PathKeys would match
the distinct column. This is not always true as postgres will remove
entries from PathKeys it considers constant leading to SkipScan
operating on the wrong column under those circumstances.
This did most likely not cause any wrong results as the other
constraints for SkipScan to apply still had to be satisfied but
resulted in very inefficient query execution for those affected
queries.
This patch refactors the SkipScan code to use the distinctClause
from the Query instead.

Fixes #3330
2021-06-23 19:32:46 +02:00
Sven Klemm
3bcd35640b Add compatibility macro for convert_tuples_by_name
PG13 removes the msg parameter for convert_tuples_by_name so this
patch provides a compatibility macro that abstracts the version
differences away.
2021-06-23 19:32:46 +02:00
Sven Klemm
7b67f72f86 Move timestamp_limits and with_clause_parser test
Move the timestamp_limits and with_clause_parser test to
regresscheck-shared since those tests don't need a private
database incurring less overhead to run those tests.
Also add missing ORDER BY clauses to some of the queries
in timestamp_limits to make the output more stable.
2021-06-23 14:51:09 +02:00
Markos Fountoulakis
a5caa5562f Fix memory overflow
Fix heap buffer overflow when renaming compressed hypertable columns.
2021-06-23 13:51:49 +03:00
Markos Fountoulakis
c82b5c3262 Fix Regression Linux i386 workflow
Change the postgresql ftp URL from snapshot/ to source/. This way we
do not need to react to every new commit upstream, but only whenever
the postgresql minor version changes.

Co-authored-by: Mats Kindahl <mats.kindahl@gmail.com>
2021-06-23 13:30:41 +03:00
Aleksander Alekseev
9eec2a544c Refactor initialize_func_info().
Replace unnecessary chain of ts_extension_schema_oid() ->
ts_extension_schema_name() -> get_namespace_oid() calls with
a single OID lookup.
2021-06-22 12:34:58 +03:00
Markos Fountoulakis
59d868bdf1 Run sanitizer tests on PG12
Change sanitizer test to run on PG12 and make it use the same
infrastructure as the other linux regression tests.

Co-authored-by: Sven Klemm <sven@timescale.com>
2021-06-22 11:42:48 +03:00
Sven Klemm
374decb5ac Don't skip default path when looking for prove 2021-06-22 09:47:21 +02:00
Aleksander Alekseev
33dfdcf5ea Introduce experimental time_bucket_ng() function
This patch adds time_bucket_ng() function to the experimental
schema. The "ng" part stands for "next generation". Unlike
current time_bucket() implementation the _ng version will support
months, years and timezones.

Current implementation doesn't claim to be complete. For instance,
it doesn't support timezones yet. The reasons to commit it in it's
current state are 1) to shorten the feedback loop 2) to start
experimenting with monthly buckets are soon as possible,
3) to reduce the unnecessary work of rebasing and resolving
conflicts 4) to make the work easier to the reviewers
2021-06-21 12:00:18 +03:00
Nikhil
8aaef4ae14 Fix update tests to handle sequences
The post-update script was handling preserving initprivs for newly
added catalog tables and views. However, newly added catalog sequences
need separate handling otherwise update tests start failing. We also
now grant privileges for all future sequences in the update tests.

In passing, default the PG_VERSION in the update tests to 12 since we
don't work with PG11 anymore.
2021-06-21 13:22:08 +05:30