17 Commits

Author SHA1 Message Date
Lakshmi Narayanan Sreethar
8e941b80ae Fix incorrect row count in EXPLAIN ANALYZE INSERT .. ON CONFLICT output
INSERT ... ON CONFLICT statements record few metrics in the ModifyTable
node's instrument but they get overwritten by hypertable_modify_explain
causing wrong output in EXPLAIN ANALYZE statments. Fix it by saving the
metrics into HypertableModify node before replacing them.

Fixes #6014
2023-09-01 00:44:55 +05:30
Sven Klemm
a9751ccd5e Move partitioning 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:

- get_partition_for_key(val anyelement)
- get_partition_hash(val anyelement)
2023-08-29 12:55:22 +02:00
Alexander Kuzmenkov
56945b37b8 Enable ON CONFLICT ON CONSTRAINT for hypertables
It now works since we started to rely on Postgres' arbiter
index inference.
2022-06-14 15:04:11 +05:30
Sven Klemm
cd71556504 Fix UPSERT with prepared statements
When doing upsert with prepared statement the code to restore
arbiter_indexes would not trigger when an error occurred on the
INSERT leading to a segfault on the next EXECUTE of the prepared
statement.
2019-04-30 22:57:12 +02:00
Sven Klemm
601524ff0c Fix ON CONFLICT when using prepared statements and functions
A prepared statement or function plan can be turned into a generic plan
after a couple executions. When this happens the last plan that run
through plan creation gets reused so we need to revert any modifications
we did to that plan so reusing it is safe.
2019-03-05 02:49:26 +01:00
Matvey Arye
2f6b58af21 Fix tlist on hypertable inserts inside CTEs
Previously, hypertable insert tlists were only fixed
for the top-level plan. We also need to fix the tlist
for hypertable inserts that appear inside ctes
2019-02-07 12:04:55 -05:00
Matvey Arye
ba32dab011 Fix displayed error when an arbiter index is missing.
When doing an upsert, we expect to be able to translate a
hypertable index used as an arbiter to a chunk index. But,
it is possible that the corresponding chunk index has been dropped.
Previously this resulted in a postgres generated error like
"unexpected failure to find arbiter index". We now handle
this more gracefully.
2019-02-05 17:13:05 -05:00
Matvey Arye
61e524e0c1 Make slot for upserts be update for every chunk switch
Previously, the slots for upserts were only updated when
a ChunkInsertState was created, but not when it was found in the
ChunkDispatch cache. This was wrong -- we need to update the slots
every time we switch to the chunk.

Right now the switch function is called on every tuple. We will
optimize that later to only be called when the previous chunk was
different. But, that is not part of this bug-fix PR.
2019-01-28 18:08:23 -05:00
Matvey Arye
8a7c127f6c Fix for ExecSlotDescriptor during upserts
Previously we set the mt_existing and onConflictProjInfo slot
descriptors only when the current chunk had a tup_conv_map this
was based on a false assumption that these slot descriptors had the
hypertable's slot descriptor. In fact, since we are reusing these slots
across chunks, the slot descriptor will correspond to the previous
chunk's one. This led to an error if the previous chunk had a
tup_conv_map but the current one did not.

Most of the work done here was by @gayyappan with minor improvements by
@cevian. The latter is submitting because of a time-crunch having to do
with upcoming release.
2019-01-28 18:08:23 -05: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
Matvey Arye
c1db608664 Fix upsert TLE translation when mapping variable numbers
Previously, there was a bug when chunks contained dropped columns
in the mapping of variable numbers. This PR fixes the bug and adds a
test for this case.
2018-11-20 09:53:28 -05:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Matvey Arye
ca6e5ef5a8 Fix upserts on altered tables.
Previously, upserts (ON CONFLICT) clauses did not work well on tables
where the hypertable attribute numbers did not match chunk attribute
numbers. This is common if the hypertable has dropped columns or
there were other alter commands run on the hypertable before
chunks were created.

This PR fixes the projection of the returning clause as well
as the update clauses. It also fixes the where clause for ON CONFLICT
UPDATE. These fixes are mostly about mapping the attribute numbers
from the hypertable attnos->chunk attnos. Some slot tupleDesc also
needed to be changed to the tupleDesc of the chunk.

Note that because of the limitations in PG 9.6 we had to copy over
some expressions from the ModifyTable plan node inside the chunk
dispatch. These original expressions are irrecoverable from the
ModifyTableState node or the ProjectionInfo structs in 9.6.
2018-06-21 15:13:29 -04:00
Matvey Arye
8378beb236 Enable hypertable inserts within CTEs
Previously, the chunk dispatch node used arbiter index and other
information from the top-level Query node. This did not work with CTEs
(and probably subqueries) because the info for this insert was not at
the top-level. This commit changes the logic to use that same info from the
parent ModifyTable node (and ModifyTableState).

This commit also changes the logic to translate the arbiter indexes
from the hypertable index to the chunk index directly using our catalog
tables instead of re-inferring the index on the chunk.
2018-03-23 12:41:44 -04:00
Matvey Arye
543a75f865 Refactor regression tests
This commit moves a lot of test setup logic to runner.sh. Also
passes the right commands to the regression infrastructure to create
appropriate users and run tests as a regular user.
2017-10-05 15:56:33 -04:00
Erik Nordström
953346c18b Make VACUUM and REINDEX recurse to chunks
Previously, when issued on hypertable, database maintenance
commands, like VACUUM and REINDEX, only affected the main
table and did not recurse to chunks.

This change fixes that issue, allowing database maintainers
to issue single commands on hypertables that affect all
the data stored in the hypertable.

These commands (VACUUM, REINDEX) only work at the table level
for hypertables. If issued at other levels, e.g., schema, or
database, the behavior is the same as in standard PostgreSQL
as all tables are covered by default.

REINDEX commands that specify a hypertable index do not
recurse as that requires mapping the hypertable
index to the corresponding index on the chunk. This might
be fixed in a future update.
2017-08-15 17:26:52 +02:00
Erik Nordström
23f9d3c0b0 Add support for upserts (ON CONFLICT DO UPDATE)
Upserts are now supported as long as there is a unique index that
includes all hypertable dimensions. Upserts using ON CONFLICT ON
CONSTRAINT statements are currently unsupported, although this should
be possible in the future.
2017-07-27 18:02:23 +02:00