3379 Commits

Author SHA1 Message Date
gayyappan
79bf4f53b1 Add api to associate a hypertable with custom jobs
This PR introduces a new SQL function to associate a
hypertable or continuous agg with a custom job. If
this dependency is setup, the job is automatically
deleted when the hypertable/cagg is dropped.
2022-06-23 13:33:33 -04:00
Konstantina Skovola
bd3d2ef884 Make reproduction steps field mandatory 2022-06-23 18:31:56 +03:00
gayyappan
131f58ee60 Add internal api for foreign table chunk
Add _timescaledb_internal.attach_osm_table_chunk.
This treats a pre-existing foreign table as a
hypertable chunk by adding dummy metadata to the
catalog tables.
2022-06-23 10:11:56 -04:00
Markos Fountoulakis
6c38c60b97 Repair numeric partial state on the fly
The numeric format changed between PG13 and PG14 to include infinities.
As a result the serialized partial state of numeric aggregates also
changed format.

If a user that has stored partials (e.g. by using Continuous
Aggregates) upgrades to PG14 then the partial state deserialization
will lead to errors due to the mismatch with the PG14 code.

Repair the deserialization process on the fly by appending zeroed
plus-infinity and minus-infinity counts for the numeric aggregate state
to use.

Fixes #4427
2022-06-23 11:14:40 +03:00
Alexander Kuzmenkov
93e9d42193 Use COPY protocol in row-by-row fetcher
This gives about 2x speedup for bulk data transfer queries.
2022-06-22 21:00:21 +05:30
Nikhil Sontakke
e3b2fbdf15 Fix empty bytea handlng with distributed tables
The "empty" bytea value in a column of a distributed table when
selected was being returned as "null". The actual value on the
datanodes was being stored appropriately but just the return code path
was converting it into "null" on the AN. This has been handled via the
use of PQgetisnull() function now.

Fixes #3455
2022-06-22 12:25:54 +05:30
Sven Klemm
db64473786 Use PG 14.4 in update test
Switch update/downgrade test to use 14.4. This has been split off
the CI PR switching the rest of CI to 14.4 because it usually takes
more then a week for the upstream docker images to become available.
2022-06-22 08:42:59 +02:00
Jacob Champion
f400c75b79 Tweak commit-msg hook's line character limits
The commit-msg hook was counting the end-of-line characters in the 50-
and 72-character limit, so commit messages had to be wrapped slightly
shorter in order to avoid the hook complaint. Strip the EOL characters
during the check instead.

Since we use universal newline handling during the file read, stripping
LF ('\n') should be enough to handle both Windows and Unix development
environments.
2022-06-21 13:04:42 -05:00
Jacob Champion
bab5cc101d Update commit-msg hook to Python 3
This git hook is copied automatically during CMake, and breaks commits
immediately afterwards if Python 2 isn't installed. Since Python 2 has
been end-of-life for a while now, take this chance to upgrade.
2022-06-21 13:04:27 -05:00
Jacob Champion
1221977c9c Inspect pg_config.h for SSL support
We parse apart the output of `pg_config --configure` to see whether or
not OpenSSL is enabled. This is a bit brittle; it has broken in the past
with the change from --with-openssl to --with-ssl, and upstream is
currently testing a change to the build system (Meson, which doesn't
rely on autotools during configuration) that is likely to further
interfere with this approach.

As an alternative, we can just look at the header files to get this
information.  USE_OPENSSL is not defined in pg_config.h if SSL support
is not compiled in.
2022-06-21 10:52:18 -05:00
Dmitry Simonenko
79aa0f6378 Do not allow dist ddl during create extension
This change fixes logic for the extension loading check, by
moving it before the distributed_ddl guc check.
2022-06-21 14:17:01 +03:00
Sven Klemm
02d4aefb85 Fix flaky data_node_bootstrap test
Copy collation and chartype before releasing syscache since we need
them past the lifetime of the current context.
2022-06-21 11:53:18 +02:00
Alexander Kuzmenkov
5c69adfb7e Add more tests for errors on data nodes
Use a data type with faulty send/recv functions to test various error
handling paths.
2022-06-21 14:55:14 +05:30
Nikhil Sontakke
1a9d775a2c Fix perms in copy/move chunk
We mandate that a superuser or a user with REPLICATION privileges can
invoke copy_chunk or move_chunk procedures. Internally, many stages
are carried out to complete the activity and different stages need
different user permissions. To keep things uniform we now switch to the
bootstrap superuser in each stage. Care is taken to ensure that the
original hypertable ownership is retained on the new chunk post the
move operation.
2022-06-20 19:26:22 +05:30
Sven Klemm
048d86e7e7 Fix duplicate header guard
The compression code had 2 files using the same header guard. This
patch renames the file with floating point helper functions to
float_utils.h and renames the other file to compression/api since
that more clearly reflects the purpose of the functions.
2022-06-20 09:03:02 +02:00
Sven Klemm
5cfedda1d0 Bump pgspot version used in CI to 0.3.2 2022-06-20 07:59:16 +02:00
Sven Klemm
cb096757fa Bump Postgres version used in CI to 14.4
Make CI use just released PG 14.4. We skip the version bump for the
update script as docker images with 14.4 are nowhere to be seen.
2022-06-20 07:59:16 +02:00
Pavel Borisov
1fbd4116f9 Fix tests to be resilient to possible PG planner changes. 2022-06-17 14:31:57 -03:00
Fabrízio de Royes Mello
42f197e579 Explicit constraint names in schema definition
In `src/ts_catalog/catalog.c` we explicit define some constraints and
indexes names into `catalog_table_index_definitions` array, but in our
pre-install SQL script for schema definition we don't, so let's be more
explicit here and prevent future surprises.
2022-06-17 12:47:55 -03:00
Nikhil Sontakke
ed55654a32 Retain hypertable ownership on attach_data_node
If a superuser is used to invoke attach_data_node on a hypertable then
we need to ensure that the object created on this data node has the
same original ownership permissions.

Fixes #4433
2022-06-17 18:05:25 +05:30
Konstantina Skovola
d83db1578c Redirect CI failures report to new channel 2022-06-17 10:30:39 +03:00
Erik Nordström
19b3f67b9c Drop remote data when detaching data node
Add a parameter `drop_remote_data` to `detach_data_node()` which
allows dropping the hypertable on the data node when detaching
it. This is useful when detaching a data node and then immediately
attaching it again. If the data remains on the data node, the
re-attach will fail with an error complaining that the hypertable
already exists.

The new parameter is analogous to the `drop_database` parameter of
`delete_data_node`. The new parameter is `false` by default for
compatibility and ensures that a data node can be detached without
requiring communicating with the data node (e.g., if the data node is
not responding due to a failure).

Closes #4414
2022-06-14 15:53:41 +02:00
Alexander Kuzmenkov
56945b37b8 Enable ON CONFLICT ON CONSTRAINT for hypertables
It now works since we started to rely on Postgres' arbiter
index inference.
2022-06-14 15:04:11 +05:30
Sven Klemm
1784e83d77 Fix segfault in subscription_exec
Add a check for NULL input to subscription_exec as the function
currently segfaults on NULL input. Found by sqlsmith.
2022-06-13 21:13:35 +02:00
Fabrízio de Royes Mello
07c5f7281c Create index on Continuous Aggregates
Timescale 2.7 released a new version of Continuous Aggregate (#4269)
that allows users efectivelly create and use indexes in the
materialization hypertable. The boring part of it is that users should
discover what is the associated materialization hypertable to issue a
`CREATE INDEX` statement.

Improved it by allowing users to easily create indexes in the
materialization hypertable by simple executing a `CREATE INDEX` direct
in the Continuous Aggregate.

Example:
`CREATE INDEX name_of_the_index ON continuous_agregate (column);`
2022-06-13 15:45:27 -03:00
Sven Klemm
1ac06c71c2 Refactor make_partfunc_call
Refactor make_partfunc_call to only accept fnoid and rettype instead
of PartitioningFunc which also gets rid of a coverity warning about
that parameter being passed by value instead of reference because
that parameter was longer than 128 bytes.
2022-06-13 18:49:40 +02:00
Sven Klemm
308ce8c47b Fix various misspellings 2022-06-13 10:53:08 +02:00
Luigi Servini
eb9f466582 Update dump_meta_data.sql
Added `c.dropped is false ` for table _timescaledb_catalog.chunk to
skip dropped chunks in the size calculation.
2022-06-10 19:17:51 +02:00
Fabrízio de Royes Mello
f72a277577 Fix continuous aggregates deprecated tests
Previous pull request #4269 introduced new format for Continuous
Aggregates and we also added regression tests for the `deprecated`
version to make sure it will keep working until we decide to completely
deprecate and remove the old version.

Unfortunately for some deprecated continous aggregates regression tests
we miss to set properly the flag `timescaledb.finalized=false`.

Fixed it by properly setting the `timecaledb.finalized=false` during
the continuous aggregate creation.
2022-06-09 10:08:16 -03:00
Rajakavitha Kodhandapani
c6dc0caf1d Update README.md
fixes: https://github.com/timescale/docs/issues/1162
2022-06-08 11:53:03 +02:00
Alexander Kuzmenkov
3c56d3eceb Faster lookup of chunks by point
Don't keep the chunk constraints while searching. The number of
candidate chunks can be very large, so keeping these constraints is a
lot of work and uses a lot of memory. For finding the matching chunk,
it is enough to track the number of dimensions that matched a given
chunk id. After finding the chunk id, we can look up only the matching
chunk data with the usual function.

This saves some work when doing INSERTs.
2022-06-07 18:10:20 +05:30
Sven Klemm
216ea65937 Enable chunk exclusion for space dimensions in UPDATE/DELETE
This patch transforms constraints on hash-based space partitions to make
them usable by postgres constraint exclusion.

If we have an equality condition on a space partitioning column, we add
a corresponding condition on get_partition_hash on this column. These
conditions match the constraints on chunks, so postgres' constraint
exclusion is able to use them and exclude the chunks.

The following transformations are done:

device_id = 1
becomes
((device_id = 1) AND (_timescaledb_internal.get_partition_hash(device_id) = 242423622))

s1 = ANY ('{s1_2,s1_2}'::text[])
becomes
((s1 = ANY ('{s1_2,s1_2}'::text[])) AND
(_timescaledb_internal.get_partition_hash(s1) = ANY ('{1583420735,1583420735}'::integer[])))

These transformations are not visible in EXPLAIN output as we remove
them again after hypertable expansion is done.
2022-06-07 13:10:28 +02:00
Sven Klemm
ce59820678 Fix removal of constified constraints
Commit dcb7dcc5 removed the constified intermediate values used
during hypertable expansion but only did so completely for PG14.
For PG12 and PG13 some constraints remained in the plan.
2022-06-06 15:47:02 +02:00
Konstantina Skovola
b6a974e7f3 Add schedule_interval to policies
Add a parameter `schedule_interval` to retention and
compression policies to allow users to define the schedule
interval. Fall back to previous default if no value is
specified.

Fixes #3806
2022-06-06 16:22:22 +03:00
Sven Klemm
96202a99bd Adjust code to PG15 pg_database changes
PG15 changes the type of collate and ctype from name to text.

https://github.com/postgres/postgres/commit/54637508
2022-06-05 14:43:55 +02:00
Sven Klemm
1ef515eb7a Add shmem_request_hook
This patch consolidates all shared memory requests in a
shmem_request_hook. While there are no strict requirements when
to request shared memory for PG < 15 in PG 15 it has to happen
in the shmem_request_hook otherwise the request will be blocked.

https://github.com/postgres/postgres/commit/4f2400cb
2022-06-03 16:48:47 +02:00
Konstantina Skovola
f059e00fad Create composite index on segmentby columns
Previously we created one index per segmentby column, of the form
`(col, _ts_meta_sequence_num)`.
Compressed data is ordered by segmentby, then by orderby within
the segments and lastly by the sequence number of the batch. So if
segmentby columns are missing from the index, that index cannot be
used to produce ordered output, requiring an extra sort step.

A composite index containing all segmentby columns removes the
additional sort step and gives better plans.

Fixes #4314
2022-06-03 11:41:01 +03:00
Erik Nordström
8f9975d7be Fix crash during insert into distributed hypertable
For certain inserts on a distributed hypertable, e.g., involving CTEs
and upserts, plans can be generated that weren't properly handled by
the DataNodeCopy and DataNodeDispatch execution nodes. In particular,
the nodes expect ChunkDispatch as a child node, but PostgreSQL can
sometimes insert a Result node above ChunkDispatch, causing the crash.

Further, behavioral changes in PG14 also caused the DataNodeCopy node
to sometimes wrongly believe a RETURNING clause was present. The check
for returning clauses has been updated to fix this issue.

Fixes #4339
2022-06-02 17:25:33 +02:00
Erik Nordström
65b0dda97b Fix CI coredump handling
The CI task for getting coredumps after crashes of a 32-bit build
didn't handle a variable correctly. Fix to avoid errors.
2022-06-02 17:25:33 +02:00
Sven Klemm
cae1f16367 Use our implementation of find_em_expr_for_rel for PG15+
PG13 added an implementation of find_em_expr_for_rel to postgres
core code. Which is removed again in PG15. This patch adjusts
our macros to deal with the removal in PG15.

https://github.com/postgres/postgres/commit/f3dd9fe1
2022-06-02 11:05:53 +02:00
Konstantina Skovola
f28131cff5 Don't ask for orderby column if default already set
When enabling compression on a hypertable, the orderby option can be
omitted, which will set the default value of "time DESC".
However previously, when executing the same command twice not setting
orderby, the second time we would get an error that orderby was
previously set and must be specified.
For example when executing
`alter table set (timescaledb.compress, timescaledb.segmentby = '..')`

The reason for that error was that it's unclear if no orderby means
leave as is, or if it means set the default value.
But in the case where orderby is already set to the default value,
there is no ambiguity and both cases are equivalent, so the default
value can be reset without giving an error.

Fixes #4331
2022-06-02 11:18:11 +03:00
Alexander Kuzmenkov
ed948b1772 Don't force clang-tidy on
If the compiler is gcc, clang-tidy might not recognize some of its
flags and error out. It will be enabled by default if the compiler is
clang.
2022-06-02 13:08:15 +05:30
Mats Kindahl
533e849c57 Pass parameters to workers as a struct
Non-functional change.

Parameters to workers were passed in as a serialized string, which then
needs to be serialized and deserialized using dedicated functions.

This commit refactors code to pass parameters to workers as a struct,
which is then just copied into the `bgw_extra` field of
`BackgroundWorker`. The struct contains simple values and can therefore
be copied using memcpy(3c).
2022-05-31 15:22:13 +02:00
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