14 Commits

Author SHA1 Message Date
Alexander Kuzmenkov
85f5efdc8f Fix -Wsign-compare with PG 15
It changed the type of Var.varno from Index to int. I'm starting to
wonder if it was a good idea to enable this warning, but maybe we can
give it the last try.
2022-10-28 17:10:13 +04:00
Alexander Kuzmenkov
c73c5a74b9 Avoid extra projection when scanning a compressed chunk
We don't have to project the result of the underlying scan of
DecompressChunk, because the latter can selectively decompress the
resulting columns anyway. The projection slows down the things
especially when we use JIT, when the projection has to be compiled for
each chunk.

To avoid this unnecessary work, use the physical targetlist for
compressed scan if we can. This commit rewrites the function that
determines what we have to decompress, and makes it use the targetlist
generated by the planner, instead of building it from scratch. Then we
can give it the physical targetlist when possible.
2022-05-11 13:12:01 +05:30
Alexander Kuzmenkov
97078dde05 Enable DecompressChunk node to skip some input columns
No functional change.

This refactoring adds explicit output attnos to the metadata of column
decompression, enabling DecompressChunk node to skip some input columns
of the compressed scan. This is ultimately needed to support physical
targetlists in compressed scan.
2022-04-27 18:06:41 +05:30
Alexander Kuzmenkov
eeb9d13317 Avoid compiling extra projection when constifying the tableoid column
If we didn't constify anything, no need to recompile the projection. It
can be costly if we're using JIT.
2022-04-21 16:45:30 +05:30
gayyappan
9f64df8567 Add ts_catalog subdirectory
Move files that are related to timescaledb catalog
access to this subdirectory
2022-01-24 16:58:09 -05:00
Sven Klemm
93ffec7c10 Allow ALTER TABLE ADD COLUMN with DEFAULT on compressed hypertable
When adding a new column with a default postgres doesnt materialize
the default expression but just stores it in catalog with a flag
signaling that it is missing from the physical row.
Any expressions used as default that do not require materialization
can be allowed on compressed hypertables as well.

The following statements will work on compressed hypertables with
this patch:
ALTER TABLE t ADD COLUMN c1 int DEFAULT 42;
ALTER TABLE t ADD COLUMN c2 text NOT NULL DEFAULT 'abc';
2021-11-03 11:10:54 +01:00
Mats Kindahl
f8bf3b9767 Always reset expr context in DecompressChunk
When decompressing very large compressed chunks as part of executing a
`DecompressChunk`, the expression memory context was not reset after
each qual evaluation if the qual did not match, meaning that if the
qual did not match often, memory allocations would start to accumulate.

This commit fixes this by resetting the expression memory context for
each tuple when executing a `DecompressChunk` node, even if the qual
did not match.

Fixes #3620
2021-10-27 16:39:40 +02:00
Sven Klemm
d0426ff234 Move all compatibility related files into compat directory 2021-08-28 05:17:22 +02:00
Sven Klemm
b1a9c3b7b7 Add support for PG13 List implementation
PG13 changes the List implementation from a linked list to an array
while most of the API functions did not change a few them have slightly
different signature in PG13, additionally the list_make5 functions
got removed.

https://github.com/postgres/postgres/commit/1cff1b95ab
2021-01-04 11:18:33 +01:00
Sven Klemm
3d1a7ca3ac Fix delete on tables involving hypertables with compression
The DML blocker to block INSERTs and UPDATEs on compressed hypertables
would trigger if the UPDATE or DELETE referenced any hypertable with
compressed chunks. This patch changes the logic to only block if the
target of the UPDATE or DELETE is a compressed chunk.
2020-07-20 13:22:49 +02:00
Sven Klemm
c90397fd6a Remove support for PG9.6 and PG10
This patch removes code support for PG9.6 and PG10. In addition to
removing PG96 and PG10 macros the following changes are done:

remove HAVE_INT64_TIMESTAMP since this is always true on PG10+
remove PG_VERSION_SUPPORTS_MULTINODE
2020-06-02 23:48:35 +02:00
Ruslan Fomkin
1ddc62eb5f Refactor header inclusion
Correcting conditions in #ifdefs, adding missing includes, removing
and rearranging existing includes, replacing PG12 with PG12_GE for
forward compatibility. Fixed number of places with relation_close to
table_close, which were missed earlier.
2020-04-14 23:12:15 +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
c6350aaaea Move decompress_chunk to nodes/decompress_chunk
Code for all custom nodes should live under the nodes directory
to make different parts of the code easier to distinguish.
2019-11-06 10:43:36 +01:00