2960 Commits

Author SHA1 Message Date
Fabrízio de Royes Mello
f25e795ec8 Add regression tests for Memoize Node
PostgreSQL 14 introduced new `Memoize Node` that serve as a cache of
results from parameterized nodes.

We should make sure it will work correctly together with ChunckAppend
custom node over hypertables (compressed and uncompressed).

Closes #3684
2021-10-15 19:20:33 -03:00
Erik Nordström
57744c84ce Adjust cost estimates for distributed queries
To improve remote query push down, do the following:

* Import changes to remote cost estimates from PostgreSQL 14
  `postgres_fdw`. The cost estimations for distributed (remote)
  queries are originally based on the `postgres_fdw` code in
  PG11. However, fixes and changes have been applied in never
  PostgreSQL versions, which improves, among other things, costing of
  sorts and having clauses.
* Increase the cost of transferring tuples. This penalizes doing
  grouping/aggregation on the AN since it requires transferring more
  tuples, leading to the planner preferring the push-down plans.
* As a result of the above, the improved costing also makes
  distributed queries behave similar across all currently supported
  PostgreSQL versions for our test cases.
* Enable `dist_query` tests on PG14 (since it now passes).
* Update the `dist_partial_agg` test to use additional ordering
  columns so that there is no diff in the test output due to ordering
  of input to the `first` and `last` functions.
2021-10-15 15:34:08 +02:00
Erik Nordström
28a5650382 Allow anyone to use size utilities on distributed hypertables
This change removes a check for `USAGE` privileges on data nodes
required to query the data node using utility commands, such as
`hypertable_size`. Normally, PostgreSQL doesn't require `USAGE` on a
foreign server to query its remote tables. Also, size utilities, like
`pg_table_size` can be used by anyone---even roles without any
privileges on a table. The behavior on distributed hypertables is now
consistent with PostgreSQL.

Fixes #3698
2021-10-15 15:01:44 +02:00
Aleksander Alekseev
cb13754c91 Clarify the comment for invalidation threshold
Explicitly state that the invalidation threshold is ignored by the transactions
that use an isolation level above READ COMMITTED.
2021-10-14 17:08:42 +03:00
Aleksander Alekseev
3729c50017 Fix two "unused function" errors
When building on MacOS with Clang 11 the build fails with:

error: unused function 'get_chunk_rri'
error: unused function 'get_hyper_rri'
      [-Werror,-Wunused-function]

This PR fixes it.
2021-10-14 16:21:40 +03:00
Sven Klemm
2f7bb43fe0 No longer require -DEXPERIMENTAL for PG14
Change cmake to no longer require -DEXPERIMENTAL when building
against PG14. Run more PG14 tests (32bit, windows, sanitizer).
2021-10-14 02:14:37 +02:00
Sven Klemm
f686b2af40 Fix various windows compilation problems with PG14
The windows compiler has problems with the macros in genbki.h
complaining about redefinition of a variable with a different
storage class. Since those specific macros are processed by a
perl script and not relevant for the build process we turn them
into noops for windows.
2021-10-14 02:14:37 +02:00
Sven Klemm
a82826405e Minor create_compress_chunk_result_relation_info refactor
Refactor create_compress_chunk_result_relation_info to get rid
of compiler warning about unused variable when compiling on PG14
without assertions.
2021-10-14 02:14:37 +02:00
Dmitry Simonenko
35bd83d083 Allow owner change of a data node
Allow previously blocked `ALTER SERVER OWNER TO` operation
on a data node foreign server.

Fix #3617
2021-10-13 17:01:32 +03:00
gayyappan
fffd6c2350 Use plpgsql procedure for executing compression policy
This PR removes the C code that executes the compression
policy. Instead we use a PL/pgSQL procedure to execute
the policy.

PG13.4 and PG12.8 introduced some changes
that require PortalContexts while executing transactions.
The compression policy procedure compresses chunks in
multiple transactions. We have seen some issues with snapshots
and portal management in the policy code (due to the
PG13.4 code changes). SPI API has transaction-portal management
code. However, the compression policy code does not use SPI
interfaces. But it is fairly easy to just convert this into
a PL/pgSQL procedure (which calls SPI) rather than replicating
portal managment code in C to manage multiple txns in the
compression policy.

This PR also disallows decompress_chunk, compress_chunk and
recompress_chunk in txn read only mode.

Fixes #3656
2021-10-13 09:11:59 -04:00
gayyappan
c55cbb9350 Expose subtract_integer_from_now as SQL function
Move subtract_integer_from_now to src directory
and create a SQL function for it.
2021-10-13 09:11:59 -04:00
Sven Klemm
bfe2b08350 Make dist_partial_agg output pg version specific
The plan output of the dist_partial_agg test is different on PG14
so we need to make it PG version specific. On PG14 sorts are pushed
down more often leading to better plans in some cases.
This also updates the dist_hypertable-14 test output which differs
to previous PG versions due to some renumbering of relation aliases.
2021-10-13 13:33:44 +02:00
Fabrízio de Royes Mello
de2d446cb2 Add handling of new ALTER TABLE options in PG14
PG14 introduced new `ALTER TABLE` sub-commands:

* `.. ALTER COLUMN .. SET COMPRESSION`: handled it properly on
  `process_utility` hook code and added related regression tests

* `.. DETACH PARTITION .. {CONCURRENTLY | FINALIZE}`: handled it
  properly on `process_utility` hook code but there's no need to add
  regression tests because we don't rely to native partitioning in
  hypertables.

Closes #3643
2021-10-12 19:01:20 -03:00
Dmitry Simonenko
f9d8667b1d Fix distributed hypertable DROP within a procedure
When DROP being executed inside procedure ddl_command_start
was not handled which lead to ignoring this operation on the
data nodes.

Fix #3663
2021-10-12 23:28:57 +03:00
Sven Klemm
8d12b28a00 Fix UPSERT for PG14
Adjust code to upstream UPDATE/DELETE changes. PG14 refactored the way
UPDATEs and DELETEs are planned and executed.

https://github.com/postgres/postgres/commit/86dc90056d
2021-10-12 14:11:13 +02:00
Sven Klemm
bfe3603d57 Move pg version specific part of create_hypertable test with custom partition type
Since custom types are hashable in PG14 the partition test will be
different on PG14. Since the only difference was testing whether
creating hypertable with custom type paritition throws errors
without partitioning function that specific test got moved to ddl
tests which already is pg version specific.
2021-10-11 21:07:02 +02:00
Sven Klemm
d959828155 Don't use VACUUM VERBOSE in vacuum tests
VACUUM VERBOSE is the source for flaky tests and we don't gain much
by including the verbose output in the test. Additionally removing
the verbose option prevents us from having to make the vacuum tests
pg-version specific as PG14 slightly changes the formatting of the
VACUUM VERBOSE output.
2021-10-09 00:36:10 +02:00
Sven Klemm
4d425d9470 Disable memoize node for append and transparent_decompression tests
With memoize enabled PG14 append tests produce a very different
plan compared to previous PG versions. To make comparing plans
between PG versions easier we disable memoize for PG14.
PG14 also modified how EXTRACT is shown in EXPLAIN output
so any query using EXTRACT will have different EXPLAIN output
between PG14 and previous versions.
2021-10-09 00:15:23 +02:00
Sven Klemm
9486247798 Adjust bgw_db_scheduler test to work across PG versions
PG14 changes bgw log message to include the job type so we filter
it out in the log message view to make the output consistent across
PG versions.
2021-10-09 00:15:23 +02:00
Sven Klemm
c873731e25 Remove unused variables from ExecModifyTable
Remove two unused variables from ExecModifyTable that were
accidentally left in when removing dead code.
2021-10-09 00:15:23 +02:00
Sven Klemm
90d1a390c7 Require successful PG14 tests for PRs
The previous PR enabling tests on PG14 did not actually require
tests to pass but with INSERT support merged and most of the tests
passing it makes sense to require tests to pass to not introduce
regression and explicitly not require the currently known failing
tests.
2021-10-08 22:35:46 +02:00
Sven Klemm
26c5f27683 Adjust hypertable insert for PG14
PG14 refactors the INSERT path and removes the result relation from
executor state which means plan nodes don't have easy access to
the current result relation and can no longer modify it. This patch
changes the chunk tuple routing for PG14 to pull in code from
ModifyTable which unfortunately is static and adjust it to allow
chunk tuple routing.
2021-10-08 22:35:46 +02:00
Sven Klemm
9e53cbb6d3 Fix SkipScan path generation with constant DISTINCT column
When a DISTINCT query has a WHERE clause that constifies the
DISTINCT column the query might use an index that does not have
include the DISTINCT column even though it is referenced in the
ORDER BY clause. The skipscan path generation would error on any
path with such a configuration. This patch changes the path
generation code to skip generating SkipScan path under these
circumstances.

Fixes #3629
2021-10-07 16:59:21 +02:00
Fabrízio de Royes Mello
74ca546565 Fix memory context bug executing TRUNCATE
Inside the `process_truncate` function is created a new relations list
removing the distributed hypertables and this new list is assigned to
the current statement relation list. This new list is allocated into
the `PortalContext` that is destroyed at the end of the statement
execution.

The problem arise on the subsequent `TRUNCATE` call because the
compiled plpgsql code is cached into another memory context and the
elements of the relations inside this cache is pointing to an invalid
memory area because the `PortalContext` is destroyed.

Fixed it by allocating the new relations list to the same memory
context of the original list.

Fixes #3580, fixes #3622, fixes #3182
2021-10-06 16:13:21 -03:00
Sven Klemm
0f64e11db4 Fix CI telemetry test to use correct build args
The telemetry without openssl test did not use the correct args
supplied in the build matrix leading to a failure on PG14 as
building against PG14 currently requires -DEXPERIMENTAL=ON
2021-10-06 14:42:16 +02:00
Daniel Orf
ecac52f494 Fix a typo in README.md 2021-10-06 13:56:46 +02:00
Sven Klemm
a118f384c1 Fix index attnum mapping in reorder_chunk
When we clone an index from a chunk we must not do attnum mapping if the
supplied index template is not on the hypertable. Ideally we would check
for the template being on the chunk but we cannot do that since when we
rebuild a chunk the new chunk has a different id.

Fixes #3651
2021-10-06 12:59:02 +02:00
Sven Klemm
ef0ff45006 Add PG14 regresscheck test output files
This patch adds PG14 specific test output files for regresscheck,
regresscheck-t and regresscheck-shared.
2021-10-05 20:20:57 +02:00
Sven Klemm
6b69c781ba Add PG14 to our CI 2021-10-05 20:20:57 +02:00
Fabrízio de Royes Mello
b3380e8174 Fix execution of refresh_caggs from user actions
Segmentation fault was ocurring when calling the procedure
`refresh_continous_aggregate` from an user defined action (job).

Fixed it by adding the `SPI_connect_ext/SPI_finish` during the
execution because there are underlying SPI calls that was leading
us to an invalid SPI state (nonexistent `_SPI_current` global).

Fixes #3145
2021-10-04 15:37:25 -03:00
Avthar Sewrathan
27d547853d README Update for Project Prince
Updated README for TimescaleDB GitHub page for Project Prince, with various references and links updated.
2021-10-04 19:03:35 +02:00
Dmitry Simonenko
a60b2e5f6a Allow alter column type on distributed hypertable
Unlock and support ALTER TABLE ALTER TYPE on distributed
hypertable.

Fix #3582
2021-10-04 18:06:58 +03:00
Dmitry Simonenko
55840eb48d Make ssl_dir/passfile gucs accessible for read
timescaledb.ssl_dir/passfile GUC is currently only visible for superusers.
This makes it impossible for non superusers to read GUC value which might be useful in some cases
(eg. troubleshooting or building multinode automation).

Since this GUC's does not contain any sensitive information it makes sense to make it public.

Fix #3608
2021-10-04 17:17:19 +03:00
Nikhil
7570f27638 Schema qualify UDTs in multi-node
"create_distributed_hypertable" fails on the datanodes if the columns
involved in the underlying non-default schema-qualified PG table are
using user defined types (UDTs) from another non-standard schema.

This happens because we explicitly set the namespace during the table
creation on the datanode which doesn't allow us to lookup other
schemas. We now unconditionally schema-qualify the UDT while sending
the SQL from access node to the datanode to avoid this.

Includes test case changes.

Issue reported by and general fix provided by @phemmer

Fixes #3543
2021-10-04 18:42:31 +05:30
Sven Klemm
f0ba729acb Adjust code to PG14 es_result_rel_info removal
PG14 removes es_result_relation_info from executor state.

https://github.com/postgres/postgres/commit/a04daa97
2021-10-04 13:26:22 +02:00
Sven Klemm
325f68a62d Adjust Code to PG14 ModifyTablePath changes
PG14 changes ModifyTablePath struct to have single child subpath
instead of list of subpaths. Similarly ModifyTableState mt_nplans
gets removed because ModifyTable will only have single child in
PG14. The same patch also removes ri_junkFilter from ResultRelInfo.

https://github.com/postgres/postgres/commit/86dc9005
2021-10-04 13:26:22 +02:00
Sven Klemm
d011418239 Adjust ts_set_append_rel_pathlist to PG14 changes
PG14 removes partitioned_child_rels from RelOptInfo

https://github.com/postgres/postgres/commit/a929e17e
2021-10-04 13:26:22 +02:00
Sven Klemm
4c4eb635ce Switch appveyor to preview image
Since there is an issue with the current appveyor image we switch
appveyor to the preview image which runs CI fine.
2021-10-04 12:57:45 +02:00
Sven Klemm
98f4cd6581 Fix flaky drop_owned test
Using now() in regression tests will result in flaky tests as this
can result in creating different number of chunks depending on
alignment of now() relative to chunk boundaries.
2021-10-03 15:20:05 +02:00
Fabrízio de Royes Mello
609b5ea34a Refactor SQL function approximate_row_count
Simplify the CTE to recursively inspect all partitions of a relation
and calculate the sum of `pg_class.reltuples` taking in account the
differences introduced by PG14.
2021-10-01 14:20:17 -03:00
Mats Kindahl
0fd7ad4c0f Install OpenSSL in MacOS workflow
MacOS 10.15 image version 20210927.1 does not have OpenSSL installed
so we have to explicitly install OpenSSL in the workflow for PostgreSQL
to build.
2021-10-01 17:16:23 +02:00
Mats Kindahl
9783144bec Add shared dependencies when creating chunk
When a new chunk is created, the ACL is copied from the hypertable, but
the shared dependencies are not set at all. Since there is no shared
dependency, a `DROP OWNED BY` will not find the chunk and revoke the
privileges for the user from the chunk. When the user is later dropped,
the ACL for the chunk will contain a non-existent user.

This commit fixes this by adding shared dependencies of the hypertable
to the chunk when the chunk is created.

Fixes #3614
2021-10-01 16:42:44 +02:00
Mats Kindahl
5b16ac097e Improve error message when chunk not found
When a chunk is not found, we print a generic error message that does
not hint at what we are looking for, which means that it is very hard
to locate the problem.

This commit adds details to the error message printing out values used
for the scan key when searching for the chunk.

Related-To: #2344
Related-To: #3400
Related-To: #153
2021-09-27 13:01:59 +02:00
Mats Kindahl
46a584e6b5 Show details on compressed chunk error
If insertion is attempted into a chunk that is compressed, the error
message is very brief. This commit adds a hint that the chunk should be
decompressed before inserting into it and also list the triggers on the
chunk so that it is easy to debug.
2021-09-23 14:18:29 +02:00
Sven Klemm
6838fcf906 Post 2.4.2 release
Update version numbers and add 2.4.2 to update tests.

We have to put the DROP FUNCTION back in latest-dev because
2.4.2 did not include the commit which removed the function
definitions.
2021-09-22 18:20:30 +02:00
Erik Nordström
0098829cf5 Update connection cache on role changes
The access node maintains a cache of connections to its data
nodes. Each entry in the cache is a connection for a user and remote
data node pair. Currently, a cache entry is invalidated when a foreign
server object representing a data node is changed (e.g., the port
could have been updated). The connection will remain in the cache for
the duration of the current command, but will be remade with the
updated parameters the next time it is fetched from the cache.

This change invalidates a connection cache entry if the connection's
role/user changes and drops an entry if the role is dropped. One
reason for invalidating a connection is that a role rename invalidates
the certificate the connection is using in case client certificate
authentication is used. Thus, connections that have been
authenticated with a certificate that is no longer valid will be
remade. In some cases, this extra invalidation leads to purging
connections when not strictly necessary. However, this is not a big
problem in practice since role objects don't change often.
2021-09-22 12:36:40 +02:00
Mats Kindahl
b449803878 Make continuous aggregate errors more descriptive
Users often have trouble creating continuous aggregates because many
error messages are the same and quite terse offering no guidance
for the user in how to fix. This makes some of them less terse.

Co-authored-by: David Kohn <david@timescale.com>
Co-authored-by: Mats Kindahl <mats@timescale.com>"
2021-09-22 08:00:01 +02:00
Sven Klemm
3f944bee82 Release 2.4.2
This release contains bug fixes since the 2.4.1 release.
We deem it high priority to upgrade.

**Bugfixes**
* #3437 Rename on all continuous aggregate objects
* #3469 Use signal-safe functions in signal handler
* #3520 Modify compression job processing logic
* #3527 Fix time_bucket_ng behaviour with origin argument
* #3532 Fix bootstrap with regresschecks disabled
* #3574 Fix failure on job execution by background worker
* #3590 Call cleanup functions on backend exit

**Thanks**
* @jankatins for reporting a crash with background workers
* @LutzWeischerFujitsu for reporting an issue with bootstrap
2021-09-20 19:22:13 +02:00
Mats Kindahl
592e0bd46e Rename on all continuous aggregate objects
When renaming a column on a continuous aggregate, only the user view
column was renamed. This commit changes this by applying the rename on
the materialized table, the user view, the direct view, and the partial
view, as well as the column name in the dimension table.

Since this also changes some of the table definitions, we need to
perform the same rename in the update scripts as well, which is done by
comparing the direct view and the user view to decide what columns that
require a rename and then executing that rename on the direct view,
partial view, and materialization table, as well as updating the column
name in the dimension table.

When renaming columns in tables with indexes, the column in the table
is renamed but not the column in the index, which keeps the same name.
When restoring from a dump, however, the column name of the table is
used, which create a diff in the update test. For that reason, we
change the update tests to not list index definitions as part of the
comparison. The existance of the indexes is still tracked and compared
since the indexes for a hypertable is listed as part of the output.

If a downgrade does not revert some changes, this will cause a diff in
the downgrade test. Since the rename is benign and not easy to revert,
this will cause test failure. Instead, we add a file to do extra
actions during a clean-rerun to prevent these diffs. In this case,
applying the same renames as the update script.

Fixes #3405
2021-09-20 12:18:52 +02:00
Fabrízio de Royes Mello
e22aaad48c Fix failure on job execution by background worker
If the registered procedure has COMMIT inside the code, the execution
of the job by the background worker was failing.

Fixed it checking if there are an ActivePortal, if NO then create a
Portal from scratch and execute the existing job execution code.
2021-09-17 11:09:02 -03:00