19 Commits

Author SHA1 Message Date
Erik Nordström
a51d21efbe Fix issue creating dimensional constraints
During chunk creation, the chunk's dimensional CHECK constraints are
created via an "upcall" to PL/pgSQL code. However, creating
dimensional constraints in PL/pgSQL code sometimes fails, especially
during high-concurrency inserts, because PL/pgSQL code scans metadata
using a snapshot that might not see the same metadata as the C
code. As a result, chunk creation sometimes fail during constraint
creation.

To fix this issue, implement dimensional CHECK-constraint creation in
C code. Other constraints (FK, PK, etc.) are still created via an
upcall, but should probably also be rewritten in C. However, since
these constraints don't depend on recently updated metadata, this is
left to a future change.

Fixes #5456
2023-03-24 10:55:08 +01:00
Sven Klemm
a4081516ca Append pg_temp to search_path
Postgres will prepend pg_temp to the effective search_path if it
is not present in the search_path. While pg_temp will never be
used to look up functions or operators unless explicitly requested
pg_temp will be used to look up relations. Putting pg_temp in
search_path makes sure objects in pg_temp will be considered last
and pg_temp cannot be used to mask existing objects.
2022-05-03 07:55:43 +02:00
Sven Klemm
6dddfaa54e Lock down search_path in install scripts
This patch locks down search_path in extension install and update
scripts to only contain pg_catalog, this requires that any reference
in those scripts is fully qualified. Additionally we add explicit
create commands to all update scripts for objects added to the
public schema. This change will make update scripts fail if a
function with identical signature already exists when installing
or upgrading instead reusing the existing object.
2022-02-09 17:53:20 +01:00
Sven Klemm
3e28f10600 Fix constraint trigger on hypertables
When creating a constraint trigger on a hypertable the command
succeeds and the constraint trigger works correctly for existing
chunks but any chunk creation after that would fail with an
error, because the constraint trigger was treated like a normal
constraint. But since pg_get_constraintdef does not return a SQL
command for constraint triggers the corresponding command that was
created would throw an error.

Fixes #3235
2021-05-20 21:26:47 +02:00
Tyler Fontaine
1bccedf3f8 Limit Index Tablespace Lookup To p and u Constraints
This resolves an issue when using both constraints with index
tablespaces AND constraints that have no indexes on a single hypertable.

chunk_constraint_add_table_constraint() was attempting to add
`USING INDEX TABLESPACE` to all constraints when a given hypertable had
any constraint configured to use a tablespace, resulting in a SYNTAX
error and blocking the creation of new chunks.

The solution here is to limit index tablespace lookups to only the
constraint types which use indexes: primary key and unique so that only
those constraits will have `USING INDEX TABLESPACE` prepended when
necessary.
2020-11-04 08:39:44 -06:00
Ruslan Fomkin
cfb3331cab Use index tablespace during chunk creation
If a tablespace is provided for an index on a hypertable, it will be
also used for the index on new chunks. This is done when constraints
are created on new chunk from the hypertable constraints.

Fixes #903
2020-07-02 16:22:44 +02: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
e06733acf0 Fix casing in SQL license header to be consistent with elsewhere 2018-11-15 15:18:58 -05:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Mike Futerko
4f2f1a6eb7 Update the error messages to conform with the style guide; Fix tests
An attempt to unify the error messages to conform with the PostgreSQL error
messages style guide. See the link below:
https://www.postgresql.org/docs/current/static/error-style-guide.html
2018-07-10 12:55:02 -04:00
Erik Nordström
21efcce95c Refactor chunk table creation and unify constraint handling
This change is part of an effort to create a consistent way
of dealing with metadata catalog updates, which is currently
a mix of C API and INSERT/UPDATE/DELETE statements from SQL
code. This mix makes catalog handling unnecessarily complex as
there are multiple ways to update metadata, increasing the risk
of security issues with publically exposed SQL functions. It also
complicates things like cache invalidation, requiring different
mechanisms for C and SQL code. Catalog updates from SQL code
require triggers on metadata tables for cache invalidation that
do not work with native catalog updates.

The creation of chunks has been particularly messy in this regard,
making the code hard to follow. Especially the handling of a chunk's
constraints, where dimensional and other constraints were handled
differently. With this change, constraint handling is now consistent
across constraint types with a single API for updating metadata.

Reduce memory usage for out-of-order inserts

The chunk_result_relation_info should be put on the chunk memory
context. This will cause the rri constraint expr to also go onto
that context and be correctly freed when the chunk insert state
is destroyed.
2017-12-28 11:24:29 +01:00
Matvey Arye
90c7a6f546 Fix logic for one space partition
This PR fixes handling of one space partition. It
avoids creating a CHECK constraint and also fixes the
logic in default dimension range creation.
2017-12-18 12:31:14 -05:00
Matvey Arye
f38a578578 Fix handling of long constraint names 2017-12-09 12:05:34 -05:00
Matvey Arye
c420c11e44 Create a catalog entry for constraint-backed indexes
This change makes our catalog more in-line with the pg catalog.
It also will simplify a lot of other code.
2017-10-24 11:26:04 -04:00
Erik Nordström
097db3d589 Refactor chunk index handling
This change refactors the chunk index handling to make better use
of standard PostgreSQL catalog information, while removing the
hypertable_index metadata table and associated triggers, including
those on the chunk_index table. The chunk_index table itself is
also simplified.

A benefit of this refactoring is that indexes are no longer
created using string mangling to construct the CREATE INDEX command
for a chunk, based on the string definition of the hypertable
index. Instead, indexes are created in C using proper index-related
internal data structures.

Chunk indexes can now also be renamed and are added in the parent
index tablespace. Changing tablespace on a hypertable index also
recurses to chunks, as expected. Default indexes that are added when
creating a hypertable use the hypertable's tablespace.

Creating Hypertable indexes with the CONCURRENTLY modifier is
currently blocked, due to unclear semantics regarding concurrent
creation over many tables, including how to deal with snapshots.
2017-10-03 10:51:32 +02:00
Matvey Arye
238003316e Block ALTER TABLE and handle DROP TABLE on chunks
This PR adds logic to block alter table and handle drop operations on chunks.
2017-09-13 18:42:45 -04:00
Matvey Arye
19d3d8981b Handle changing the type of dimension columns correctly.
Update the type in the dimension metadata table and recreate
the check constraints.
2017-09-13 18:28:24 -04:00
Matvey Arye
48e0a61131 Remove triggers from chunk and chunk_constraint
Streamline code and remove triggers from chunk and
chunk_constraint. Lots of additional cleanup. Also removes need to CASCADE
hypertable drops (fixes #88).
2017-09-07 11:31:48 -04:00
Matvey Arye
4dcbe6114d Add support for hypertable constraints
This PR add support for primary-key, foreign-key, unique, and exclusion constraints.
Previously supported are CHECK and NOT NULL constraints. Now, foreign key
constraints where a hypertable references a plain table is support
(while vice versa, with a plain table references a hypertable, is still not).
2017-09-07 11:31:48 -04:00