146 Commits

Author SHA1 Message Date
Sven Klemm
bc935ab2ca Remove multinode public API
This patch removes the following functions/procedures:
- add_data_node
- alter_data_node
- attach_data_node
- create_distributed_hypertable
- create_distributed_restore_point
- delete_data_node
- detach_data_node
- distributed_exec
- set_replication_factor
- _timescaledb_functions.ping_data_node
- _timescaledb_functions.remote_txn_heal_data_node
- _timescaledb_functions.set_dist_id
- _timescaledb_functions.set_peer_dist_id
- _timescaledb_functions.show_connection_cache
- _timescaledb_functions.validate_as_data_node
- _timescaledb_internal.ping_data_node
- _timescaledb_internal.remote_txn_heal_data_node
- _timescaledb_internal.set_dist_id
- _timescaledb_internal.set_peer_dist_id
- _timescaledb_internal.show_connection_cache
- _timescaledb_internal.validate_as_data_node
2023-12-12 20:37:35 +01:00
Sven Klemm
c5bed532ac Remove multinode tests
This tests removes all the multinode test files to remove the
burden to keep them update with PRs. The actual code will be removed
in followup PRs.
2023-12-11 16:37:55 +01:00
Nikhil Sontakke
44817252b5 Use creation time in retention/compression policy
The retention and compression policies can now use drop_created_before
and compress_created_before arguments respectively to specify chunk
selection using their creation times.

We don't support creation times for CAggs, yet.
2023-11-16 20:17:17 +05:30
Sven Klemm
e93b5fa657 PG16: Fix join recursion
The initial approach to mark EquivalenceMember as derived had some
loopholes still leading to infinite recursion with certain join
conditions.
2023-11-06 14:17:42 +01:00
Sven Klemm
393cc68057 Simplify compress_chunk calls in tests
Dont construct chunk names from internal catalog tables in
tests but instead use show_chunks and the informational views.
2023-11-04 20:08:28 +01:00
Ante Kresic
65ecda93e6 Align gapfill bucket generation with time_bucket
In certain scenarios, when generating buckets with
monthly buckets and different timezones, gapfill
would create timestamps which don't align with
time_bucket and thus potentially generating multiple
rows for an individual month. Instead of relying on
previous timestamp to generate the next one, now
we generate them always from the start point
which will make us align with time_bucket buckets.
2023-10-19 11:56:29 +02:00
Fabrízio de Royes Mello
a409065285 PG16: Prohibit use of multi-node
Since multi-node is not supported on PG16, add errors to multi-node
functions when run on this PostgreSQL version.
2023-10-18 11:45:06 -03:00
Sven Klemm
8f3bb0ba70 Fix EXPLAIN for compressed DML
EXPLAIN ANALYZE for compressed DML would error out with `bogus varno`
error because we would modify the original expressions of the plan
that were still referenced in nodes instead of adjusting copies and
using those copies in our internal scans.
2023-10-18 13:50:23 +02:00
Sven Klemm
a664e685cd Keep track of catalog version
This patch stores the current catalog version in an internal
table to allow us to verify catalog and code version match.
When doing dump/restore people occasionally report very unusual
errors and during investigation it is discovered that they loaded
a dump from an older version and run it with a later code version.
This allows to detect mismatches between installed code version
and loaded dump version. The version number in the metadata table
will be kept updated in upgrade and downgrade scripts.
2023-10-14 22:28:21 +02:00
Sven Klemm
332bbdb6e7 Show batches/tuples decompressed in EXPLAIN output
This patch adds tracking number of batches and tuples that needed
to be decompressed as part of DML operations on compressed hypertables.
These will be visible in EXPLAIN ANALYZE output like so:

QUERY PLAN
 Custom Scan (HypertableModify) (actual rows=0 loops=1)
   Batches decompressed: 2
   Tuples decompressed: 25
   ->  Insert on decompress_tracking (actual rows=0 loops=1)
         ->  Custom Scan (ChunkDispatch) (actual rows=2 loops=1)
               ->  Values Scan on "*VALUES*" (actual rows=2 loops=1)
(6 rows)
2023-10-14 18:01:36 +02:00
Fabrízio de Royes Mello
586b247c2b Fix cagg trigger on compat schema layer
The trigger `continuous_agg_invalidation_trigger` receive the hypertable
id as parameter as the following example:

Triggers:
    ts_cagg_invalidation_trigger AFTER INSERT OR DELETE OR UPDATE ON
       _timescaledb_internal._hyper_3_59_chunk
    FOR EACH ROW EXECUTE FUNCTION
       _timescaledb_functions.continuous_agg_invalidation_trigger('3')

The problem is in the compatibility layer using PL/pgSQL code there's no
way to passdown the parameter from the wrapper trigger function created
to the underlying trigger function in another schema.

To solve this we simple create a new function in the deprecated
`_timescaledb_internal` schema pointing to the function trigger and
inside the C code we emit the WARNING message if the function is called
from the deprecated schema.
2023-10-07 14:39:35 -03:00
Sven Klemm
f8738c838c Remove multinode tests from regresscheck-shared
The multinode tests in regresscheck-shared were already disabled
by default and removing them allows us to skip setting up the
multinode environment in regresscheck-shared. This database
is also used for sqlsmith which will make sqlsmith runs more
targetted. Additionally this will be a step towards running
regresscheck-shared unmodified against our cloud.
2023-10-05 15:44:18 +02:00
Pallavi Sontakke
0d6f5f2634
Modify interpolate() call in gapfill test (#6146)
To work fine on dev-cloud tests, in presence of other extensions.

Disable-check: force-changelog-file
2023-10-04 16:44:16 +05:30
Fabrízio de Royes Mello
32a695e18f Make CAggs materialized only by default
Historically creating a Continuous Aggregate make it realtime by default
but it confuse users specially when using `WITH NO DATA` option. Also is
well known that realtime Continuous Aggregates can potentially lead to
issues with Hierarchical and Data Tiering.

Improved the UX by making Continuous Aggregates non-realtime by default.
2023-09-26 15:53:26 -03:00
Sven Klemm
a7e7e675a4 Improve compression datatype handling
Fall back to btree operator input type when it is binary compatible with
the column type and no operator for column type could be found. This
should improve performance when using column types like char or varchar
instead of text.
2023-09-18 12:18:21 +02:00
Jan Nidzwetzki
ba9b81854c Support for partial aggregations at chunk level
This patch adds support for partial aggregations at the chunk level.
The aggregation is replanned in the create_upper_paths_hook of
PostgreSQL. The AggPath is split up into multiple
AGGSPLIT_INITIAL_SERIAL operations (one on top of each chunk), which
create partials, and one AGGSPLIT_FINAL_DESERIAL operation, which
finalizes the aggregation.
2023-09-14 09:30:23 +02:00
Sven Klemm
e4facda540 Add compatibility layer for _timescaledb_internal functions
With timescaledb 2.12 all the functions present in _timescaledb_internal
were moved into the _timescaledb_functions schema to improve schema
security. This patch adds a compatibility layer so external callers
of these internal functions will not break and allow for more
flexibility when migrating.
2023-08-31 14:55:31 +02:00
Sven Klemm
e3437786ad Make multinode tests conditional
Since multinode tests take a long time to run we dont want to run
them in CI on individual PRs but only on nightly runs.
2023-08-30 15:32:42 +02:00
Sven Klemm
a9751ccd5e Move partitioning functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- get_partition_for_key(val anyelement)
- get_partition_hash(val anyelement)
2023-08-29 12:55:22 +02:00
Sven Klemm
b2a91494a1 Move ddl_internal functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint)
- chunk_drop_replica(regclass,name)
- chunk_index_clone(oid)
- chunk_index_replace(oid,oid)
- create_chunk_replica_table(regclass,name)
- drop_stale_chunks(name,integer[])
- health()
- hypertable_constraint_add_table_fk_constraint(name,name,name,integer)
- process_ddl_event()
- wait_subscription_sync(name,name,integer,numeric)
2023-08-29 11:15:39 +02:00
Sven Klemm
6576d969b3 Move log invalidation functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- cagg_watermark(integer)
- cagg_watermark_materialized(integer)
- hypertable_invalidation_log_delete(integer)
- invalidation_cagg_log_add_entry(integer,bigint,bigint)
- invalidation_hyper_log_add_entry(integer,bigint,bigint)
- invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[])
- invalidation_process_cagg_log(integer,integer,regtype,bigint,bigint,integer[],bigint[],bigint[],text[])
- invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[])
- invalidation_process_hypertable_log(integer,integer,regtype,integer[],bigint[],bigint[],text[])
- materialization_invalidation_log_delete(integer)
2023-08-29 08:06:49 +02:00
Sven Klemm
cf04496e4b Move utility functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- generate_uuid()
- get_git_commit()
- get_os_info()
- tsl_loaded()
2023-08-22 13:42:54 +02:00
Mats Kindahl
3db6922960 Call eq_func correctly in time_bucket_gapfill
The equality comparison function is called using
`DirectFunctionCall2Coll`, which do not set the `fcinfo->flinfo` when
calling the PostgreSQL function.  Since `array_eq` uses
`fcinfo->flinfo->fn_extra` for caching, and `flinfo` is null, this
causes a crash.

Fix this issue by using `FunctionCall2Coll` instead, which sets
`fcinfo->flinfo` before calling the PostgreSQL function.

Fixes #5981
2023-08-22 09:57:39 +02:00
Sven Klemm
4256009e4c Move dist_internal functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- set_dist_id(uuid)
- set_peer_dist_id(uuid)
- validate_as_data_node()
- show_connection_cache()
- ping_data_node(name, interval)
- remote_txn_heal_data_node(oid)
2023-08-22 09:50:35 +02:00
Sven Klemm
0a66bdb8d3 Move functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- to_unix_microseconds(timestamptz)
- to_timestamp(bigint)
- to_timestamp_without_timezone(bigint)
- to_date(bigint)
- to_interval(bigint)
- interval_to_usec(interval)
- time_to_internal(anyelement)
- subtract_integer_from_now(regclass, bigint)
2023-08-21 15:01:35 +02:00
Mats Kindahl
71b0168ab7 Add debug utilities to debug builds
This will move the definitions of `debug_waitpoint_enable`,
`debug_waitpoint_disable`, and `debug_waitpoint_id` to always be
defined for debug builds and modify existing tests accordingly.

This means that it is no longer necessary to generate isolation test
files from templates (in most cases), and it will be straightforward to
use these functions in debug builds.

The debug utilities can be disabled by setting the option
`ENABLE_DEBUG_UTILS` to `OFF`.
2023-08-14 14:42:47 +02:00
Lakshmi Narayanan Sreethar
c3a9f90fdd Merge PG12 specific testfiles
Merged testfiles that were split out due to their output differing only
in PG12.
2023-07-25 16:00:18 +05:30
Ante Kresic
fb0df1ae4e Insert into indexes during chunk compression
If there any indexes on the compressed chunk, insert into them while
inserting the heap data rather than reindexing the relation at the
end. This reduces the amount of locking on the compressed chunk
indexes which created issues when merging chunks and should help
with the future updates of compressed data.
2023-06-26 09:37:12 +02:00
Sven Klemm
e302aa2ae9 Fix handling of Result nodes below Sort nodes in ConstraintAwareAppend
With PG 15 Result nodes can appear between Sort nodes and
DecompressChunk when postgres tries to adjust the targetlist.
2023-06-13 18:42:02 +02:00
Sotiris Stamokostas
1a93c2d482 Improve parallel workers for decompression
So far, we have set the number of desired workers for decompression to
1. If a query touches only one chunk, we end up with one worker in a
parallel plan. Only if the query touches multiple chunks PostgreSQL
spins up multiple workers. These workers could then be used to process
the data of one chunk.

This patch removes our custom worker calculation and relies on
PostgreSQL logic to calculate the desired parallelity.

Co-authored-by: Jan Kristof Nidzwetzki <jan@timescale.com>
2023-06-02 16:16:08 +03:00
Bharathy
b38c920266 MERGE support on hypertables
This patch does following:

1. Planner changes to create ChunkDispatch node when MERGE command
   has INSERT action.
2. Changes to map partition attributes from a tuple returned from
   child node of ChunkDispatch against physical targetlist, so that
   ChunkDispatch node can read the correct value from partition column.
3. Fixed issues with MERGE on compressed hypertable.
4. Added more testcases.
5. MERGE in distributed hypertables is not supported.
6. Since there is no Custom Scan (HypertableModify) node for MERGE
   with UPDATE/DELETE on compressed hypertables, we don't support this.

Fixes #5139
2023-05-27 10:29:11 +05:30
Jan Nidzwetzki
df32ad4b79 Optimize compressed chunk resorting
This patch adds an optimization to the DecompressChunk node. If the
query 'order by' and the compression 'order by' are compatible (query
'order by' is equal or a prefix of compression 'order by'), the
compressed batches of the segments are decompressed in parallel and
merged using a binary heep. This preserves the ordering and the sorting
of the result can be prevented. Especially LIMIT queries benefit from
this optimization because only the first tuples of some batches have to
be decompressed. Previously, all segments were completely decompressed
and sorted.

Fixes: #4223

Co-authored-by: Sotiris Stamokostas <sotiris@timescale.com>
2023-05-02 10:46:15 +02:00
Bharathy
44dc042bb3 Fixed transparent decompress chunk test which seem to be flaky. 2023-04-24 19:58:02 +05:30
Sven Klemm
744b44cc52 Fix parameterization in DecompressChunk path generation
All children of an append path are required to have the same parameterization
so we have to reparameterize when the selected path does not have the right
parameterization.
2023-04-20 17:20:04 +02:00
shhnwz
ca472ebb0d Fixed transparent decompress chunk
Transparent decompress chunk was added into to ignore list due to
the side effect of #5118. This issue is to fix the flaky nature of
the test.
2023-04-18 14:12:22 +05:30
Sven Klemm
90e54def8a Improve interpolate error message on datatype mismatch
Include information about the expected and the returned datatype
in the error details of interpolate.
2023-04-15 09:38:42 +02:00
Alexander Kuzmenkov
827684f3e2 Use prepared statements for parameterized data node scans
This allows us to avoid replanning the inner query on each new loop,
speeding up the joins.
2023-03-15 18:22:01 +04:00
Pallavi Sontakke
6be14423d5
Flag test space_constraint.sql.in for release run (#5380)
It was incorrectly flagged as requiring a debug build.

Disable-check: force-changelog-changed
2023-03-03 15:52:34 +05:30
Erik Nordström
b81033b835 Make data node command execution interruptible
The function to execute remote commands on data nodes used a blocking
libpq API that doesn't integrate with PostgreSQL interrupt handling,
making it impossible for a user or statement timeout to cancel a
remote command.

Refactor the remote command execution function to use a non-blocking
API and integrate with PostgreSQL signal handling via WaitEventSets.

Partial fix for #4958.

Refactor remote command execution function
2023-02-03 13:15:28 +01:00
Bharathy
3a8d294d58 SELECT from partial compressed chunks crashes
SELECT from partially compressed chunk crashes due to reference to NULL
pointer. When generating paths for DecompressChunk, uncompressed_partial_path
is null which is not checked, thus causing a crash. This patch checks for NULL
before calling create_append_path().

Fixes #5134
2023-01-02 20:40:30 +05:30
Sven Klemm
c0e9bb4a30 Fix enabling compression on caggs with renamed columns
On caggs with realtime aggregation changing the column name does
not update all the column aliases inside the view metadata.
This patch changes the code that creates the compression
configuration for caggs to get the column name from the materialization
hypertable instead of the view internals.

Fixes #5100
2022-12-19 10:46:37 +01:00
Lakshmi Narayanan Sreethar
3b3846b0ff Fix assertion failure in cursor_fetcher_rewind
The cursor_fetcher_rewind method assumes that the data node cursor is
rewind either after eof or when there is an associated request. But the
rewind can also occur once the server has generated required number of
rows by joining the relation being scanned with another regular
relation. In this case, the fetch would not have reached eof and there
will be no associated requests as the rows would have been already
loaded into the cursor causing the assertion in cursor_fetcher_rewind
to fail. Fixed that by removing the Assert and updating
cursor_fetcher_rewind to discard the response only if there is an
associated request.

Fixes #5053
2022-12-14 21:00:53 +05:30
Erik Nordström
fd42fe76fa Read until EOF in COPY fetcher
Ensure the COPY fetcher implementation reads data until EOF with
`PQgetCopyData()`. Also ensure the malloc'ed copy data is freed with
`PQfreemem()` if an error is thrown in the processing loop.

Previously, the COPY fetcher didn't read until EOF, and instead
assumed EOF when the COPY file trailer is received. Since EOF wasn't
reached, it required terminating the COPY with an extra call to the
(deprecated) `PQendcopy()` function.

Still, there are cases when a COPY needs to be prematurely terminated,
for example, when querying with a LIMIT clause. Therefore, distinguish
between "normal" end (when receiving EOF) and forceful end (cancel the
ongoing query).
2022-12-05 18:28:35 +01:00
Bharathy
7bfd28a02f Fix dist_fetcher_type test on PG15 2022-11-24 18:41:46 +05:30
Fabrízio de Royes Mello
a4356f342f Remove trailing whitespaces from test code 2022-11-18 16:31:47 -03:00
Bharathy
bfa641a81c INSERT .. SELECT on distributed hypertable fails on PG15
INSERT .. SELECT query containing distributed hypertables generates plan
with DataNodeCopy node which is not supported. Issue is in function
tsl_create_distributed_insert_path() where we decide if we should
generate DataNodeCopy or DataNodeDispatch node based on the kind of
query. In PG15 for INSERT .. SELECT query timescaledb planner generates
DataNodeCopy as rte->subquery is set to NULL. This is because of a commit
in PG15 where rte->subquery is set to NULL as part of a fix.

This patch checks if SELECT subquery has distributed hypertables or not
by looking into root->parse->jointree which represents subquery.

Fixes #4983
2022-11-17 21:18:23 +05:30
Sven Klemm
9744b4f3bc Remove BitmapScan support in DecompressChunk
We don't want to support BitmapScans below DecompressChunk
as this adds additional complexity to support and there
is little benefit in doing so.
This fixes a bug that can happen when we have a parameterized
BitmapScan that is parameterized on a compressed column and
will lead to an execution failure with an error regarding
incorrect attribute types in the expression.
2022-11-08 23:29:29 +01:00
Bharathy
2a64450651 Add new tests to gitignore list
Since new tests specific to PG15 were added, these tests which generated .sql files needs to be added to .gitnore
2022-11-07 22:14:39 +05:30
Bharathy
3a9688cc97 Extra Result node on top of CustomScan on PG15
On PG15 CustomScan by default is not projection capable, thus wraps this
node in Result node. THis change in PG15 causes tests result files which
have EXPLAIN output to fail. This patch fixes the plan outputs.

Fixes #4833
2022-11-07 21:20:08 +05:30
Alexander Kuzmenkov
da9af2c05d Do not cache the classify_relation result
It depends on the context, not only on the relation id. The same chunk
can be expanded both as a child of hypertable and as an independent
table.
2022-10-26 17:05:39 +04:00