3336 Commits

Author SHA1 Message Date
Alexander Kuzmenkov
5c0110cbbf Mark partialize_agg as parallel safe
Postgres knows whether a given aggregate is parallel-safe, and creates
parallel aggregation plans based on that. The `partialize_agg` is a
wrapper we use to perform partial aggregation on data nodes. It is a
pure function that produces serialized aggregation state as a result.
Being pure, it doesn't influence parallel safety. This means we don't
need to mark it parallel-unsafe to artificially disable the parallel
plans for partial aggregation. They will be chosen as usual based on
the parallel-safety of the underlying aggregate function.
2022-05-31 14:53:58 +05:30
Jan Nidzwetzki
1d0670e703 Fix flaky copy test by generating fixed test data
The copy test is flaky because some test data is generated
dynamically based on the current date. This patch changes the data
generation to a time series with fixed dates.
2022-05-31 11:05:27 +02:00
Sven Klemm
1fbe2eb36f Support intervals with month component when constifying now()
When dealing with Intervals with month component timezone changes
can result in multiple day differences in the outcome of these
calculations due to different month lengths. When dealing with
months we add a 7 day safety buffer.
For all these calculations it is fine if we exclude less chunks
than strictly required for the operation, additional exclusion
with exact values will happen in the executor. But under no
circumstances must we exclude too much cause there would be
no way for the executor to get those chunks back.
2022-05-30 18:02:58 +02:00
Sven Klemm
2715b5564a Replace pg_atoi with pg_strtoint16/32
PG 15 removes pg_atoi, so this patch changes all callers to use
pg_strtoint16/32.

https://github.com/postgres/postgres/commit/73508475
2022-05-30 08:32:50 +02:00
Sven Klemm
12574dc8ec Support intervals with day component when constifying now()
The initial patch to use now() expressions during planner hypertable
expansion only supported intervals with no day or month component.
This patch adds support for intervals with day component.

If the interval has a day component then the calculation needs
to take into account daylight saving time switches and thereby a
day would not always be exactly 24 hours. We mitigate this by
adding a safety buffer to account for these dst switches when
dealing with intervals with day component. These calculations
will be repeated with exact values during execution.
Since dst switches seem to range between -1 and 2 hours we set
the safety buffer to 4 hours.

This patch also refactors the tests since the previous tests
made it hard to tell the feature was working after the constified
values have been removed from the plans.
2022-05-28 10:02:33 +02:00
Alexander Kuzmenkov
a6b5f9002c More clear clang-tidy options
Enable a closed list of checks and treat everything as errors.
2022-05-26 13:51:36 +05:30
Alexander Kuzmenkov
ecf34132c6 Fix clang-tidy warning readability-redundant-control-flow 2022-05-26 13:51:36 +05:30
Alexander Kuzmenkov
e75274ee7c Fix clang-tidy warning bugprone-argument-comment 2022-05-26 13:51:36 +05:30
Alexander Kuzmenkov
a3ef038465 Fix clang-tidy warning bugprone-macro-parentheses 2022-05-26 13:51:36 +05:30
Sven Klemm
7aec25d69e Adjust coccinelle and shellcheck CI config
Currently coccinelle and shellcheck get run an additional time
for every merged commit to master. This patch adjusts the config
so they are only run on pull request or on push to prerelease_test
instead of push to any branch, similar to how all the other
workflows are set up.
2022-05-26 09:25:15 +02:00
Joshua Lockerman
c35e9bf611 Function telemetry
This commit contains extends our telemetry system with function call
telemetry. It gathers function call-counts from all queries, and send
back counts for those functions that are built in or from our related
extensions.
2022-05-25 15:28:13 -04:00
Mats Kindahl
34bf695444 Add initializer to auto variable
Compilers are not smart enough to check that `conn` is initialized
inside the loop so not initializing it gives an error. Added an
initializer to the auto variable to get rid of the error.
2022-05-25 14:36:23 +02:00
Sven Klemm
f0556dc902 Skip 001_extension test on PG13.2 in CI
The extension test uses the background_psql function which is not
present in the 13.2 PostgresNode module. This function is only
available in PG 13.5+.

https://github.com/postgres/postgres/commit/a9d0a540
2022-05-25 13:55:57 +02:00
Sven Klemm
0b6a09f027 Add support for SKIPS to provecheck
This patch adds support for skipping individual tests in a provecheck
run similar to what we have for our regression checks.
2022-05-25 13:55:57 +02:00
Sven Klemm
dcb7dcc506 Remove constified now() constraints from plan
Commit 35ea80ff added an optimization to enable expressions with
now() to be used during plan-time chunk exclusion by constifying
the now() expression. The added constified constraints were left
in the plan even though they were only required during the
hypertable explansion. This patch marks those constified constraints
and removes them once they are no longer required.
2022-05-24 17:19:18 +02:00
Jan Nidzwetzki
d249954be0 Improved buffer management in the copy operator
The multi-buffer copy optimization creates a multi-insert buffer per
ChunkInsertState. However, chunks can be closed. When
ts_chunk_dispatch_get_chunk_insert_state is called for a closed chunk
again, a new ChunkInsertState is returned. So far, also a new
multi-insert buffer has been created. Therefore, multiple batch
operations could be executed per chunk, which reduces the efficiency
of the optimization.

This patch introduces an HTAB that maps from the chunk_id to the
multi-insert buffer. Even when a chunk is closed, all tuples for
a chunk are stored in the same buffer.
2022-05-24 13:41:56 +02:00
Sven Klemm
cf9b626794 Post-Release 2.7.0
Adjust version.config and add 2.7.0 to update/downgrade test.
2022-05-24 12:54:06 +02:00
Sven Klemm
0a68209563 Release 2.7.0
This release adds major new features since the 2.6.1 release.
We deem it moderate priority for upgrading.

This release includes these noteworthy features:

* Optimize continuous aggregate query performance and storage
* The following query clauses and functions can now be used in a continuous
  aggregate: FILTER, DISTINCT, ORDER BY as well as [Ordered-Set Aggregate](https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE)
  and [Hypothetical-Set Aggregate](https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-HYPOTHETICAL-TABLE)
* Optimize now() query planning time
* Improve COPY insert performance
* Improve performance of UPDATE/DELETE on PG14 by excluding chunks

This release also includes several bug fixes.

If you are upgrading from a previous version and were using compression
with a non-default collation on a segmentby-column you should recompress
those hypertables.

**Features**
* #4045 Custom origin's support in CAGGs
* #4120 Add logging for retention policy
* #4158 Allow ANALYZE command on a data node directly
* #4169 Add support for chunk exclusion on DELETE to PG14
* #4209 Add support for chunk exclusion on UPDATE to PG14
* #4269 Continuous Aggregates finals form
* #4301 Add support for bulk inserts in COPY operator
* #4311 Support non-superuser move chunk operations
* #4330 Add GUC "bgw_launcher_poll_time"
* #4340 Enable now() usage in plan-time chunk exclusion

**Bugfixes**
* #3899 Fix segfault in Continuous Aggregates
* #4225 Fix TRUNCATE error as non-owner on hypertable
* #4236 Fix potential wrong order of results for compressed hypertable with a non-default collation
* #4249 Fix option "timescaledb.create_group_indexes"
* #4251 Fix INSERT into compressed chunks with dropped columns
* #4255 Fix option "timescaledb.create_group_indexes"
* #4259 Fix logic bug in extension update script
* #4269 Fix bad Continuous Aggregate view definition reported in #4233
* #4289 Support moving compressed chunks between data nodes
* #4300 Fix refresh window cap for cagg refresh policy
* #4315 Fix memory leak in scheduler
* #4323 Remove printouts from signal handlers
* #4342 Fix move chunk cleanup logic
* #4349 Fix crashes in functions using AlterTableInternal
* #4358 Fix crash and other issues in telemetry reporter

**Thanks**
* @abrownsword for reporting a bug in the telemetry reporter and testing the fix
* @jsoref for fixing various misspellings in code, comments and documentation
* @yalon for reporting an error with ALTER TABLE RENAME on distributed hypertables
* @zhuizhuhaomeng for reporting and fixing a memory leak in our scheduler
2022-05-23 17:58:20 +02:00
Sven Klemm
26da1b5035 Show warning for caggs with numeric
Postgres changes the internal state format for numeric aggregates
which we materialize in caggs in PG14. This will invalidate the
affected columns when upgrading from PG13 to PG14. This patch
adds a warning to the update script when we encounter this
configuration.
2022-05-23 16:40:53 +02:00
Sven Klemm
4f58132d37 Fix PG13.2 isolation tests
The deadlock_recompress_chunk isolation test uses syntax not
supported by earlier versions of the isolation tester leading
to a parse failure when processing that file on PG13.2.
This patch skips that particular test on PG13.2.
2022-05-23 10:12:00 +02:00
Sven Klemm
94ca9c66f4 Ignore telemetry isolation test on PG13.2
Commit 7b9d8673 added an isolation test for telemetry but did not
add it to the ignore list for earlier postgres versions. PG14 changed
the output format for isolation tests which got backported to PG12
and PG13 which makes the output of earlier PG12 and PG13 different
from the latest one so we ignore isolation tests on those earlier
versions.
2022-05-20 21:37:01 +02:00
Sven Klemm
aa0b36d5ba Skip telemetry test on PG12.0
With recent refactorings the telemetry test seems to trigger the
same use-after-free bug that got triggered by tablespace test so
we skip that test on PG12.0 as well.
2022-05-20 20:31:19 +02:00
Sven Klemm
b845f9423b Skip tablespace test on PG12.0
The tablespace test causes a segfault on PG12.0 due to an upstream
bug in the event trigger handling.
2022-05-20 17:18:21 +02:00
Erik Nordström
7b9d867358 Fix crash and other issues in telemetry reporter
Make the following changes to the telemetry reporter background worker:

- Add a read lock to the current relation that the reporter collects
  stats for. This lock protects against concurrent deletion of the
  relation, which could lead to errors that would prevent the reporter
  from completing its report.
- Set an active snapshot in the telemetry background process for use
  when scanning a relation for stats collection.

- Reopen the scan iterator when collecting chunk compression stats for
  a relation instead of keeping it open and restarting the scan. The
  previous approach seems to cause crashes due to memory corruption of
  the scan state. Unfortunately, the exact cause has not been
  identified, but the change has been verified to work on a live
  running instance (thanks to @abrownsword for the help with
  reproducing the crash and testing fixes).

Fixes #4266
2022-05-20 16:52:54 +02:00
Sven Klemm
46c95c426c Ignore pg_dump test on appveyor
On appveyor the pg_dump is flaky and seems to fail every other time.
This patch makes appveyor ignore the result of that test.
2022-05-20 14:09:44 +02:00
Sven Klemm
b7472c82ce Remove dead code
Remove noop ternary operator in cagg_rebuild_view_definition. We
return if finalized is true on line 2475 so the NIL would never
be reached in the ternary operator. Found by coverity.
2022-05-20 13:38:38 +02:00
Sven Klemm
8c5c7bb4ad Filter out chunk ids in shared tests
Multinode queries use _timescaledb_internal.chunks_in to specify
the chunks from which to select data. The chunk id in
regresscheck-shared is not stable and may differ depending on
execution order leading to flaky tests.
2022-05-19 21:33:33 +02:00
Sven Klemm
eab4efa323 Move metrics_dist1 out of shared_setup
The table metrics_dist1 was only used by a single test and therefore
should not be part of shared_setup but instead be created in the
test that actually uses it. This reduces executed time of
regresscheck-shared when that test is not run.
2022-05-19 21:33:33 +02:00
Erik Nordström
9b91665162 Fix crashes in functions using AlterTableInternal
A number of TimescaleDB functions internally call `AlterTableInternal`
to modify tables or indexes. For instance, `compress_chunk` and
`attach_tablespace` act as DDL commands to modify
hypertables. However, crashes occur when these functions are called
via `SELECT * INTO FROM <function_name>` or the equivalent `CREATE
TABLE AS` statement. The crashes happen because these statements are
considered process utility commands and therefore sets up an event
trigger context for collecting commands. However, the event trigger
context is not properly set up to record alter table statements in
this code path, thus causing the crashes.

To prevent crashes, wrap `AlterTableInternal` with the event trigger
functions to properly initialize the event trigger context.
2022-05-19 17:37:09 +02:00
Dmitry Simonenko
54d6b41e65 Fix move chunk cleanup logic
Add a new stage "complete" in the "chunk_copy_operation" to
indicate successful move/copy chunk operations. Make the
"cleanup_copy_chunk_operation" procedure more robust and make it only
delete chunk operation entries from the catalog without doing any other
unwanted cleanup if called on successful operations.
2022-05-19 16:16:58 +03:00
Jan Nidzwetzki
8375b9aa53 Fix a crash in the copy multi-buffer optimization
This patch solves a crash in the multi-buffer copy optimization,
which was introduced in commit
bbb2f414d2090efd2d8533b464584157860ce49a.

This patch handles closed chunks (e.g., caused by timescaledb.max_open_
chunks_per_insert) properly. The problem is addressed by:

1) Re-reading the ChunkInsertState before the data is stored, which
   ensures that the underlying table is open.

2) A TSCopyMultiInsertBuffer is deleted after the data of the buffer
   is flushed. So, operations like table_finish_bulk_insert are
   executed and the associated chunk can properly be closed.
2022-05-19 13:38:27 +02:00
Sven Klemm
43c8e51510 Fix Var handling for Vars of different level in constify_now
This patch fixes the constify_now optimization to ignore Vars of
different level. Previously this could potentially lead to an
assertion failure cause the varno of that varno might be bigger
than the number of entries in the rangetable. Found by sqlsmith.
2022-05-19 11:45:17 +02:00
Sven Klemm
5193af7396 Test attnum stays consistent in update
This patch adds a test for attnum consistency to our update scripts.
When attnum between fresh install and updated install is different
the updated installation will not be able to correctly process affected
catalog tables.
2022-05-18 21:35:30 +02:00
Dmitry Simonenko
f1575bb4c3 Support moving compressed chunks between data nodes
This change allows to copy or move compressed chunks
between data nodes by including compressed chunk into the
chunk copy command stages.
2022-05-18 22:14:50 +03:00
Sven Klemm
11c6813b1d Fix flaky regresscheck-shared
While we do filter out chunk ids and hypertable ids from the test
output, the output was still unstable when those ids switch between
single and double digit as that changes the length of the query
decorator in EXPLAIN output. This patch removes this decorator
entirely from all shared test output.
2022-05-18 17:34:11 +02:00
Fabrízio de Royes Mello
f266f5cf56 Continuous Aggregates finals form
Following work started by #4294 to improve performance of Continuous
Aggregates by removing the re-aggregation in the user view.

This PR get rid of `partialize_agg` and `finalize_agg` aggregate
functions and store the finalized aggregated (plain) data in the
materialization hypertable.

Because we're not storing partials anymore and removed the
re-aggregation, now is be possible to create indexes on aggregated
columns in the materialization hypertable in order to improve the
performance even more.

Also removed restrictions on types of aggregates users can perform
with Continuous Aggregates:
* aggregates with DISTINCT
* aggregates with FILTER
* aggregates with FILTER in HAVING clause
* aggregates without combine function
* ordered-set aggregates
* hypothetical-set aggregates

By default new Continuous Aggregates will be created using this new
format, but the previous version (with partials) will be supported.

Users can create the previous style by setting to `false` the storage
paramater named `timescaledb.finalized` during the creation of the
Continuous Aggregate.

Fixes #4233
2022-05-18 11:38:58 -03:00
Nikhil Sontakke
ddd02922c9 Support non-superuser move chunk operations
The non-superuser needs to have REPLICATION privileges atleast. A
new function "subscription_cmd" has been added to allow running
subscription related commands on datanodes. This function implicitly
upgrades to the bootstrapped superuser and then performs subscription
creation/alteration/deletion commands. It only accepts subscriptions
related commands and errors out otherwise.
2022-05-18 16:56:31 +05:30
Sven Klemm
4988dac273 Fix sqlsmith CI workflow
Commit 3b35da76 changed the setup script for regresscheck-shared
to no longer be usable directly by the sqlsmith workflow. This
patch set TEST_DBNAME at the top of the script so it is easier
to use the script outside of regression check environment.
2022-05-18 11:47:07 +02:00
Sven Klemm
747b532be6 Bump pg version in update test
Bump PG versions to 12.11, 13.7 and 14.3 in update tests. The update
test was skipped with the previous PG version bump because upstream
docker images were not yet available which we rely on in the update
test.
2022-05-18 10:57:33 +02:00
Sven Klemm
d1ed09ce98 Fix build failure on PG12.0
Building against PG12.0 failed with
test_utils.c:99:5: error: expected ‘;’ before ‘errmsg’
because the errmsg argument was not in parens.
2022-05-18 09:18:21 +02:00
Sven Klemm
35ea80ffdf Enable now() usage in plan-time chunk exclusion
This implements an optimization to allow now() expression to be
used during plan time chunk exclusions. Since now() is stable it
would not normally be considered for plan time chunk exclusion.
To enable this behaviour we convert `column > now()` expressions
into `column > const AND column > now()`. Assuming that time
always moves forward this is safe even for prepared statements.
This optimization works for SELECT, UPDATE and DELETE.
On hypertables with many chunks this can lead to a considerable
speedup for certain queries.

The following expressions are supported:
- column > now()
- column >= now()
- column > now() - Interval
- column > now() + Interval
- column >= now() - Interval
- column >= now() + Interval

Interval must not have a day or month component as those depend
on timezone settings.

Some microbenchmark to show the improvements, I did best of five
for all of the queries.

-- hypertable with 1k chunks
-- with optimization
select * from metrics1k where time > now() - '5m'::interval;
Time: 3.090 ms

-- without optimization
select * from metrics1k where time > now() - '5m'::interval;
Time: 145.640 ms

-- hypertable with 5k chunks
-- with optimization
select * from metrics5k where time > now() - '5m'::interval;
Time: 4.317 ms

-- without optimization
select * from metrics5k where time > now() - '5m'::interval;
Time: 775.259 ms

-- hypertable with 10k chunks
-- with optimization
select * from metrics10k where time > now() - '5m'::interval;
Time: 4.853 ms

-- without optimization
select * from metrics10k where time > now() - '5m'::interval;
Time: 1766.319 ms (00:01.766)

-- hypertable with 20k chunks
-- with optimization
select * from metrics20k where time > now() - '5m'::interval;
Time: 6.141 ms

-- without optimization
select * from metrics20k where time > now() - '5m'::interval;
Time: 3321.968 ms (00:03.322)

Speedup with 1k chunks: 47x
Speedup with 5k chunks: 179x
Speedup with 10k chunks: 363x
Speedup with 20k chunks: 540x
2022-05-17 21:47:39 +02:00
Sven Klemm
01c6125de6 Reduce repetitions in workflows
Derive postgres major version from full version so we don't have
to specify both in matrix.
2022-05-17 15:24:38 +02:00
Sven Klemm
54f56af3ef Support wildcards in IGNORES
Add support for wildcards in IGNORES for regression tests.
2022-05-17 15:24:38 +02:00
Sven Klemm
a7c8641e04 Bump postgres versions used in CI
Bump postgres versions used in CI to 14.3, 13.7 and 12.11.
2022-05-17 15:24:38 +02:00
Nuno Santos
952f536636 Add security policy to repositoy 2022-05-16 22:02:56 +01:00
Konstantina Skovola
79d1d3cb3e Add GUC "bgw_launcher_poll_time"
This GUC permits configuring the TIMEOUT parameter
for the background worker launcher in the loader.

Fixes #4217
2022-05-16 23:12:22 +03:00
Fabrízio de Royes Mello
047d6b175b Revert "Pushdown of gapfill to data nodes"
This reverts commit eaf3a38fe9553659e515fac72aaad86cf1a06d1e.
2022-05-16 15:21:32 -03:00
Fabrízio de Royes Mello
4083e48a1c Revert "Add missing gitignore entry"
This reverts commit 57411719fb1f5e4d5863089bb4b840abea3bc3db.
2022-05-16 15:21:32 -03:00
Fabrízio de Royes Mello
557023c3a7 Revert "Ignore flaky "dist_gapfill_pushdown" test"
This reverts commit cf83b3b9c2d899fa0156d5c94dc4848b7584e3c9.
2022-05-16 15:21:32 -03:00
Alexander Kuzmenkov
3b35da7607 More tests for errors when fetching from data nodes
Add a special function that allows to inject these errors.
2022-05-16 18:57:42 +05:30