3956 Commits

Author SHA1 Message Date
Fabrízio de Royes Mello
4a6650d170 Fix broken CAgg with JOIN repair function
The internal `cagg_rebuild_view_definition` function was trying to cast
a pointer to `RangeTblRef` but it actually is a `RangeTblEntry`.

Fixed it by using the already existing `direct_query` data struct to
check if there are JOINs in the CAgg to be repaired.
2023-04-25 15:20:48 -03:00
Ante Kresic
910663d0be Reduce decompression during UPDATE/DELETE
When updating or deleting tuples from a compressed chunk, we first
need to decompress the matching tuples then proceed with the operation.
This optimization reduces the amount of data decompressed by using
compressed metadata to decompress only the affected segments.
2023-04-25 15:49:59 +02:00
Lakshmi Narayanan Sreethar
3bf58dac02 Update windows package link in github action 2023-04-25 11:29:37 +05:30
Bharathy
44dc042bb3 Fixed transparent decompress chunk test which seem to be flaky. 2023-04-24 19:58:02 +05:30
Jan Nidzwetzki
2f194e6109 Make compression metadata column names reusable
Move the creation of metadata column names for min/max values to
separate functions to make the code reusable.
2023-04-24 13:42:00 +02:00
Jan Nidzwetzki
c54d8bd946 Add missing order by to compression_ddl tests
Some queries in compression_ddl had no order by. Therefore the output
order was not defined, which led to flaky tests.
2023-04-21 15:54:25 +02:00
Ante Kresic
583c36e91e Refactor compression code to reduce duplication 2023-04-20 22:27:34 +02:00
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
Ante Kresic
23b3f8d7a6 Block unique idx creation on compressed hypertable
This block was removed by accident, in order to support this we
need to ensure the uniqueness in the compressed data which is
something we should do in the future thus removing this block.
2023-04-20 16:22:03 +02:00
Alexander Kuzmenkov
12f3131f9e Post-release 2.10.2
Adjust the upgrade/downgrade scripts and add the tests.
2023-04-20 17:55:18 +04:00
Zoltan Haindrich
a0df8c8e6d Fix on-insert decompression for unique constraints
Inserting multiple rows into a compressed chunk could have bypassed
constraint check in case the table had segment_by columns.

Decompression is narrowed to only consider candidates by the actual
segment_by value.
Because of caching - decompression was skipped for follow-up rows of
the same Chunk.

Fixes #5553
2023-04-20 13:47:47 +02:00
Ante Kresic
a49fdbcffb Reduce decompression during constraint checking
When inserting into a compressed chunk with constraints present,
we need to decompress relevant tuples in order to do speculative
inserting. Usually we used segment by column values to limit the
amount of compressed segments to decompress. This change expands
on that by also using segment metadata to further filter
compressed rows that need to be decompressed.
2023-04-20 12:17:12 +02:00
Alexander Kuzmenkov
28d9db1af9 Changelog for 2.10.2
## 2.10.2 (2023-04-20)

**Bugfixes**
* #5410 Fix file trailer handling in the COPY fetcher
* #5446 Add checks for malloc failure in libpq calls
* #5233 Out of on_proc_exit slots on guc license change
* #5428 Use consistent snapshots when scanning metadata
* #5499 Do not segfault on large histogram() parameters
* #5470 Ensure superuser perms during copy/move chunk
* #5500 Fix when no FROM clause in continuous aggregate definition
* #5433 Fix join rte in CAggs with joins
* #5556 Fix duplicated entries on timescaledb_experimental.policies view
* #5462 Fix segfault after column drop on compressed table
* #5543 Copy scheduled_jobs list before sorting it
* #5497 Allow named time_bucket arguments in Cagg definition
* #5544 Fix refresh from beginning of Continuous Aggregate with variable time bucket
* #5558 Use regrole for job owner
* #5542 Enable indexscan on uncompressed part of partially compressed chunks

**Thanks**
* @nikolaps for reporting an issue with the COPY fetcher
* @S-imo-n for reporting the issue on Background Worker Scheduler crash
* @geezhu for reporting issue on segfault in historgram()
* @mwahlhuetter for reporting the issue with joins in CAggs
* @mwahlhuetter for reporting issue with duplicated entries on timescaledb_experimental.policies view
* @H25E for reporting error refreshing from beginning of a Continuous Aggregate with variable time bucket
2023-04-20 09:54:39 +04:00
Konstantina Skovola
5633960f8b Enable indexscan on uncompressed part of partially compressed chunks
This was previously disabled as no data resided on the
uncompressed chunk once it was compressed, but this is not
the case anymore with partially compressed chunks, so we
enable indexscan for the uncompressed chunk again.

Fixes #5432

Co-authored-by: Ante Kresic <ante.kresic@gmail.com>
2023-04-18 17:29:08 +03: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
Mats Kindahl
9a64385f34 Use regrole for job owner
Instead of using a user name to register the owner of a job, we use
regrole. This allows renames to work properly since the underlying OID
does not change when the owner name changes.

We add a check when calling `DROP ROLE` that there is no job with that
owner and generate an error if there is.
2023-04-18 08:57:52 +02:00
Alexander Kuzmenkov
20db884bd7 Increase remote tuple and startup costs
Our cost model should be self-consistent, and the relative values for
the remote tuple and startup costs should reflect their real cost,
relative to costs of other operations like CPU tuple cost.

For example, now remote costs are set even lower than the parallel tuple
and startup cost. Contrary to that, their real world cost is going to be
an order of magnitude higher or more, because parallel tuples are sent
through shared memory, and remote tuples are sent over the network.

Increasing these costs leads to query plan improvements, e.g. we start
to favor the GROUP BY pushdown in some cases.
2023-04-17 22:22:08 +04:00
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
Alexander Kuzmenkov
d32224a914 Add labels to backported PRs
Makes it easier to check what was done when looking at the release
milestone.
2023-04-17 13:26:57 +04:00
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
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
Lakshmi Narayanan Sreethar
a383c8dd4f Copy scheduled_jobs list before sorting it
The start_scheduled_jobs function mistakenly sorts the scheduled_jobs
list in-place. As a result, when the ts_update_scheduled_jobs_list
function compares the updated list of scheduled jobs with the existing
scheduled jobs list, it is comparing a list that is sorted by job_id to
one that is sorted by next_start time. Fix that by properly copying the
scheduled_jobs list into a new list and use that for sorting.

Fixes #5537
2023-04-14 15:59:57 +05:30
Lakshmi Narayanan Sreethar
b10139ba48 Update bgw_custom testcase
Added a few cleanup steps and updated a test logic to make the testcase
runs more stable.
2023-04-14 15:59:57 +05:30
Maheedhar PV
b136bb554b Run dist_move_chunk as a solo test in PG15.2
Running the test dist_move_chunk in parallel can
cause a timeouts(deadlock) in other tests running
in parallel on PG15.2. Force the test to run solo.
2023-04-14 14:26:50 +05:30
Maheedhar PV
ca240c33ca Build failure on windows
The cmake call to "find_package(OpenSSL)" on windows may set the
variable OPENSSL_LIBRARIES to a non-standard list which might include
non path items such as "debug", "optimized". These non-standard
elements in the list would cause the link failure with error
"LNK1104".

Fix:
Check and retain only valid paths in OPENSSL_LIBRARIES list.

closes#407
2023-04-13 17:10:43 +05:30
Ante Kresic
464d20fb41 Propagate vacuum/analyze to compressed chunks
With recent changes, we enabled analyze on uncompressed chunk tables
for compressed chunks. This change includes analyzing the compressed
chunks table when analyzing the hypertable and its chunks,
enabling us to remove the generating stats when compressing chunks.
2023-04-13 12:15:32 +02: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
Fabrízio de Royes Mello
09565acae4 Fix timescaledb_experimental.policies duplicates
Commit 16fdb6ca5e introduced `timescaledb_experimental.policies` view
to expose the Continuous Aggregate policies but the current JOINS over
our catalog are not accurate.

Fixed it by properly JOIN the underlying catalog tables to expose the
correct information without duplicates about the Continuous Aggregate
policies.

Fixes #5492
2023-04-12 15:28:29 -03:00
Fabrízio de Royes Mello
f6c8468ee6 Fix timestamp out of range refreshing CAgg
When refreshing from the beginning (window_start=NULL) of a
Continuous Aggregate with variable time bucket we were getting a
`timestamp out of range` error.

Fixed it by setting `-Infinity` when passing `window_start=NULL` when
refreshing a Continuous Aggregate with variable time bucket.

Fixes #5474, #5534
2023-04-12 14:50:04 -03:00
Mats Kindahl
3cc8a4ca34 Fix error message for continuous aggregates
Several error messages for continuous aggregates are not following the
error message style guidelines at
https://www.postgresql.org/docs/current/error-style-guide.html

In particular, they do not write the hints and detailed messages as
full sentences.
2023-04-12 18:34:56 +02:00
Sven Klemm
f0623a8c38 Skip Ordered Append when only 1 child node is present
This is mostly a cosmetic change. When only 1 child is present there
is no need for ordered append. In this situation we might still
benefit from a ChunkAppend node here due to runtime chunk exclusion
when we have non-immutable constraints, so we still add the ChunkAppend
node in that situation even with only 1 child.
2023-04-12 13:19:16 +02:00
Sven Klemm
0595ff0888 Move type support functions into _timescaledb_functions schema 2023-04-12 12:48:34 +02:00
Sven Klemm
2d7eb18f24 Drop unused SQL functions
This patch drops the following internal SQL functions which were
unused:
  _timescaledb_internal.is_main_table(regclass);
  _timescaledb_internal.is_main_table(text, text);
  _timescaledb_internal.hypertable_from_main_table(regclass);
  _timescaledb_internal.main_table_from_hypertable(integer);
  _timescaledb_internal.time_literal_sql(bigint, regtype);
2023-04-12 11:00:18 +02:00
Ante Kresic
84b6783a19 Fix chunk status when inserting into chunks
While executing compression operations in parallel with
inserting into chunks (both operations which can potentially
change the chunk status), we could get into situations where
the chunk status would end up inconsistent. This change re-reads
the chunk status after locking the chunk to make sure it can
decompress data when handling ON CONFLICT inserts correctly.
2023-04-12 10:50:44 +02:00
Ante Kresic
54074f1fd4 Add more compression DML isolation tests
Verify that insertion into compressed chunks does not block
each other if the chunks is already partially compressed. Also
check that using the RETURNING clause works the same.
2023-04-11 17:30:08 +02:00
Ante Kresic
dc5bf3b32e Test compression DML with physical layout changes
These tests try to verify that changing physical layout
of chunks (either compressed or uncompressed) should
yield consistent results. They also verify index mapping
on compressed chunks is handled correctly.
2023-04-11 17:30:08 +02:00
Fabrízio de Royes Mello
9a466ca185 Silence WARNING after extension update
Commit 8afdddc2da added the first step for deprecating the old format
of Continuous Aggregate but just for PostgreSQL 15 and later versions.

During the extension update we emit a message about the deprecation but
this has being emited even if the user is using PostgreSQL versions
before 15.

Fixed it by emiting the WARNING just when PostgreSQL version is greater
or equal to 15.
2023-04-11 09:01:52 -03:00
Sven Klemm
04f43335de Move aggregate support function into _timescaledb_functions
This patch moves the support functions for histogram, first and last
into the _timescaledb_functions schema. Since we alter the schema
of the existing functions in upgrade scripts and do not change the
aggregates this should work completely transparently for any user
objects using those aggregates.
2023-04-11 13:11:07 +02:00
Konstantina Skovola
3814a3f351 Properly format license error hint
Commit 57fde383b3dddd0b52263218e65a0135981c2d34 changed the
messaging but did not format the error hint correctly.
This patch fixes the error hint.

Fixes #5490
2023-04-10 14:06:39 +03:00
Alexander Kuzmenkov
8c77be6c68 Look up compressed column metadata only at planning time
Now we look them up again at execution time, which adds up for tables
with a large number of chunks.

This gives about 15% speedup (100 mcs) on a small query on a table from
tests with 50 chunks:
`select id, ts, value from metric_compressed order by id, ts limit 100;`
2023-04-10 14:45:11 +04:00
Konstantina Skovola
df70f3e050 Remove unused variable in tsl_get_compressed_chunk_index_for_recompression
Commit 72c0f5b25e569015aacb98cc1be3169a1720116d introduced
an unused variable. This patch removes it.
2023-04-06 10:58:57 +03:00
Zoltan Haindrich
975e9ca166 Fix segfault after column drop on compressed table
Decompression produces records which have all the decompressed data
set, but it also retains the fields which are used internally during
decompression.
These didn't cause any problem - unless an operation is being done
with the whole row - in which case all the fields which have ended up
being non-null can be a potential segfault source.

Fixes #5458 #5411
2023-04-06 08:49:54 +02:00
Sven Klemm
feef9206fa Add _timescaledb_functions schema
Currently internal user objects like chunks and our functions
live in the same schema making locking down that schema hard.
This patch adds a new schema _timescaledb_functions that is meant
to be the schema used for timescaledb internal functions to
allow separation of code and chunks or other user objects.
2023-04-05 21:01:24 +02:00
Fabrízio de Royes Mello
6440bb3477 Remove unused function
Remove unused function `invalidation_threshold_htid_found`.
2023-04-05 11:38:08 -03:00
Bharathy
1fb058b199 Support UPDATE/DELETE on compressed hypertables.
This patch does following:

1. Executor changes to parse qual ExprState to check if SEGMENTBY
   column is specified in WHERE clause.
2. Based on step 1, we build scan keys.
3. Executor changes to do heapscan on compressed chunk based on
   scan keys and move only those rows which match the WHERE clause
   to staging area aka uncompressed chunk.
4. Mark affected chunk as partially compressed.
5. Perform regular UPDATE/DELETE operations on staging area.
6. Since there is no Custom Scan (HypertableModify) node for
   UPDATE/DELETE operations on PG versions < 14, we don't support this
   feature on PG12 and PG13.
2023-04-05 17:19:45 +05:30
Sven Klemm
c2941a3f9a Fix windows package test
Use the windows packages from the github release for package testing.
2023-04-04 15:53:22 +02:00
Erik Nordström
2e6c6b5c58 Refactor and optimize distributed COPY
Refactor the code path that handles remote distributed COPY. The
main changes include:

* Use a hash table to lookup data node connections instead of a list.
* Refactor the per-data node buffer code that accumulates rows into
  bigger CopyData messages.
* Reduce the default number of rows in a CopyData message to 100. This
  seems to improve throughput, probably striking a better balance
  between message overhead and latency.
* The number of rows to send in each CopyData message can now be
  changed via a new foreign data wrapper option.
2023-04-04 15:35:54 +02:00
Ildar Musin
c6b9f50978 Fix OSM chunks exclusion from append paths
OSM chunks have their own fdw_private which conflicts with checks in
the MergeAppend code path causing segfaults. This commit fixes this by
returning early when there is an OSM chunk in the MergeAppendPath.
2023-04-03 17:46:23 +02:00
Nikhil Sontakke
517dee9f6b Add test for superuser chunk copy/move
Add isolation test case to check that the chunk object created during
chunk copy/move operation on the destination datanode always has
superuser credentials till the end of the operation.
2023-04-03 11:31:58 +05:30
Rafia Sabih
ff5959f8f9 Handle when FROM clause is missing in continuous aggregate definition
It now errors out for such a case.

Fixes #5500
2023-03-29 22:29:16 +02:00