381 Commits

Author SHA1 Message Date
Matvey Arye
c3b6fb90d9 Fix bug with negative dimension values
Previously, negative dimension values had an off-by-one bug where the
wrong chunk was created for points on chunk borders. This PR fixes that.
2017-08-28 10:29:05 -04:00
Matvey Arye
3c69e4fc9e Fix semantics of time_bucket on DATE input
Previously, date was auto-cast to timestamptz when time_bucket was
called. This led to weird behavior with regards to timezones and
the return value was a timestamptz. This PR makes time_bucket return
a DATE on DATE input and avoids all timezone conversions.
2017-08-24 15:45:49 -04:00
Olof Rensfelt
0137c92cdb Fix output order of chunk dimensions and ranges in chunk_relation_size. 2017-08-24 11:14:52 +02:00
Rob Kiefer
fcb7114c26 Prepare the repo for next development cycle 2017-08-21 15:19:17 -04:00
Rob Kiefer
c54dd6fd08 Release 0.4.0 2017-08-21 13:57:36 -04:00
Rob Kiefer
2a51cf0701 Add support for negative values in dimension range
Previously dimension_slice would only allow ranges to start and
end with values >= 0. However, this did not allow for timestamps
prior to 1970 because those times would be represented by negative
integers. With this PR we now support dates prior to 1970.

Addresses issue #153.
2017-08-18 11:28:11 -04:00
Michael J. Freedman
f2d5c3fc5d Error if add_dimension given both partition number and interval length 2017-08-18 10:41:14 -04:00
Rob Kiefer
f3df02d50c Improve handling of non-TIMESTAMP/TZ timestamps
Previously the default chunk time in microseconds was too large
for a SMALLINT or INTEGER field. Now, we only assign a default
value if the type is TIMESTAMP or TIMESTAMPTZ. Integer timestamps,
such as SMALLINT, INTEGER, and BIGINT, need to be explicitly set
since only the user knows what units the numbers represent.

Further, we check to make sure the chunk time interval is not too
large for SMALLINT and INTEGER so as to avoid confusing problems
later when the user goes to insert.
2017-08-17 12:13:00 -04:00
Rob Kiefer
69ac1a37d8 Prepare the repo for next development cycle 2017-08-02 09:54:34 -04:00
Rob Kiefer
d1f66c5af4 Release 0.3.0 2017-07-31 13:27:01 -04:00
Erik Nordström
1f3dcd814f Make INSERTs use a custom plan instead of triggers
With this change, hypertables no longer rely on an INSERT trigger to
dispatch tuples to chunks. While an INSERT trigger worked well for
both INSERTs and COPYs, it caused issues with supporting some regular
triggers on hypertables, and didn't support RETURNING statements and
upserts (ON CONFLICT DO UPDATE).

INSERTs are now handled by modifying the plan for INSERT statements. A
custom plan node is inserted as a subplan to a ModifyTable plan node,
taking care of dispatching tuples to chunks by setting the result
table for every tuple scanned.

COPYs are handled by modifying the regular copy code. Unfortunately,
this required copying a significant amount of regular PostgreSQL
source code since there are no hooks to add modifications. However,
since the modifications are small it should be fairly easy to keep the
code in sync with upstream changes.
2017-07-27 15:49:01 +02:00
Olof Rensfelt
f23bf58285 Remove empty chunks on TRUNCATE hypertable. 2017-07-26 21:17:44 +02:00
Olof Rensfelt
6cc5aa19bb Add update scripts from earlier versions to the extension.
To allow upgrading versions older than the most recent one,
update scripts from older versions need to be added to the
extension. This is now done by including all files in the
file extra_extension_files.txt to the extension. Currently
that file needs to be manually updated when a new release
is built.
2017-07-18 10:27:36 +02:00
Rob Kiefer
6d075af802 Release 0.2.0 2017-07-13 09:04:01 -04:00
Matvey Arye
a0db5004f4 Add update script for PR #121
Also includes some update infrastructure changes. Main difference
is that sql/updates/ scripts are now split into pre- and post- files.
This is needed because table updates need to happen before reloading
functions (some functions checked for accessing right schema at
definition time). Meanwhile trigger updates need to happen after
since triggers must refer to valid functions at definition time.
2017-07-13 08:33:08 -04:00
Matvey Arye
83c75fd154 Add support for most triggers on hypertables
This adds support for all types of triggers on a hypertable except
INSERT AFTER. UPDATE and DELETE ROW triggers are automatically copied from
a hypertable onto the chunks. Therefore, any trigger defined on the
parent hypertable will apply to any row in any of the chunks as well.
STATEMENT level triggers and iNSERT triggers need not be copied in this
way.
2017-07-13 08:27:54 -04:00
Olof Rensfelt
e0eeeb9bdb Add hypertable, chunk, and indexes size utils functions. 2017-07-13 14:14:40 +02:00
Olof Rensfelt
4d2a65daa6 Add infrastructure to build update script files.
SQL code is now split into setup, functions, and init files to
allow a subset to be run when the extension is updated. During
build, an update script is now also generated.
2017-07-12 13:00:29 -04:00
Olof Rensfelt
a5725d9875 Add support to rename and change schema on hypertable. 2017-07-12 16:53:02 +02:00
Olof Rensfelt
84b0338498 Add function to get git version of code base. 2017-07-10 10:33:15 +02:00
Matvey Arye
70ede45083 Fix off-by-one error when creating aligned chunks
It is not an error for range_end of a new chunk to be equal to
range_start of an existing chunk because range_end is exclusive.
Fix logic not to throw an error in that case.
2017-06-27 16:51:07 -04:00
Erik Nordström
696cc4c4f1 Provide API for adding hypertable dimensions
A new public-facing API `add_dimension(table, column, ...)`
makes it possible to add additional dimensions (partitioning
columns) to a hypertable.

Currently, new dimension can only be added to empty tables.

The code has also been refactored with a corresponding
internal function that is called by both `add_dimension()`
and `create_hypertable()`.
2017-06-27 19:39:14 +03:00
Matvey Arye
97681c2328 Fixes permission handling
Previously, catalog tables were not fully protected from malicious
non-superusers. This PR fixes permission handling be severely
restricting permissions to the catalog and instead using SECURITY
DEFINER functions to alter the catalog when needed without giving
users permission to do those same operations outside of these functions.
In addition, these functions check for proper permissions themselves
so are safe to use.

This PR also makes sure that chunk tables have the same owner as the
hypertable and correctly handles `ALTER TABLE...OWNER TO` commands to
keep this info in sync.
2017-06-27 11:20:41 -04:00
Matvey Arye
aca7f326b3 Fix extension drop handling
Previously, the extension could end up in a bad state if it
was dropped as part of a cascade. This PR fixes that by
checking explicitly for the presence of the proxy table
to make sure we are not in the middle of an extension
drop. Fixes #73.
2017-06-27 10:57:10 -04:00
Erik Nordström
0f4169c171 Fix check constraint on dimension table
Also:
- Fix indentation
- Fix comments
2017-06-22 20:15:38 +02:00
Erik Nordström
a6309dac48 Fix a number of comments and cleanup unused code 2017-06-22 20:15:38 +02:00
Matvey Arye
9489d06595 Some minor code cleanup 2017-06-22 20:15:38 +02:00
Erik Nordström
71c5e7801f Fix and refactor tablespace support
Tablespaces can now be associated with a hypertable
using the new user-facing API attach_tablespace().
Alternatively, if the main table, which is to be
converted into a hypertable, was created with an
associated tablespace, that tablespace will
automatically be associated also with the hypertable.

Whenever a chunk is created, a tablespace will be
chosen from the ones associated with the chunk's
hypertable (if any). This is done in a way that ensures
consistency in one dimension. I.e., if a hypertable
has a closed (space) dimension with a fixed number
of slices (ranges), it will ensure that chunks that
fall in the same slice will alsp be stored in the same
tablespace.

If a hypertable has more than one closed dimension,
the first one will be used to assign tablespaces
to chunks. If the table has no closed dimensions, but
one or more open (time) dimensions, then the first
time dimension will be used. However, since open
dimensions do not have a fixed number of slices,
tablespaces will be assigned in a round-robbin
fashion as new slices are created. Still, chunks
in the same time slice will be stored in the same
tablespace.
2017-06-22 20:15:38 +02:00
Erik Nordström
15657b5435 Remove unused code and add more code documentation
- Remove get_or_create_chunk()
- Fix warnings in metadata_queries + cleanups
- Documentation nits
- Fix mixed declaration and code warning
2017-06-22 20:15:38 +02:00
Matvey Arye
5452dc56d9 Fix partiton functions; bug fixes (including memory) 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
3c460f02b4 Fix partitioning, memory, and tests 2017-06-22 20:15:38 +02:00
Erik Nordström
fe51d8d7fc Add native scan for the chunk table
- The chunk table can now be scanned in the C code
- Rename DimensionAxis to DimensionVec
2017-06-22 20:15:38 +02:00
Matvey Arye
fc68baa8cc Separate out subspace_store and add it to the hypertable object as well 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
Matvey Arye
0584c47c7a Created chunk_get_or_create in sql with an SPI connector in C 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
d3bdcbaf1b Start refactoring to support any number of partitioning dimensions
The current schema and code support only one "time" and one "space"
dimension for partitioning. While this is probably good enough for
many applications, it won't allow partitioning along two "space"
dimensions, like longitude and latitude, for instance.

This commit is a first stab at refactoring the metadata schema and
internal functionality to support any number of partitioning
dimensions. The idea is to think of a hypertable as partitioned in N
dimensions, where a partition (chunk) is a hypercube in the
N-dimensional hyperspace. Each dimension is divided into a number of
"slices" (dimensional partitions) that each occupies a range along the
dimension's keyspace axis.

A dimension can either be "closed" or "open", indicating a space-like
or time-like dimension, respectively. Closed dimensions have a limited
number of partitions that cover the entire domain. Open dimensions have
an unlimited number of partitions and thus must be created on-demand
as needed for the inserted data.

Note that the open/closed notation is preferred over time/space, since
an open dimension could be used for something other than time (for
instance, a sequence number). Conversely, closed dimensions need not be
space-like as it is entirely possible to use time as a closed
dimension.

Another advantage of this refactoring is that it now unifies a lot
of the logic for time and space that used to be separate.

On a schema-level, this gets rid of partition/partitition_epoch tables and
replace them with dimension, dimension_slice, and chunk_constraint. It
also removes the time columns associated with a chunk and instead makes
this a separate dimension stored as a chunk_constraint.
2017-06-22 20:15:38 +02:00
Olof Rensfelt
2a01ebca61 Ensure that chunks are aligned.
Previously, chunks could end up unaligned betweeen partitions if the chunk_time_interval
was updated between chunk creations. Now there is a check when a chunk is created whether there is
a chunk matching the time point in another partition and if there is, the new chunk is created
with the same interval.
2017-06-15 13:19:29 -04:00
Matvey Arye
73622bf1eb Fix default index creation duplication of indexes
Previously there was a bug causing indexes for partition, time to
be created twice.  This fixes #77.
2017-06-08 14:25:32 -04: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
Matvey Arye
db01c84c2d Make time-bucket function parallel safe
There was no reason for it not to be parallel safe before.
2017-06-02 16:15:51 -04:00
Olof Rensfelt
997029a86d if_not_exist flag to create_hypertable now works on hypertables with data as well 2017-06-01 16:51:37 +02:00
Olof Rensfelt
8ccc8cc156 Add if_not_exists flag to create_hypertable()
Previously create_hypertable() would throw an error when called on
an already existing hypertable. This can now be skipped by setting
if_not_exists argument to true.
2017-05-24 18:37:24 +02:00
Matvey Arye
cedcafc959 Remove setup_timescaledb() and fix pg_dump/pg_restore.
This PR removes the need to run setup_timescaledb. It also fixes
pg_dump and pg_restore. Previously, the database would restore in
a broken state because trigger functions were never attached to
meta tables (since setup_timescaledb() was not run). However, attaching
those triggers at extension creation also causes problems since the data
copy happens after extension creation but we don't want triggers fired
on the data restored (that could cause duplicate rows, for example).

The solution to this chicken-and-egg problem in this PR is to have
a special configuration (GUC) variable `timescaledb.restoring` that,
if 'on', would prevent the extension from attaching triggers at
extension creation. Then, after restoration, you'd call
restore_timescaledb() to attach the triggers and unset the GUC above.
This procedure is documented in the README as part of this PR.
2017-05-22 16:12:21 -04:00
Matvey Arye
fc4ddd65b5 Fix bug with dropping chunks on tables with indexes 2017-05-20 15:54:46 -04:00
Matvey Arye
32215ff6c5 Add default indexes for hypertables
Changed create_hypertable to add time DESC and partitioning_column, time DESC
indexes by default (the latter only if partitioning column not null).
Indexes only created if there is no index on time and
partitioning_column, time respectively. Index creation can be turned off
with the create_default_indexes parameter to create_hypertable (default true).
2017-05-20 15:54:46 -04:00
Matvey Arye
662be94d69 Add the first(value, time),last(value, time) aggregates
Add the first and last aggregate functions, which allows for getting
the first and last value, by time, per group. Addresses issue #30.
2017-05-16 09:46:49 -04:00
Matvey Arye
31ee92a6ee Remove unit tests and sql/setup
Remove unit tests because most of our testing is in regression tests
anyway and regression tests are better integrated with the Postgres
extension workflow. sql/setup scripts were old and not used except
for unit testing.
2017-05-16 09:04:13 -04:00