4553 Commits

Author SHA1 Message Date
Fabrízio de Royes Mello
0254abd9c2 Remove useless table lock
In ae21ee96 we fixed a race condition when running a query to get the
hypertable sizes and one or more chunks was dropped in a concurrent
session leading to exception because the chunks does not exist.

In fact the table lock introduced is useless because we also added
proper joins with Postgres catalog tables to ensure that the relation
exists in the database when calculating the sizes. And even worse with
this table lock now dropping chunks wait for the functions that
calculate the hypertable sizes.

Fixed it by removing the useless table lock and also added isolation
tests to make sure we'll not end up with race conditions again.
2023-11-15 12:17:33 -03:00
Sven Klemm
49121aec00 Bump PG versions used in CI
Use newly released 13.13, 14.10, 15.5 and 16.1 in CI.
2023-11-14 17:01:23 +01:00
Jan Nidzwetzki
ecb4c21313 Fix solo test for dist_util
In 068534e31730154b894dc8e4fb5315054e1ae51c we make the dist_util
regression test version specific. However, the solo test declaration for
this test was not adjusted, which makes this test flaky. This PR fixes
the declaration.
2023-11-14 16:37:51 +01:00
Fabrízio de Royes Mello
b917eedea0 Fix sanitizer output log directory
In the sanitizer workflow we're trying to upload sanitizer output
logs from `${{ github.workspace }}/sanitizer` but in the ASAN_OPTIONS,
LSAN_OPTIONS and UBSAN_OPTIONS we were setting output logs to another
place.

Example of workflow that files were not found in the provided path:
https://github.com/timescale/timescaledb/actions/runs/6830847083
2023-11-14 11:12:03 -03:00
Mats Kindahl
0892d909df Move issue to Done column when closed
Workflow actions does not move issue to Done column when there is a
comment and the issue is then closed. This commit deals with that by
handling the closed event and move it to the Done column as well as
removing labels that can interfere with processing.
2023-11-14 13:35:17 +01:00
Fabrízio de Royes Mello
3e08d21ace Add SQL function cagg_validate_query
With this function is possible to execute the Continuous Aggregate query
validation over an arbitrary query string, without the need to actually
create the Continuous Aggregate.

It can be used, for example, to check for most frequent queries maybe
using `pg_stat_statements`, validate them and check if there are queries
that potenttialy can turned into a Continuous Aggregate.
2023-11-14 08:29:26 -03:00
Mats Kindahl
483ddcd4de Make _timescaledb_functions.makeaclitem strict
Function `_timescaledb_functions.makeaclitem` needs to be strict since
if it is called with NULL values, it should return NULL.
2023-11-10 14:08:09 +01:00
Alexander Kuzmenkov
1d7a7e4e25 Fix the PG16 test references
I forgot to update them in #6212
2023-11-09 21:48:43 +01:00
Alexander Kuzmenkov
06e9fa0eee Read and decompress columns lazily
We will decompress the compressed columns on demand, skipping them if
the vectorized quals don't pass for the entire batch. This allows us to
avoid reading some columns, saving on IO. The number of batches that are
entirely filtered out is reflected in EXPLAIN ANALYZE as 'Batches
Removed by Filters'.
2023-11-09 17:01:38 +01:00
Fabrízio de Royes Mello
d0021d5f38 Fix segfault creating cagg with NULL bucket width
When creating a Continuous Aggregate using a NULL `bucket_width` in the
`time_bucket` function it lead to a segfault, for example:

CREATE MATERIALIZED VIEW cagg WITH (timescaledb.continuous) AS
SELECT time_bucket(NULL, time), count(*)
FROM metrics
GROUP BY 1;

Fixed it by raising an ERROR if a NULL `bucked_width` is used during the
Continuous Aggregate query validation.
2023-11-09 09:44:02 -03:00
Jan Nidzwetzki
b423d14ef5 Adjust restore points test for PG 16
Currently, MN is not supported on PG16. Therefore, the creation of
distributed restore points fails on PG16. This patch disables the CI
test for this PG version.
2023-11-09 11:43:49 +01:00
Mats Kindahl
f2310216a8 Repair relacl on extension upgrade
If users have accidentally been removed from `pg_authid` as a result of
bugs where dropping a user did not revoke privileges from all tables
where the had privileges, it will not be possible to create new chunks
since these require the user to be found when copying the privileges
for the parent table (either compressed hypertable or normal
hypertable).

To fix the situation, we repair the `pg_class` table when updating the
extension by modifying the `relacl` for relations and remove any user
that do not have an entry in `pg_authid`.

A repair function `_timescaledb_functions.repair_relation_acls` is
added that will perform the job. A `makeaclitem` from PG16 that accepts
a list of comma and used as part of the repair is also added as
`_timescaledb_functions.makeaclitem`.
2023-11-09 11:35:27 +01:00
Jan Nidzwetzki
418f5c5610 Stabilize CI by excluding debug messages
The CI tests on Windows log the creation of a new WAL file in a
non-deterministic way. This message causes the regression tests to fail.
This PR removed these messages from the test output.
2023-11-09 11:28:32 +01:00
Jan Nidzwetzki
ff88de9b1c Determine data type of vector agg at plan stage
This patch adds the support for the dynamic detection of the data type
for a vectorized aggregate. In addition, it removes the hard-coded
integer data type and initializes the decompression_map properly. This
also fixes an invalid memory access.
2023-11-09 08:25:15 +01:00
Jan Nidzwetzki
e90280a07e Add support for startup chunk exclusion with aggs
In ba9b81854c8c94005793bccff29433f6086e5274 we added support for
chunk-wise aggregates. The pushdown of the aggregate breaks the startup
exclusion logic of the ChunkAppend node. This PR adds the support for
startup chunk exclusion with chunk-wise aggs.

Fixes: #6282
2023-11-08 21:58:59 +01:00
Fabrízio de Royes Mello
1b3f4a7035 PG16: Fix ignored workflow for Windows on CI
In ef505760 we enabled PG16 on Windows CI but forgot the add it to the
ignored workflow.
2023-11-08 17:53:59 -03:00
Fabrízio de Royes Mello
d602be4d81 PG16: Fix flaky test
In PG16 new collations named `en_US` and `en-US` on Windows bootstrap
that are incompatible with UTF-8. So added the `collencoding` to the
order of the query that determine the collation name to get another
compatible collation.
2023-11-08 15:26:42 -03:00
Fabrízio de Royes Mello
9d4ffc94af PG16: Enable Windows on CI
Now that PG16 is approved on Chocolatey we can finally enable Windows on
CI.

https://community.chocolatey.org/packages/postgresql16
2023-11-08 15:26:42 -03:00
Alexander Kuzmenkov
e1331c6398 Improve diagnostics for cagg trigger errors
Print more precise error message and the affected chunk.
2023-11-08 14:47:56 +01:00
Alexander Kuzmenkov
6bca947762 Fix ABI check on PG 16
This changes the way of pinning OpenSSL 1.1, so that it supports the
case of PG16 where both the oldest and the newest alpine docker images
have OpenSSL 3. Depending on the PG versions, both old and new images
might have either 1.1 or 3, so we first try to install the versioned
1.1 package, and if it fails, it means the unversioned package is 1.1
  and we install it instead.
2023-11-08 13:35:14 +01:00
Jan Nidzwetzki
6e796878d7 Fix CI configuration for PG 16
In fbc1fbb64bed5e82bc3992dc4ac547bb172d46c3 PG 16 was enabled in the CI.
However, PG16 was not added to PG_LATEST. Jobs that try to modify the
build matrix (e.g., the Sanitizer) fail since they can not find an
entry for PG 16. This patch fixes the build configuration.
2.13.0-dev
2023-11-07 08:18:07 +01:00
Fabrízio de Royes Mello
56a708bde6 PG16: Enable SQLSmith on CI 2023-11-06 12:07:12 -03:00
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
Alexander Kuzmenkov
c34fd0b06c Do not use partial indexes for compression
They refer only to a subset of the table.
2023-11-06 13:34:33 +01:00
Jan Nidzwetzki
2422f51f69 Add debug messages to job scheduler
This patch adds some further debug messages to the job scheduler. This
allows to debug the scheduled jobs in production environments.
2023-11-06 11:40:26 +01:00
Jan Nidzwetzki
9b7cb831ed Simplified aggregation type detection logic
a094f175eb7c98173c78f557880ccd2d89b791f8 changes the
contains_path_plain_or_sorted_agg function. However, a return statement
is missing to properly return the result of subpaths. This pull request
addresses the logic issues and simplifies the check.
2023-11-06 11:39:27 +01:00
Fabrízio de Royes Mello
68e39a3d56 PG16: Fix telemetry tests without OpenSSL
Telemetry tests without OpenSSL was failing to build because PG16
converted the *GetDatum() and DatumGet*() macros to inline functions
that enable compiler to catch wrong usage of Datums.

postgres/postgres@c8b2ef0
2023-11-05 16:09:26 -03:00
Fabrízio de Royes Mello
18bcf16257 Use last package Postgres version on Windows
Sometime ago we freeze Postgres packages on Windows (14.5.1 and 15.0.1)
due to some issues on chocolatey.

Now is time to remove it and use the latest version.
2023-11-04 16:21:22 -03: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
Sven Klemm
f6bd108f96 Fix compression for tables with large oids
When trying to compress a table with an oid > 2^31 an error about
bitmapset not allowing negative members would be raised because
we tried to store the oids in a bitmapset.
Oids should not be stored in Bitmapsets as storing Oids that way
is very inefficient and may potentially consume a lot of memory
depending on the values of the oids. Storing them as list is more
efficient instead.
2023-11-04 18:34:47 +01:00
Fabrízio de Royes Mello
fbc1fbb64b PG16: Enable CI
This commit enables PG16 in the following workflows:
* Regression Linux (including 32bit)
* ABI test
* Memory tests
* Sanitizer tests
* Coverity
2023-11-04 13:29:02 -03:00
Fabrízio de Royes Mello
b4bb3a0c81 PG16: Fix transparent decompression output tests 2023-11-03 17:19:33 -03:00
Konstantina Skovola
187b124d17 Fix wrong use of Const instead of Datum
PG16 converted the *GetDatum() and DatumGet*() macros to inline
functions. This enabled the compiler to catch a wrong use of Const
instead of Datum.

postgres/postgres@c8b2ef0
2023-11-03 17:07:12 +02:00
Sven Klemm
c58a640a8e PG16: Fix join recursion
Mark the EquivalenceMember for the compressed chunk as derived to
prevent an infinite recursion.
2023-11-03 14:57:32 +01:00
Sven Klemm
dbb8ce5eac Store hypertable RelOptInfo in CompressionInfo 2023-11-03 14:57:32 +01:00
Alexander Kuzmenkov
61f2606bfb Evaluate stable expressions in vectorized filters at run time
This allows vectorizing common filters such as ts > now() - interval '1 day'.
2023-11-03 12:10:50 +01:00
Jan Nidzwetzki
7f4f23be8f Add Coccinelle rules - bitmap set operations
Some bitmap set operations recycle one of the input parameters or return
a reference to a new bitmap set. The added set of rules checks that the
returned reference is not discarded.
2023-11-03 11:05:27 +01:00
Sven Klemm
7f25cd9c9f Fix missing result assignment for bms_del_member
This was causing memory corruption in the PG16 tests but affects
previous PG versions as well.
2023-11-03 10:44:06 +01:00
Nikhil Sontakke
844807a374 Change show_chunks/drop_chunks using creation time
- Updated show_chunks, drop_chunks APIs to get the affected
chunks using chunk creation time metadata based on the
"date/time/interval" like boundary specified for the INTEGER
columns.

- We honor "integer_now" function if it's specified so as to keep
backwards compatibility with the existing behavior

Co-authored-by: Dipesh Pandit <dipesh@timescale.com>
2023-11-02 18:37:09 +05:30
Sven Klemm
22b556d069 Fix exception detail passing in compression_policy_execute
In 2 instances of the exception handling _message and _detail were
not properly set in compression_policy_execute leading to empty
message and detail being reported.
2023-11-01 19:45:29 +01:00
Jan Nidzwetzki
48f4296926 Support for segment_by filters on vector aggs
This patch adds support for vectorized aggregation queries with filters
on the segment_by value of compressed data.
2023-11-01 14:09:00 +01:00
Alexander Kuzmenkov
bc5e39d67a Vectorize the comparison operators for Date type
This uses our normal arithmetic vectorized operators.
2023-11-01 13:26:37 +01:00
Jan Nidzwetzki
a094f175eb Vectorized aggregation execution for sum()
This commit introduces a vectorized version of the sum() aggregate
function on compressed data. This optimization is enabled if (1) the
data is compressed, (2) no filters or grouping is applied, (3) the data
type is a 32-bit sum, and (4) the aggregation can be pushed down to
the chunk level.
2023-11-01 10:04:44 +01:00
Jan Nidzwetzki
4048900540 Adjust dist_util test output
In 8767de658b8279fd3352d0bf2acce4564784079e the freezing of tuples was
introduced, which changes the relation size in PG >= 14 by one page
since a visibility map is created. This PR adjusts the output of the
dist_util test.
2023-10-31 20:44:45 +01:00
Mats Kindahl
98623ea1d9 Check if worker registration succeeded
If `RegisterDynamicbackgroundworker` fails the returned handle will be
null, which will cause `WaitForBackgroundWorkerStartup` to fail with a
crash. This can typically happen if there is not enough slots in
`BackgroundWorkerData`. In that case, just return and do not call
`WaitForBackgroundWorkerStartup`.
2.13.0-dev1
2023-10-30 08:27:35 +01:00
Sven Klemm
0aefc072c0 Pass RowDecompressor by reference in build_scankeys
Change the code to pass RowDecompressor by reference instead of
value. Found by coverity.
2023-10-29 17:10:23 +01:00
Sven Klemm
c9ca6f5f5a Add OpenSSF badge to readme 2023-10-29 09:59:17 +01:00
Fabrízio de Royes Mello
4678f6605f PG16: Fix ordered append output test
In #6168 we added the ordered append output test for PG16 but
unfortunately it was wrong and didn't take in account the planner
output differences introduced.

Fixed it by changing properly the output changes for PG16.
2023-10-28 12:45:52 -03:00
Jan Nidzwetzki
3c3bdb3dad Remove invalid memcpy
f3b3e556932e016a321796bc0c517199939aabf6 introduces sorted paths for
compressed chunks. However, it uses an unneeded and invalid memcpy call,
which can cause crashes. This PR removes the memcpy call.
2023-10-28 17:03:02 +02:00
Fabrízio de Royes Mello
29fe401e54 PG16: Refactored ownercheck functions
In our code we have an Event Trigger on `ddl_command_end` to process
some DDL commands, and specially the `ALTER TABLE` we execute some code
to properly deal with hypertables, chunks and compressed chunks.

The problem is when we start to process our code at `ddl_command_end`
event we get the related `relid` by calling the `AlterTableLookupRelation`
that perform the proper acl checking. But this is a bit wrong because in
case of a `ALTER TABLE ... OWNER TO ...` at this point (aka
`ddl_command_end`) the ownership of the relation was already processed
and with this PG16 refactoring it now is visible for the
`object_ownercheck` leading to a misbehavior.

Due to our intention is just the get the `relid` related to the
AlterTableCmd just fixed it by replacing the `AlterTableLookupRelation`
for the `RangeVarGetRelid` because at this point all the proper aclcheck
was already done.

postgres/postgres@afbfc029
2023-10-27 14:17:28 -03:00