19 Commits

Author SHA1 Message Date
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
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
Bharathy
3a9688cc97 Extra Result node on top of CustomScan on PG15
On PG15 CustomScan by default is not projection capable, thus wraps this
node in Result node. THis change in PG15 causes tests result files which
have EXPLAIN output to fail. This patch fixes the plan outputs.

Fixes #4833
2022-11-07 21:20:08 +05:30
Sven Klemm
110d77a2fe Combine test files
Merge test files that after the removal of PG11 support need
to be no longer version specific.
2021-06-01 20:21:06 +02:00
Joshua Lockerman
949b88ef2e Initial support for PostgreSQL 12
This change includes a major refactoring to support PostgreSQL
12. Note that many tests aren't passing at this point. Changes
include, but are not limited to:

- Handle changes related to table access methods
- New way to expand hypertables since expansion has changed in
  PostgreSQL 12 (more on this below).
- Handle changes related to table expansion for UPDATE/DELETE
- Fixes for various TimescaleDB optimizations that were affected by
  planner changes in PostgreSQL (gapfill, first/last, etc.)

Before PostgreSQL 12, planning was organized something like as
follows:

 1. construct add `RelOptInfo` for base and appendrels
 2. add restrict info, joins, etc.
 3. perform the actual planning with `make_one_rel`

For our optimizations we would expand hypertables in the middle of
step 1; since nothing in the query planner before `make_one_rel` cared
about the inheritance children, we didn’t have to be too precises
about where we were doing it.

However, with PG12, and the optimizations around declarative
partitioning, PostgreSQL now does care about when the children are
expanded, since it wants as much information as possible to perform
partition-pruning. Now planning is organized like:

 1. construct add RelOptInfo for base rels only
 2. add restrict info, joins, etc.
 3. expand appendrels, removing irrelevant declarative partitions
 4. perform the actual planning with make_one_rel

Step 3 always expands appendrels, so when we also expand them during
step 1, the hypertable gets expanded twice, and things in the planner
break.

The changes to support PostgreSQL 12 attempts to solve this problem by
keeping the hypertable root marked as a non-inheritance table until
`make_one_rel` is called, and only then revealing to PostgreSQL that
it does in fact have inheritance children. While this strategy entails
the least code change on our end, the fact that the first hook we can
use to re-enable inheritance is `set_rel_pathlist_hook` it does entail
a number of annoyances:

 1. this hook is called after the sizes of tables are calculated, so we
    must recalculate the sizes of all hypertables, as they will not
    have taken the chunk sizes into account
 2. the table upon which the hook is called will have its paths planned
    under the assumption it has no inheritance children, so if it's a
    hypertable we have to replan it's paths

Unfortunately, the code for doing these is static, so we need to copy
them into our own codebase, instead of just using PostgreSQL's.

In PostgreSQL 12, UPDATE/DELETE on inheritance relations have also
changed and are now planned in two stages:

- In stage 1, the statement is planned as if it was a `SELECT` and all
  leaf tables are discovered.
- In stage 2, the original query is planned against each leaf table,
  discovered in stage 1, directly, not part of an Append.

Unfortunately, this means we cannot look in the appendrelinfo during
UPDATE/DELETE planning, in particular to determine if a table is a
chunk, as the appendrelinfo is not at the point we wish to do so
initialized. This has consequences for how we identify operations on
chunks (sometimes for blocking and something for enabling
functionality).
2020-04-14 23:12:15 +02:00
Sven Klemm
3e03ca0b02 Include parallel leader in plan execution
We have to let the leader participate in parallel plan execution
if for some reason no parallel workers were started.

This commit also changes the parallel EXPLAINs to not run with
ANALYZE because the output is not stable as it depends on
worker assignment.
2020-04-08 01:45:27 +02:00
Matvey Arye
825645b2f5 Fix bug with histogram function in parallel
Histogram's combine function threw a segfault if both state1
and state2 were NULL. I could only reproduce this case in
PG 10. Add a tests that hits this with PG 10.4

Fixes #1490
2019-10-30 12:13:41 -04:00
Sven Klemm
b0c75d3106 Speed up parallel test
Since we can now set reloptions on chunks we don't have to rely on
data volume to trigger parallel plans.
2019-10-10 20:18:23 +02:00
Sven Klemm
36bff37daf Add support for non-partial paths to parallel ChunkAppend
PostgreSQL will produce plans where a parallel append has children
that are not partial paths. This patch adds support for those plans
to ChunkAppend.
2019-10-09 18:41:35 +02:00
Sven Klemm
4cd645eb72 Improve ChunkAppend parallel worker assignment
The initial implementation of assigning multiple workers per subplan
would always assign a fixed amount of workers per child. This
patch changes the logic to assign each child one worker and then
moving to the next subplan, iterating until all subplans are finished.
This will lead to a much better distribution of workers especially
when the children are not well balanced.
2019-10-07 13:46:16 +02:00
Sven Klemm
441dc241da Make ChunkAppend parallel aware
This patch makes ChunkAppend parallel aware allowing ChunkAppend
to coordinate parallel workers.

Since setting up the shared memory for the LWLock has to happen
in the library loaded with shared_preload_libraries this change
requires a server restart.
2019-09-18 17:39:38 +02:00
Sven Klemm
74908c3632 Change parallel aggregation to run without ANALYZE
The number of loops per subplan is not stable
in the parallel aggregation leading to that test
sometimes failing. This patch changes this query
to run EXPLAIN without ANALYZE.
2019-04-03 21:00:34 +02:00
Joshua Lockerman
e051842fee Add interval to internal conversions, and tests for both this and time conversions
We find ourselves needing to store intervals (specifically time_bucket widths) in
upcoming PRs, so this commit adds that functionality, along with tests that we
perform the conversion in a sensible, round-tripa-able, manner.

This commit fixes a longstanding bug in plan_hashagg where negative time values
would prevent us from using a hashagg. The old logic for to_internal had a flag
that caused the function to return -1 instead of throwing an error, if it could
not perform the conversion. This logic was incorrect, as -1 is a valid time val
The new logic throws the error uncoditionally, and forces the user to CATCH it
if they wish to handle that case. Switching plan_hashagg to using the new logic
fixed the bug.

The commit adds a single SQL file, c_unit_tests.sql, to be the driver for all such
pure-C unit tests. Since the tests run quickly, and there is very little work to
be done at the SQL level, it does not seem like each group of such tests requires
their own SQL file.

This commit also upates the test/sql/.gitignore, as some generated files were
missing.
2019-03-29 14:47:41 -04:00
Sven Klemm
49b7a5f721 Change first/last parallel test to not run ANALYZE
Don't run ANALYZE on first/last parallel tests because the analyze
output is not stable.
2019-03-29 18:58:19 +01:00
Sven Klemm
fce3d08638 Make constraint aware append parallel safe
Constraint aware append used some planner data structures in the
executor which cannot be serialized so they will not be available
in parallel workers, this patch refactors this and marks the
constraint aware append node as parallel safe when the subpath is
parallel safe. The additional function executions in the test output
are because the constify is run once per chunk now, previously it run
only once and the result was copied to the restrictinfo of every chunk
and then adjusted for the chunk, but since the adjustment for the chunk
has to happen in the planner because it needs access to appendrelinfo
we now create per chunk restrictinfo in the planner and constify each of
these in the executor.

On PostgreSQL < 12 now() is not parallel safe and using now() in a
query will prevent parallelism. As a workaround transaction_timestamp()
or CURRENT_TIMESTAMP can be used which will not prevent parallelism.
2019-02-22 15:31:56 -05:00
Sven Klemm
fabaa6ea51 Use hypertable for parallel tests
Generated data has been offset by 1 to align with chunk boundaries.
2019-01-25 15:59:03 +01:00
Sven Klemm
f89fd07c5b Remove year from SQL file license text
This changes the license text for SQL files to be identical
with the license text for C files.
2019-01-13 23:30:22 +01:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Erik Nordström
500563ffe5 Add support for PostgreSQL 10
The extension now works with PostgreSQL 10, while
retaining compatibility with version 9.6.

PostgreSQL 10 has numerous internal changes to functions and
APIs, which necessitates various glue code and compatibility
wrappers to seamlessly retain backwards compatiblity with older
versions.

Test output might also differ between versions. In particular,
the psql client generates version-specific output with `\d` and
EXPLAINs might differ due to new query optimizations. The test
suite has been modified as follows to handle these issues. First,
tests now use version-independent functions to query system
catalogs instead of using `\d`. Second, changes have been made to
the test suite to be able to verify some test outputs against
version-dependent reference files.
2017-11-10 09:44:20 +01:00