3890 Commits

Author SHA1 Message Date
Mats Kindahl
67ff84e8f2 Add check for malloc failure in libpq calls
The functions `PQconndefaults` and `PQmakeEmptyPGresult` calls
`malloc` and can return NULL if it fails to allocate memory for the
defaults and the empty result. It is checked with an `Assert`, but this
will be removed in production builds.

Replace the `Assert` with an checks to generate an error in production
builds rather than trying to de-reference the pointer and cause a
crash.
2023-03-16 14:20:54 +01: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
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
Sven Klemm
03a799b874 Mention that new status values need handling in downgrade script
When adding new status values we must make sure to add special
handling for these values to the downgrade script as previous
versions will not know how to deal with those.
2023-03-14 23:59:10 +01:00
Dmitry Simonenko
f8022eb332 Add additional tests for compression with HA
Make sure inserts into compressed chunks work when a DN is down

Fix #5039
2023-03-13 17:43:48 +02:00
Sven Klemm
65562f02e8 Support unique constraints on compressed chunks
This patch allows unique constraints on compressed chunks. When
trying to INSERT into compressed chunks with unique constraints
any potentially conflicting compressed batches will be decompressed
to let postgres do constraint checking on the INSERT.
With this patch only INSERT ON CONFLICT DO NOTHING will be supported.
For decompression only segment by information is considered to
determine conflicting batches. This will be enhanced in a follow-up
patch to also include orderby metadata to require decompressing
less batches.
2023-03-13 12:04:38 +01:00
Sven Klemm
c02cb76b38 Don't reindex relation during decompress_chunk
Reindexing a relation requires AccessExclusiveLock which prevents
queries on that chunk. This patch changes decompress_chunk to update
the index during decompression instead of reindexing. This patch
does not change the required locks as there are locking adjustments
needed in other places to make it safe to weaken that lock.
2023-03-13 10:58:26 +01:00
Sven Klemm
20ea406616 Add utility function to map attribute numbers
This patch adds a function ts_map_attno that can be used to map
the attribute number from one relation to another by column name.
2023-03-13 10:57:17 +01:00
Jan Nidzwetzki
356a20777c Handle user-defined FDW options properly
This patch changes the way user-defined FDW options (e.g., startup
costs, per-tuple costs) are handled. So far, these values were retrieved
in apply_fdw_and_server_options() but reset to default values afterward.
2023-03-13 10:39:52 +01:00
Maheedhar PV
5e0391392a Out of on_proc_exit slots on guc license change
Problem:

When the guc timescaledb.license = 'timescale' is set in the conf file
and a SIGHUP is sent to postgress process and a reload of the tsl
module is triggered.

This reload happens in 2 phases 1. tsl_module_load is called which
will load the module only if not already loaded and 2.The
ts_module_init is called for every ts_license_guc_assign_hook
irrespective of if it is new load.This ts_module_init initialization
function also registers a on_proc_exit function to be called on exit.

The list of on_proc_exit methods are maintained in a fixed array
on_proc_exit_list of size MAX_ON_EXITS (20) which gets filled up on
repeated SIGHUPs and hence an error.

Fix:

The fix is to make the ts_module_init() register the on_proc_exit
callback, only in case the module is reloaded and not in every init
call.

Closes #5233
2023-03-13 06:24:01 +05:30
Alexander Kuzmenkov
e92d5ba748 Add more tests for compression
Unit tests for different data sequences, and SQL test for float4.
2023-03-10 20:34:17 +04:00
Jan Nidzwetzki
f5db023152 Track file trailer only in debug builds
The commit 96574a7 changes the handling of the file_trailer_received
flag. It is now only used in asserts and not in any other kind of logic.
This patch encapsulates the file_trailer_received in a
USE_ASSERT_CHECKING macro.
2023-03-10 10:44:53 +01:00
Sven Klemm
217ba014a7 Use version checks to decide about RelationGetSmgr backporting
Use explicit version checks to decide whether to define backported
RelationGetSmgr function or rely on the function being available.
This simplifies the cmake code a bit and make the backporting similar
to how we handle this for other functions.
2023-03-09 16:55:50 +01:00
Jan Nidzwetzki
7b8177aa74 Fix file trailer handling in the COPY fetcher
The copy fetcher fetches tuples in batches. When the last element in the
batch is the file trailer, the trailer was not handled correctly. The
existing logic did not perform a PQgetCopyData in that case. Therefore
the state of the fetcher was not set to EOF and the copy operation was
not correctly finished at this point.

Fixes: #5323
2023-03-09 14:29:06 +01:00
Sven Klemm
a854b2760f Simplify ts_indexing_relation_has_primary_or_unique_index
Rely on postgres functionality for index column tracking instead
of rolling our own.
2023-03-08 22:43:59 +01:00
Bharathy
f54dd7b05d Fix SEGMENTBY columns predicates to be pushed down
WHERE clause with SEGMENTBY column of type text/bytea
non-equality operators are not pushed down to Seq Scan
node of compressed chunk. This patch fixes this issue.

Fixes #5286
2023-03-08 19:17:43 +05:30
Erik Nordström
c76a0cff68 Add parallel support for partialize_agg()
Make `partialize_agg()` support parallel query execution. To make this
work, the finalize node need combine the individual partials from each
parallel worker, but the final step that turns the resulting partial
into the finished aggregate should not happen. Thus, in the case of
distributed hypertables, each data node can run a parallel query to
compute a partial, and the access node can later combine and finalize
these partials into the final aggregate. Esssentially, there will be
one combine step (minus final) on each data node, and then another one
plus final on the access node.

To implement this, the finalize aggregate plan is simply modified to
elide the final step, and to reserialize the partial. It is only
possible to do this at the plan stage; if done at the path stage, the
PostgreSQL planner will hit assertions that assume that the node has
certain values (e.g., it doesn't expect combine Paths to skip the
final step).
2023-03-08 14:14:25 +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
Sven Klemm
00321dba41 2.10.1 Post-release adjustments
Add 2.10.1 to update test scripts and adjust the downgrade versioning.
2023-03-07 13:44:54 +01:00
Konstantina Skovola
5a3cacd06f Fix sub-second intervals in hierarchical caggs
Previously we used date_part("epoch", interval) and integer division
internally to determine whether the top cagg's interval is a
multiple of its parent's.
This led to precision loss and wrong results
in the case of intervals with sub-second components.

Fixed by using the `ts_interval_value_to_internal` function to convert
intervals to appropriate integer representation for division.

Fixes #5277
2023-03-07 13:25:49 +02:00
Fabrízio de Royes Mello
00b566dfe4 Remove unused functions
We don't use `ts_catalog_delete[_only]` functions anywhere and instead
we rely on `ts_catalog_delete_tid[_only]` functions so removing it from
our code base.
2023-03-07 04:02:25 -03:00
Sven Klemm
d386aa1def Release 2.10.1
This release contains bug fixes since the 2.10.0 release.
We recommend that you upgrade at the next available opportunity.

**Bugfixes**
* #5159 Support Continuous Aggregates names in hypertable_(detailed_)size
* #5226 Fix concurrent locking with chunk_data_node table
* #5317 Fix some incorrect memory handling
* #5336 Use NameData and namestrcpy for names
* #5343 Set PortalContext when starting job
* #5360 Fix uninitialized bucket_info variable
* #5362 Make copy fetcher more async
* #5364 Fix num_chunks inconsistency in hypertables view
* #5367 Fix column name handling in old-style continuous aggregates
* #5378 Fix multinode DML HA performance regression
* #5384 Fix Hierarchical Continuous Aggregates chunk_interval_size

**Thanks**
* @justinozavala for reporting an issue with PL/Python procedures in the background worker
* @Medvecrab for discovering an issue with copying NameData when forming heap tuples.
* @pushpeepkmonroe for discovering an issue in upgrading old-style
  continuous aggregates with renamed columns
* @pushpeepkmonroe for discovering an issue in upgrading old-style continuous aggregates with renamed columns
2023-03-07 01:23:38 +01:00
Sven Klemm
5cd2c03879 Simplify windows-build-and-test-ignored.yaml
Remove code not needed for the skip workflow of the windows test.
2023-03-06 20:02:20 +01:00
Sven Klemm
8a2f1f916a Fix windows package test
Chocolatey has all the postgres versions we need available so we
can reenable previously disabled tests. But the recent packages
seem to have different versioning schema without a suffix.
2023-03-06 20:02:20 +01:00
Dmitry Simonenko
830c37b5b0 Fix concurrent locking with chunk_data_node table
Concurrent insert into dist hypertable after a data node marked as
unavailable would produce 'tuple concurrently deleted` error.

The problem occurs because of missing tuple level locking during
scan and concurrent delete from chunk_data_node table afterwards,
which should be treated as `SELECT … FOR UPDATE` case instead.

Based on the fix by @erimatnor.

Fix #5153
2023-03-06 18:40:59 +02:00
Ildar Musin
4c0075010d Add hooks for hypertable drops
To properly clean up the OSM catalog we need a way to reliably track
hypertable deletion (including internal hypertables for CAGGS).
2023-03-06 15:10:49 +01:00
Sven Klemm
474b09bdfc Use pgspot 0.5.0 in CI 2023-03-03 19:00:38 +01:00
Fabrízio de Royes Mello
32046832d3 Fix Hierarchical CAgg chunk_interval_size
When a Continuous Aggregate is created the `chunk_interval_size` is
defined my the `chunk_interval_size` of the original hypertable
multiplied by a fixed factor of 10.

The problem is currently when we create a Hierarchical Continuous
Aggregate the same factor is applied and it lead to an exponential
`chunk_interval_size`.

Fixed it by just copying the `chunk_interval_size` from the base
Continuous Aggregate for an Hierachical Continuous Aggreagate.

Fixes #5382
2023-03-03 12:31:24 -03:00
Nikhil Sontakke
1423b55d18 Fix perf regression due to DML HA
We added checks via #4846 to handle DML HA when replication factor is
greater than 1 and a datanode is down. Since each insert can go to a
different chunk with a different set of datanodes, we added checks
on every insert to check if DNs are unavailable. This increased CPU
consumption on the AN leading to a performance regression for RF > 1
code paths.

This patch fixes this regression. We now track if any DN is marked as
unavailable at the start of the transaction and use that information to
reduce unnecessary checks for each inserted row.
2023-03-03 18:34:05 +05:30
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
Sven Klemm
e2e7ae3045 Don't run sanitizer test on individual PRs
Sanitizer tests take a long time to run so we don't want to run them on
individual PRs but instead run them nightly and on commits to master.
2023-03-03 13:31:25 +01:00
Sven Klemm
9574dd8e74 Adjust ARM64 package test
We only package timescaledb for ubuntu kinetic on PG14 because
there are no prebuilt postgres packages available for the other
postgres versions.
2023-03-03 12:56:54 +01: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
386d31bc6e Make copy fetcher more async
Make the copy fetcher more asynchronous by separating the sending of
the request for data from the receiving of the response. By doing
that, the async append node can send the request to each data node
before it starts reading the first response. This can massively
improve the performance because the response isn't returned until the
remote node has finished executing the query and is ready to return
the first tuple.
2023-03-02 15:07:23 +01:00
Sotiris Stamokostas
750e69ede1 Renamed size_utils.sql
Renamed:
tsl/test/sql/size_utils.sql
tsl/test/expected/size_utils.out
To:
tsl/test/sql/size_utils_tsl.sql
tsl/test/expected/size_utils_tsl.out
because conflicting with test/sql/size_utils.sql
2023-03-02 13:20:08 +02:00
Jan Nidzwetzki
7887576afa Handle MERGE command in reference join pushdown
At the moment, the MERGE command is not supported on distributed
hypertables. This patch ensures that the join pushdown code ignores the
invocation by the MERGE command.
2023-02-28 15:49:19 +01:00
shhnwz
e6f6eb3ab8 Fix for inconsistent num_chunks
Different num_chunks values reported by
timescaledb_information.hypertables and
timescaledb_information.chunks.
View definition of hypertables was
not filtering dropped and osm_chunks.

Fixes #5338
2023-02-28 16:32:03 +05:30
gayyappan
2f7e0433a9 Create index fails if hypertable has foreign table chunk
We cannot create indexes on foreign tables. This PR modifies
process_index_chunk to skip OSM chunks
2023-02-27 12:56:52 -05:00
Bharathy
56ce7907d9 Backport MERGE command specific postgresql code
This patch backports following:

1. Refactor ExecInsert/Delete/Update
   Backported commit 25e777cf8e547d7423d2e1e9da71f98b9414d59e
2. Backport all MERGE related interfaces and its implementations.
   Backported commit 7103ebb7aae8ab8076b7e85f335ceb8fe799097c
2023-02-27 09:58:31 +05:30
Fabrízio de Royes Mello
152ef02d74 Fix uninitialized bucket_info variable
The `bucket_info` variable is initialized by `caggtimebucketinfo_init`
function called inside the following branch:

`if (rte->relkind == RELKIND_RELATION || rte->relkind == RELKIND_VIEW)`

If for some reason we don't enter in this branch then the `bucket_info`
will not be initialized leading to an uninitialized variable when
returning `bucket_info` at the end of the `cagg_validate_query`
function.

Fixed it by initializing with zeros the `bucket_info` variable when
declaring it.

Found by coverity scan.
2023-02-24 15:54:53 -03:00
noctarius aka Christoph Engelbert
0118e6b952 Support CAGG names in hypertable_(detailed_)size
This small patch adds support for continuous aggregates to the
`hypertable_detailed_size` (and with that `hypertable_size`).
It adds an additional check to see if a continuous aggregate exists
if a hypertable with the given regclass name isn't found.
2023-02-24 10:48:31 -03:00
Maheedhar PV
c8c50dad7e Post-release fixes for 2.10.0
Bumping the previous version and adding tests for 2.10.0
2023-02-24 12:03:36 +01:00
Jan Nidzwetzki
e0be9eaa28 Allow pushdown of reference table joins
This patch adds the functionality that is needed to perform distributed,
parallel joins on reference tables on access nodes. This code allows the
pushdown of a join if:

 * (1) The setting "ts_guc_enable_per_data_node_queries" is enabled
 * (2) The outer relation is a distributed hypertable
 * (3) The inner relation is marked as a reference table
 * (4) The join is a left join or an inner join
2023-02-23 14:32:12 +01:00
Dmitry Simonenko
f12a361ef7 Add timeout argument to the ping_data_node()
This PR introduces a timeout argument and a new logic to the
timescale_internal.ping_data_node() function which allows
to handle io timeouts for nodes being unresponsive.

Fix #5312
2023-02-21 19:52:03 +02:00
Sven Klemm
0976634399 Set name for COPY insert buffer hash table
Having the hash table named makes debugging easier as the name
is used for the MemoryContext used by the hash table.
2023-02-20 18:31:48 +01:00
Jan Nidzwetzki
330bb8f4af Added coccinelle rule to find strlcpy on NameData
NameData is a fixed-size type of 64 bytes. Using strlcpy to copy data
into a NameData struct can cause problems because any data that follows
the initial null-terminated string will also be part of the data.
2023-02-20 15:23:57 +01:00
Mats Kindahl
8a51a76d00 Fix changelog message for NameData issue 2023-02-20 14:26:56 +01:00
Oleg Tselebrovskiy
0746517c77 Fix some incorrect memory handling
While running TimescaleDB under valgrind I've found
two cases of incorrect memory handling.

Case 1: When creating timescaledb extension, during the insertion of
metadata there is some junk in memory that is not zeroed
before writing there.
Changes in metadata.c fix this.

Case 2: When executing GRANT smth ON ALL TABLES IN SCHEMA some_schema
and deconstructing this statement into granting to individual tables,
process of copying names of those tables is wrong.
Currently, you aren't copying the data itself, but an address to data
on a page in some buffer. There's a problem - when the page in this
buffer changes, copied address would lead to wrong data.
Changes in process_utility.c fix this by allocating memory and then
copying needed relname there.

Fixes #5311
2023-02-20 14:26:56 +01:00
Jan Nidzwetzki
7e43c702ba Increase timeout for PostgreSQL in upgrade tests
The upgrade and downgrade tests are running PostgreSQL in Docker
containers. The function 'wait_for_pg' is used to determine if
PostgreSQL is ready to accept connections. In contrast to the upgrade
tests, the downgrade tests use more relaxed timeout values. The upgrade
tests sometimes fail because PostgreSQL cannot accept connections within
the configured time range. This patch applies the more relaxed timeout
values also to the upgrade script.
2023-02-20 11:17:48 +01:00