3853 Commits

Author SHA1 Message Date
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
Mats Kindahl
0cbd7407a6 Get PortalContext when starting job
When executing functions, SPI assumes that `TopTransactionContext` is
used for atomic execution contexts and `PortalContext` is used for
non-atomic contexts. Since jobs need to be able to commit and start
transactions, they are executing in a non-atomic context hence
`PortalContext` will be used, but `PortalContext` is not set when
starting the job. This is not a problem for PL/PgSQL executor, but for
other executors (such as PL/Python) it would be.

This commit fixes the issue by setting the `PortalContext` variable to
the portal context created for the portal and restores it (to NULL)
after execution.

Fixes #5326
2023-02-20 10:54:05 +01:00
Jan Nidzwetzki
83fc20f195 Change bgw_main field length to BGW_MAXLEN
The content of bgw_main is copied into BackgroundWorker.
bgw_function_name, which has a length of BGW_MAXLEN. This patch ensures
that the size of these fields has the same length.
2023-02-20 08:51:50 +01:00
Maheedhar PV
91b4a66eb9
Release 2.10.0 (#5324)
This release contains new features and bug fixes since the 2.9.3
release.

This release is high priority for upgrade. We strongly recommend that
you upgrade as soon as possible.

**Features**
* #5241 Allow RETURNING clause when inserting into compressed chunks
* #5245 Manage life-cycle of connections via memory contexts
* #5246 Make connection establishment interruptible
* #5253 Make data node command execution interruptible
* #5243 Enable real-time aggregation for continuous aggregates with
joins
* #5262 Extend enabling compression on a continuous aggregrate with
'compress_segmentby' and 'compress_orderby' parameters

**Bugfixes**
* #4926 Fix corruption when inserting into compressed chunks
* #5218 Add role-level security to job error log
* #5214 Fix use of prepared statement in async module
* #5290 Compression can't be enabled on continuous aggregates when
segmentby/orderby columns need quotation
* #5239 Fix next_start calculation for fixed schedules
2023-02-20 11:06:05 +05:30
Sven Klemm
ce85546b56 Fix ABI test
Pin the OpenSSL version we compile against to OpenSSL 1.1 in
backwards ABI test because OpenSLL 3 is not available across
all supported versions.
2023-02-19 14:35:58 +01:00
Fabrízio de Royes Mello
c7f46393e7 Change usage of term nested to hierarchical
To don't make developers confused the right name for Continuous
Aggregates on top of another Continuous Aggregates is `Hierarchical
Continuous Aggregates`, so changed the usage of term `nested` for
`hierarchical`.
2023-02-18 11:04:51 -03:00
Nikhil Sontakke
d50de8a72d Fix uninitialized bucket_info.htpartcolno warning
Found by coverity.
2023-02-17 16:42:20 +01:00
Mats Kindahl
38b71d0e70 Use NameData and namestrcpy for names
Using `strlcpy` to copy variables holding PostgreSQL names can cause
issues since names are fixed-size types of length 64. This means that
any data that follows the initial null-terminated string will also be
part of the data.

Instead of using `const char*` for PostgreSQL names, use `NameData`
type for PostgreSQL names and use `namestrcpy` to copy them rather
than `strlcpy`.
2023-02-17 10:43:46 +01:00
Jacob Champion
0963609271 Align GUC initializations with boot values
As of upstream a73952b795 (16devel), custom GUCs have their initialized
values checked against the configured boot value. If they differ, an
assertion is tripped. So I've gone through the list and aligned the two
sides, adding defaults where they did not previously exist for
consistency.

To allow for dynamic boot values, the new assertion logic allows the
initialized value to be zero, in which case any boot value will be
accepted. ts_guc_max_open_chunks_per_insert relies on the value of
work_mem, so I've removed its (explicit) initializer entirely.
2023-02-14 07:54:16 -08:00
Jacob Champion
917f7804a7 Remove obsolete usage of AssertArg()
Upstream HEAD (16devel) removed this in commit b1099eca8f. Assert() is
identical.
2023-02-14 07:54:16 -08:00
Jacob Champion
f21bf6faac Fix misuse of CStringGetDatum
OidFunctionCall1() returns a Datum, not const char *.
2023-02-14 07:54:16 -08:00
Jacob Champion
20e468f40c Fix use of TextDatumGetCString()
TextDatumGetCString() was made typesafe in upstream HEAD (16devel), so
now the compiler catches this. As Tom puts it in ac50f84866:

    "TextDatumGetCString(PG_GETARG_TEXT_P(x))" is formally wrong: a text*
    is not a Datum.  Although this coding will accidentally fail to fail on
    all known platforms, it risks leaking memory if a detoast step is needed,
    unlike "TextDatumGetCString(PG_GETARG_DATUM(x))" which is what's used
    elsewhere.
2023-02-14 07:54:16 -08: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
Konstantina Skovola
48d4f41d95 Run apt package tests against Ubuntu 22.10 (Kinetic Kudu) 2023-02-14 16:41:36 +02:00
Zoltan Haindrich
9d3866a50e Accept all compression options on caggs
Enable to properly handle 'compress_segmentby' and 'compress_orderby'
compression options on continous aggregates.

ALTER MATERIALIZED VIEW test_table_cagg SET (
  timescaledb.compress = true,
  timescaledb.compress_segmentby = 'device_id'
);

Fixes #5161
2023-02-13 22:21:18 +01:00
Alexander Kuzmenkov
d00c1f3721 Fix some errors in processing of code coverage data
We were using mismatched compiler and gcov, which led to either
segfaults or errors like "GCOV_TAG_COUNTER_ARCS mismatch". Add some
cmake code that tries to find the gcov that matches the compiler.

This should hopefully fix some of the mysterious missing coverage
problems that we've been experiencing for a while.
2023-02-13 18:38:09 +04:00
Sven Klemm
9ec11d8af6 Bump PG version used in CI to 12.14, 13.10, 14.7 and 15.2 2023-02-12 14:23:12 +01:00
Sven Klemm
ef25fb9ec7 Add dist_ref_table_join generated test files to .gitignore 2023-02-11 11:31:26 +01:00
Alexander Kuzmenkov
484a4ea3fc Fix our codecov repository yaml
Codecov keeps complaining that it's invalid.
2023-02-11 00:12:18 +04:00
Rafia Sabih
ece15d66a4 Enable real time aggregation for caggs with joins 2023-02-10 22:12:29 +05:30
Konstantina Skovola
348796f9d9 Fix next_start calculation for fixed schedules
This patch fixes several issues with next_start calculation.

- Previously, the offset was added twice in some cases.
This is fixed by this patch.

- Additionally, schedule intervals with month components
were not handled correctly.
Internally, time_bucket with origin is used to calculate
the next start. However, in the case of month intervals, the
timestamp calculated for a bucket is always aligned on the first
day of the month, regardless of origin.
Therefore, previously the result was aligned with origin by adding
the difference between origin and its respective time bucket.
This difference was computed as a fixed length interval in terms
of days and time. That computation led to incorrect computation of
next start occasionally, for example when a job should be executed on
the last day of a month.
That is fixed by adding an appropriate interval of months to
initial_start and letting Postgres handle this computation properly.

Fixes #5216
2023-02-09 17:57:17 +02:00
Sven Klemm
756ef68d0a Fix compression_hypertable ordering reliance
The hypertable_compression test had on implicit reliance on the
ordering of tuples when querying the materialized results.
This patch makes the ordering explicit in this test.
2023-02-09 15:23:07 +01:00
Alexander Kuzmenkov
caf79e0f5e When backporting, fetch the main branch with large depth
Apparently in some cases we're getting a shallow repo in the Github
Actions.
2023-02-08 18:48:53 +04:00
Alexander Kuzmenkov
063a9dae29 Improve cost model for data node scans
1) Simplify the path generation for the parameterized data node scans.
1) Adjust the data node scan cost if it's an index scan, instead of always
   treating it as a sequential scan.
1) Hard-code the grouping estimation for distributed hypertable, instead
   of using the totally bogus per-column ndistinct value.
1) Add the GUC to disable parameterized
data node scan.
1) Add more tests.
2023-02-08 16:12:01 +04:00
Zoltan Haindrich
cad2440b58 Compression can't be enabled on caggs
The continuous aggregate creation failed in case segmentby/orderby
columns needed quotation.
2023-02-07 21:01:56 +01:00
Lakshmi Narayanan Sreethar
1eb8aa3f14 Post-release fixes for 2.9.3
Bumping the previous version and adding tests for 2.9.3.
2023-02-07 15:53:42 +05:30
Rafia Sabih
4cb76bc053 Cosmetic changes to create.c 2023-02-06 22:39:57 +05:30
Sven Klemm
8132908c97 Refactor chunk decompression functions
Restructure the code inside decompress_chunk slightly to make core
loop reusable by other functions.
2023-02-06 14:52:06 +01:00
Lakshmi Narayanan Sreethar
fb3ad7d6c6 Release 2.9.3
This release contains bug fixes since the 2.9.2 release.
This release is high priority for upgrade. We strongly recommend that you
upgrade as soon as possible.

**Bugfixes**
* #4804 Skip bucketing when start or end of refresh job is null
* #5108 Fix column ordering in compressed table index not following the order of a multi-column segment by definition
* #5187 Don't enable clang-tidy by default
* #5255 Fix year not being considered as a multiple of day/month in hierarchical continuous aggregates
* #5259 Lock down search_path in SPI calls
2023-02-03 20:04:18 +05:30
Erik Nordström
206056ca12 Fix dist_hypertable test
A previous change accidentally broke the dist_hypertable test so that
it prematurely exited. This change restores the test so that it
executes properly.
2023-02-03 13:35:36 +01:00
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
Alexander Kuzmenkov
c4d8f35307 Improve automated backports
A follow-up for the review comments in the previous PR.

1. Create one backport PR per one source PR, even with multiple commits.
1. Add a comment to the source PR if we fail to backport it for some
   reason.
2023-02-02 16:13:33 +04:00
Konstantina Skovola
6bc8980216 Fix year not multiple of day/month in nested CAgg
Previously all intervals were converted to seconds using "epoch"
with date_part. However, this treats a year as 365.25 days to
account for leap years, leading to the unexpected situation that
a year is not a multiple of a day or a month.

Fixed by treating month-only intervals as multiples of 30 days.

Fixes #5231
2023-02-02 12:14:37 +02:00
Alexander Kuzmenkov
9133319081 Fix pylint again
Apparently a new version is out and it complains about Exception being
too general.
2023-02-02 08:57:42 +04:00
Alexander Kuzmenkov
739fd00bb9 Add a workflow for automated backporting
1. Find the latest release branch
1. For each commit in main and not in release branch (compared by
   title), find the corresponding PR.
1. If the PR fixes an issue labeled "bug", and neither the PR nor the
   issue are labeled "no-backport", cherry-pick the commits from the PR
onto the release branch, and create a PR with these changes.
2023-02-01 16:25:02 +04:00
Sven Klemm
2a47462fbc Remove SECURITY DEFINER from get_telemetry_report
We should not broadly make functions security definer as that increases
the attack surface for our extension. Especially for our telemetry we
should strive to only run it with the minimum required privileges.
2023-02-01 13:10:23 +01:00
Alexander Kuzmenkov
44cd71a602 Fix the python code style check
For an unknown reason, pip started to install an older version of
prospector which is incompatible with the current pylint. Require the
new prospector version explicitly.
2023-02-01 15:00:00 +04:00
Sven Klemm
d8f19e57a0 Bump version of setup-wsl github action
The currently used version pulls in Node.js 12 which is deprecated
on github.

https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2023-02-01 11:53:48 +01:00