34 Commits

Author SHA1 Message Date
Erik Nordström
71962b86ec Refactor dimension-related API functions
The functions for adding and updating dimensions have been refactored
in C to:

- improve usage of proper error codes
- make messages that better conform with the PostgreSQL standard.
- improve security by avoiding that lots of code run under SECURITY DEFINER

A new if_not_exists option has also been added to add_dimension() and
a the number of partitions can now be set using the new
set_number_partitions() function.

A bug in the validation of smallint time intervals has been fixed. The
previous code didn't check for intervals > 0 and smallint intervals
accepted values up to UINT16_MAX instead of INT16_MAX.
2018-01-25 19:02:34 +01:00
Erik Nordström
e593876cb0 Refactor tablespace handling
Attaching tablespaces to hypertables is now handled
in native code, with improved permissions checking and
caching of tablespaces in the Hypertable data object.
2017-12-09 18:27:50 +01:00
Erik Nordström
c4a46ac8a1 Add hypertable cache lookup on ID/pkey
Hypertables can now be looked up through the cache on
ID/pkey in addition to OID.
2017-12-09 18:27:50 +01:00
Erik Nordström
e1a0e819cf Refactor and fix cache invalidation
TimescaleDB cache invalidation happens as a side effect of doing a
full SQL statement (INSERT/UPDATE/DELETE) on a catalog table (via
table triggers). However, triggers aren't invoked when using
PostgreSQL's internal catalog API for updates, since PostgreSQL's
catalog tables don't have triggers that require full statement
parsing, planning, and execution.

Since we are now using the regular PostgreSQL catalog update API for
some TimescaleDB catalog operations, we need to do cache invalidation
also on such operations.

This change adds cache invalidation when updating catalogs using the
internal (C) API and also makes the cache invalidation more fine
grained. For instance, caches are no longer invalidated on some
INSERTS that do not affect the validity of objects already in the
cache, such as adding a new chunk.
2017-11-27 17:33:10 +01: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
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
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
Matvey Arye
44da2c0be6 Run pgindent on code 2017-06-26 18:10:59 -04:00
Erik Nordström
a6309dac48 Fix a number of comments and cleanup unused code 2017-06-22 20:15:38 +02:00
Matvey Arye
ce3d630b6d Run pgindent on code 2017-06-22 20:15:38 +02:00
Erik Nordström
e75cd7e66b Finer grained memory management
Also fix a number of memory allocation bugs
and properly initialize chunks that are allocated
during a scan for chunks.
2017-06-22 20:15:38 +02:00
Matvey Arye
f5d7786eed Change the semantics of range_end to be exclusive 2017-06-22 20:15:38 +02:00
Erik Nordström
700c9c8a79 Refactor insert path in C.
Also in this commit:

- Rename time/space to open/closed for more generality.
- Create a Point data type for mapping a tuple to an
  N-dimensional space.
- Numerous fixes and cleanups.
2017-06-22 20:15:38 +02:00
Erik Nordström
7b8de0c592 Refactor catalog for new schema and add native data types
This is the first stab at updating the table and data type
definitions in the catalog module in the C code. This also
adds functions for natively scanning the dimension and
dimension_slice tables.
2017-06-22 20:15:38 +02:00
Matvey Arye
bfe58b61f7 Refactor towards supporting version upgrades
Clean up the table schema to get rid of legacy tables and functionality
that makes it more difficult to provide an upgrade path.

Notable changes:
* Get rid of legacy tables and code
* Simplify directory structure for SQL code
* Simplify table hierarchy: remove root table and make chunk tables
* inherit directly from main table
* Change chunk table suffix from _data to _chunk
* Simplify schema usage: _timescaledb_internal for internal functions.
* _timescaledb_catalog for metadata tables.
* Remove postgres_fdw dependency
* Improve code comments in sql code
2017-06-08 13:55:05 -04:00
Erik Nordström
2bc60c79e3 Fix time interval field name in hypertable cache entry
This change makes the naming of the time interval field in
the hypertable cache entry consistent with the table schema.
2017-05-23 16:40:00 -04:00
Matvey Arye
b2900f9f85 Disable query optimization on regular tables (non-hypertables)
This PR disables query optimizations on regular tables by default.
The option timescaledb.optimize_plain_tables = 'on' enables them
again. timescaledb.disable_optimizations = 'on' disables all
optimizations (note the change from 'true' to 'on').
2017-05-20 15:31:47 -04:00
Erik Nordström
c60b08e83a Fix DROP EXTENSION
DROP EXTENSION didn't properly reset caches and other saved state
causing various errors related to bad state when the extension was
dropped and/or recreated later.

This patch adds functionality to track the state of the extension and
also signals DROP EXTENSION to other backends that might be running,
allowing them to reset their internal extension state.
2017-03-22 19:43:40 +01:00
Erik Nordström
89692c9761 Add cache statistics and do minor cleanup
Track statistics for cache hits and misses in the cache module.
Currently not exposed to SQL, but might be useful for internal
debugging.
2017-03-22 09:57:44 +01:00
Erik Nordström
852ba7ee97 Avoid allocating hypertable cache storage for negative entries.
The hypertable cache stores negative cache entries to speed up checks
for tables that aren't hypertables. However, a full hypertable cache
entry was allocated for these negative entries, thus wasting cache
storage. With this update, the full entry is only allocated for
positive entries that actually represent hypertables.
2017-03-14 13:31:34 +01:00
Matvey Arye
1f13354bf9 Make the planner use metadata cache
Previously, the planner used a direct query via the SPI interface to
retrieve metadata info needed for query planner functions like query
rewriting. This commit updates the planner to use our caching system.
This is a performance improvement for pretty much all operations,
both data modifications and queries.

For hypertables, this added a cache keyed by the main table OID and
added negative entries (because the planner often needs to know if a
table is /not/ a hypertable).
2017-03-13 14:18:33 -04:00
Erik Nordström
3a03348356 Move catalog table definitions to catalog.h
This patch continues work to consolidate catalog information
and definitions to the catalog module.

It also refactors the naming of some data types to adhere
to camelcase naming convention (Hypertable, PartitionEpoch).
2017-03-10 20:39:20 +01:00
Erik Nordström
d1ad3afd49 Perform native scans for chunks (replicas)
Previously, chunk replicas were retreived with an SPI query. Now, all
catalog items are retrieved with native scans, with the exception of
newly created chunks.

This commit also refactors the chunk (replica) cache, removing some
data structures that were duplicating information. Now chunks are
cached by their ID (including their replicas) instead of just the
set of replicas. This removes the need for additional data structures,
such as the replica set which looked like a chunk minus time info,
and the cache entry wrapper struct. Another upside is that chunks
can be retrieved from the cache directly by ID.
2017-03-10 17:28:49 +01:00
Matvey Arye
eb09ccc980 Enable catalog to support multiple indexes per table 2017-03-09 11:32:12 -05:00
Matvey Arye
00b69ac010 Change close-chunk logic to use a c-based fastpath
This change is a performance improvement. Previously each insert called
a plpgsql function to check if there is a need to close the chunk. This
patch implements a c-only fastpath for the case when the table size is
less than the configured chunk size.
2017-03-07 12:05:53 -05:00
Matvey Arye
32c45b75b2 formatting with pgindent 2017-03-06 15:20:00 -05:00
Matvey Arye
4d4ac78ef5 cleanup 2017-03-05 10:13:45 -05:00
Matvey Arye
64e8ec1877 Ordering inserts to avoid deadlocks 2017-03-03 10:10:14 -05:00
Erik Nordström
eebd9bbbc1 Use native scan for chunks.
The chunk catalog table is now scanned with a native
scan rather than SPI call.

The scanner module is also updated with the option of
of taking locks on found tuples. In the case of chunk
scanning, chunks are typically returned with a share
lock on the tuple.
2017-03-02 12:25:00 +01:00
Erik Nordström
61668c837a Allow heap/index scans to abort early if condition is met.
Aborting scans can be useful when scanning large tables or indexes and
the scan function knows that a condition has been met (e.g., all
tuples needed have been found). For instance, when scanning for
hypertable partitions, one can abort the scan when the found tuple
count equals the number of partitions in the partition epoch.
2017-03-02 12:25:00 +01:00
Erik Nordström
1daec06ce6 Use native scans for partition epochs and partitions.
This patch refactors the code to use native heap/index scans for
finding partition epochs and partitions. It also moves the
partitioning-related code and data structures to partitioning.{c,h}.
2017-03-02 12:25:00 +01:00
Erik Nordström
c92fa28ea8 Add scanner module implementing both heap and index scans. 2017-03-02 12:24:59 +01:00
Erik Nordström
f99669c880 Use direct index scan for hypertable lookups.
This is a first stab at moving from SPI queries
to direct heap/index scans for cleaner and more
efficient code. By doing direct scans, there is no
need to prepare and cache a bunch of query plans
that make the code both slower and more complex.

This patch also adds a catalog module that keeps
cached OIDs and other things for catalog tables.
The cached information is updated every time the
backend switches to a new database. A permission
check is also implemented when accessing the catalog
information, but should probably be extended to
tables and schemas in the future.
2017-03-02 12:24:59 +01:00
Matvey Arye
67ad21ee36 Cache hypertable metadata information for faster inserts.
Add caches for hypertable metadata to make it faster to map
INSERT rows to the chunk they should go into.
2017-03-02 12:24:53 +01:00