793 Commits

Author SHA1 Message Date
Fabrízio de Royes Mello
0ae6f95646 Use DROP DATABASE ... WITH (FORCE) on tests
PG13 introduced an option to DROP DATABASE statement to terminate all
existing connections to the target database. Now that our minor
supported version is PG13 make sense to use it on regression tests in
order to avoid potential flaky tests.
2023-09-26 14:35:23 -03:00
Jan Nidzwetzki
d9e4a71af3 Ensure database is unused in bgw_launcher test
The bgw_launcher test changes the tablespace for a database. However,
this requires that the database is used and no BGW are accessing the
database. This PR ensures that the background workers are stopped before
the tablespace is changed.
2023-09-26 09:58:44 +02:00
Jan Nidzwetzki
683e2bcf18 Schedule compression policy more often
By default, the compression policy is scheduled for every
chunk_time_interval / 2 in the current implementation, equal to three
days and twelve hours with our default settings. This schedule interval
was sufficient for previous versions of TimescaleDB. However, with the
introduction of features like mutable compression and ON CONFLICT .. DO
UPDATE queries, regular DML operations decompress data. To ensure that
modified data is compressed earlier, this patch reduces the schedule
interval of the compression policy to run at least every 12 hours.
2023-09-22 12:30:57 +02:00
Jan Nidzwetzki
14e275a514 Make sure BGW are stopped in test teardown
This patch stops the background worker in the bgw_launcher test teardown
before the database is dropped. The current version of the test is flaky
because sometimes the database cannot be dropped due to BGW activity.
2023-09-21 15:34:22 +02:00
Jan Nidzwetzki
8fac069be3 Make pg_join test more deterministic
The pg_join regression test is flaky. This PR adds some analyze calls
and increases the size of one table to make the test outcome more
deterministic.
2023-09-19 11:56:27 +02:00
Jan Nidzwetzki
28b801869a Don't build partition info for local hypertables
So far, we have created fake partitioning info for hypertables if the
PostgreSQL setting 'enable_partitionwise_aggregate' is set. This causes
PostgreSQL to push down partial aggregations to the chunk level.
However, the PostgreSQL code has some drawbacks because the query is
replanned and optimizations like ChunkAppend are lost. Since #5596 we
have implemented our own code to push down partial aggregations.
Therefore, we can ignore the PostgreSQL setting from now on.
2023-09-15 08:42:52 +02:00
Konstantina Skovola
38f809d4b5 Move view creation in setup.repair inside if
Previously the view was created outside the if, leading to an unexpected
error when attempting to drop a dependency of the view in the
extension upgrade script.
2023-09-07 18:19:32 +03:00
Lakshmi Narayanan Sreethar
44e41c12ab Fix segfault in set_integer_now_func
When an invalid function oid is passed to set_integer_now_func, it finds
out that the function oid is invalid but before throwing the error, it
calls ReleaseSysCache on an invalid tuple causing a segfault. Fixed that
by removing the invalid call to ReleaseSysCache.

Fixes #6037
2023-09-06 15:11:07 +05:30
Lakshmi Narayanan Sreethar
8e941b80ae Fix incorrect row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output
INSERT ... ON CONFLICT statements record few metrics in the ModifyTable
node's instrument but they get overwritten by hypertable_modify_explain
causing wrong output in EXPLAIN ANALYZE statments. Fix it by saving the
metrics into HypertableModify node before replacing them.

Fixes #6014
2023-09-01 00:44:55 +05:30
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
Jan Nidzwetzki
4516df285c Make up/downgrade test deterministic
Two queries in post.continuous_aggs.v3.sql had no ORDER BY
specification. Therefore, the query output was not deterministic. This
patch adds the missing ORDER BY.
2023-08-29 09:55:41 +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
28c7457faf Move scheduler 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:

- restart_background_workers()
- stop_background_workers()
- start_background_workers()
- alter_job_set_hypertable_id(integer,regclass)
2023-08-28 14:21:11 +02:00
Sven Klemm
0da18a93b5 Move chunk 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:

- calculate_chunk_interval(int, bigint, bigint)
- chunk_status(regclass)
- chunks_in(record, integer[])
- chunk_id_from_relid(oid)
- show_chunk(regclass)
- create_chunk(regclass, jsonb, name, name, regclass)
- set_chunk_default_data_node(regclass, name)
- get_chunk_relstats(regclass)
- get_chunk_colstats(regclass)
- create_chunk_table(regclass, jsonb, name, name)
- freeze_chunk(regclass)
- unfreeze_chunk(regclass)
- drop_chunk(regclass)
- attach_osm_table_chunk(regclass, regclass)
2023-08-24 09:33:59 +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
Sven Klemm
183362e17b Move size_util 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:

- relation_size(regclass)
- data_node_hypertable_info(name, name, name)
- data_node_chunk_info(name, name, name)
- hypertable_local_size(name, name)
- hypertable_remote_size(name, name)
- chunks_local_size(name, name)
- chunks_remote_size(name, name)
- range_value_to_pretty(bigint, regtype)
- get_approx_row_count(regclass)
- data_node_compressed_chunk_stats(name, name, name)
- compressed_chunk_local_stats(name, name)
- compressed_chunk_remote_stats(name, name)
- indexes_local_size(name, name)
- data_node_index_size(name, name, name)
- indexes_remote_size(name, name, name)
2023-08-22 12:05:23 +02:00
Jan Nidzwetzki
e99832727a Place data in first/last function in correct mctx
So far, the ts_bookend_deserializefunc() function has allocated the
deserialized data in the current memory context. This data could be
removed before the aggregation is finished. This patch moves the data
into the aggregation memory context.
2023-08-22 08:08:31 +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
Sven Klemm
a640d7ddf1 Fix psql \if expression
The expression part of the psql \if cannot contain actual SQL expression
and is instead much more limited.

A valid value is any unambiguous case-insensitive match for one of: true, false, 1, 0, on, off, yes, no.

See https://www.postgresql.org/docs/current/app-psql.html
2023-08-21 12:55:58 +02:00
Sven Klemm
0dd06e919f Move get_create_command into _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 get_create_command function.
2023-08-21 11:29:37 +02:00
Jan Nidzwetzki
154bbbb01a Perform startup chunk exclusion in parallel leader
The parallel version of the ChunkAppend node uses shared memory to
coordinate the plan selection for the parallel workers. If the workers
perform the startup exclusion individually, it may choose different
subplans for each worker (e.g., due to a "constant" function that claims
to be constant but returns different results). In that case, we have a
disagreement about the plans between the workers.  This would lead to
hard-to-debug problems and out-of-bounds reads when pstate->next_plan is
used for subplan selection.

With this patch, startup exclusion is only performed in the parallel
leader. The leader stores this information in shared memory. The
parallel workers read the information from shared memory and don't
perform startup exclusion.
2023-08-15 10:25:46 +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
Konstantina Skovola
2cb42a62f9 Remove test_status calls from telemetry test
Due to the postman-echo endpoint redirecting http requests to https, we
get an unexpected 301 response in the tests, leading to repeated test
failures. This commit removes these function calls.
2023-08-10 18:04:01 +03:00
Jan Nidzwetzki
9a2dfbfb83 Improved parallel DecompressChunk worker selection
This PR improves the way the number of parallel workers for the
DecompressChunk node are calculated. Since
1a93c2d482b50a43c105427ad99e6ecb58fcac7f, no partial paths for small
relations are generated, which could cause a fallback to a sequential
plan and a performance regression. This patch ensures that for all
relations, a partial path is created again.
2023-08-10 12:38:14 +02:00
Mats Kindahl
8a2b6a03e0 Add weird user names to update test
Since we want to be able to handle update of weird user names we add
some to the update tests and create policies on them. This will create
jobs with the strange name as owner.
2023-08-08 16:22:01 +02:00
Dmitry Simonenko
2863daf3df Support CREATE INDEX ONLY ON main table
This PR adds support for CREATE INDEX ONLY ON clause which allows to
create index only on the main table excluding chunks.

Fix #5908
2023-08-03 15:51:57 +03:00
Nikhil Sontakke
b2773aa344 Fix crash in COPY from program returning error
Reset the errcallback appropriately so that the ereport in case
of a PROGRAM returning error can work correctly.
2023-08-02 12:41:19 +05:30
Lakshmi Narayanan Sreethar
e5691bee11 Cleanup PG12 specific code from source and test files
Removed the PG12 specific macros and all the now, dead code. Also updated
the testcases which had workarounds in place to make them compatible
with PG12.
2023-07-25 16:00:18 +05:30
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
Rafia Sabih
1bd527375d Rectify interval calculation
For continuous aggregates with variable bucket size, the interval
was wrongly manipulated in the process. Now it is corrected by
creating a copy of interval structure for validation purposes
and keeping the original structure untouched.

Fixes #5734
2023-07-12 23:56:04 +02:00
Erik Nordström
e2e7e5f286 Make hypertables support replica identity
Add support for setting replica identity on hypertables via ALTER
TABLE. The replica identity is used in logical replication to identify
rows that have changed.

Currently, replica identity can only be altered on hypertables via the
root; changing it directly on chunks will raise an error.
2023-06-27 15:07:40 +02:00
Zoltan Haindrich
769646bdb6 Fix issues with scripts/test_update_smoke.sh
The test was failing on first run by leaving a database behind as a
sideeffect.
Between two steps the extension was dropped; without a proper cleanup.
A non-existent sql function was called during cleanup.

This patch also removes the "debug mode" and every execution will leave
the logs/etc in the /tmp directory for further inspection.
2023-06-07 13:30:21 +02:00
Jan Nidzwetzki
b8e674c137 Fixed handling of NULL values in bookend_sfunc
In the function bookend_sfunc values are compared. If the first
processed value is a NULL value, it was copied into the state of the
sfunc. A following comparison between the NULL value of the state and a
non-NULL value could lead to a crash.

This patch improves the handling of NULL values in bookend_sfunc.
2023-06-07 12:38:40 +02:00
epgts
d6030a32d8
Teach loader to load OSM extension (#5679) 2023-05-31 13:18:48 -05: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
Mats Kindahl
3947c01124 Support sending telemetry event reports
Add table `_timescaledb_catalog.telemetry_event` table containing
events that should be sent out with telemetry reports. The table will
be truncated after reporting being generated.
2023-05-12 16:03:05 +02:00
Dmitry Simonenko
8ca17e704c Fix ALTER TABLE SET with normal tables
Running ALTER TABLE SET with multiple SET clauses on a regular PostgreSQL table
produces irrelevant error when timescaledb extension is installed.

Fix #5641
2023-05-04 16:32:25 +03:00
Nikhil Sontakke
ed8ca318c0 Quote username identifier appropriately
Need to use quote_ident() on the user roles. Otherwise the
extension scripts will fail.

Co-authored-by: Mats Kindahl <mats@timescale.com>
2023-04-28 16:53:43 +05:30
Fabrízio de Royes Mello
b16bf3b100 Fix post repair tests
Commit 3f9cb3c2 introduced new repair tests for broken Continuous
Aggregates with JOIN clause but in the post.repair.sql we not properly
calling the post.repair.cagg_joins.sql because a wrong usage of psql
`if` statement.
2023-04-17 14:47:06 -03:00
Fabrízio de Royes Mello
a3d778f7a0 Add CI check for missing gitignore entries
Whenever we create a template sql file (*.sql.in) we should add the
respective .gitignore entry for the generated test files.

So added a CI check to check for missing gitignore entries for generated
test files.
2023-04-14 12:46:20 -03:00
Rafia Sabih
3f9cb3c27a Pass join related structs to the cagg rte
In case of joins in the continuous aggregates, pass the required
structs to the new rte created. These values are required by the
planner to finally query the materialized view.

Fixes #5433
2023-04-13 04:57:33 +02:00
Mats Kindahl
777c599a34 Do not segfault on large histogram() parameters
There is a bug in `width_bucket()` causing an overflow and subsequent
NaN value as a result of dividing with `+inf`. The NaN value is
interpreted as an integer and hence generates an index out of range for
the buckets.

This commit fixes this by generating an error rather than
segfaulting for bucket indexes that are out of range.
2023-03-28 12:47:02 +02:00
Konstantina Skovola
8cccc375fb Add license information to extension description
Fixes #5436
2023-03-20 13:27:41 -03:00
Zoltan Haindrich
790b322b24 Fix DEFAULT value handling in decompress_chunk
The sql function decompress_chunk did not filled in
default values during its operation.

Fixes #5412
2023-03-16 09:16:50 +01:00
Bharathy
c13ed17fbc Fix DELETE command tag
DELETE on hypertables always reports 0 as affected rows.
This patch fixes this issue.
2023-03-07 20:45:12 +05:30
Sven Klemm
f680b99529 Fix assertion in calculate_chunk_interval for negative target size
When called with negative chunk_target_size_bytes
calculate_chunk_interval will throw an assertion. This patch adds
error handling for this condition. Found by sqlsmith.
2023-03-07 14:50:57 +01:00
Mats Kindahl
a6ff7ba6cc Rename columns in old-style continuous aggregates
For continuous aggregates with the old-style partial aggregates
renaming columns that are not in the group-by clause will generate an
error when upgrading to a later version. The reason is that it is
implicitly assumed that the name of the column is the same as for the
direct view. This holds true for new-style continous aggregates, but is
not always true for old-style continuous aggregates. In particular,
columns that are not part of the `GROUP BY` clause can have an
internally generated name.

This commit fixes that by extracting the name of the column from the
partial view and use that when renaming the partial view column and the
materialized table column.
2023-03-03 14:02:37 +01:00
Alexander Kuzmenkov
fd66f5936a Warn about mismatched chunk cache sizes
Just noticed abysmal INSERT performance when experimenting with one of
our customers' data set, and turns out my cache sizes were
misconfigured, leading to constant hypertable chunk cache thrashing.
Show a warning to detect this misconfiguration. Also use more generous
defaults, we're not supposed to run on a microwave (unlike Postgres).
2023-02-14 19:32:41 +04:00
Bharathy
9a2cbe30a1 Fix ChunkAppend, ConstraintAwareAppend child subplan
When TidRangeScan is child of ChunkAppend or ConstraintAwareAppend node, an
error is reported as "invalid child of chunk append: Node (26)". This patch
fixes the issue by recognising TidRangeScan as a valid child.

Fixes: #4872
2023-01-18 18:06:30 +05:30