767 Commits

Author SHA1 Message Date
Narek Galstyan
a8c637e112 Create aggregate functions only once to avoid dependency issues
There is no CREATE OR REPLACE AGGREGATE which means that the only way to replace
an aggregate is to DROP then CREATE which is problematic as it will fail
if the previous version of the aggregate has dependencies.
This commit makes sure aggregates are not dropped and recreated every time.
NOTE that WHEN CREATING NEW FUNCTIONS in sql/aggregates.sql you should also make
sure they are created in an update script so that both new users and people
updating from a previous version get the new function.
sql/aggregates.sql is run only once when TimescaleDB is installed and is not
rerun during updates that is why everything created there should also be in an
update file.
Fixes #612
2018-08-06 15:07:12 -04:00
Narek Galstyan
a97f2affef Add support for custom hypertable dimension types
Previously, if a hypertable dimension type did not have a default
hash function, create_hypertable would throw an error.
However, this should not be the case if a custom partitioning
function is provided.
This commit addresses the issue making sure that arbitrary
custom types can be used as partitioning dimensions as long
as a valid partitioning function is provided.
Fixes #470.
2018-08-06 13:01:39 -04:00
Matvey Arye
dfe026c3b6 Refactor create_hypertable rel access.
This refactor does three things:
1) Upgrades the lock taken to AccessExclusive. This is
to prevent upgrading locks during data migration.
2) Explicitly release lock in the IF NOT EXISTS case.
This is more inline with what PG itself does. Also,
optimize the easy IF NOT EXISTS case.
3) Exposes a rel inside create_hypertable itself
so that checks can use one rel instead of opening and closing
a bunch of them.
2018-08-06 12:15:18 -04:00
Narek Galstyan
ed379c3dd8 Validate existing indexes before adding a new dimension
If the argument column of add_dimension is not in all
of hypertable indexes that have UNIQUE, PRIMARY KEY
or EXCLUSION constraints, then add_dimension call
should fail.
This commit enforces the above.
2018-08-03 11:30:22 -04:00
Rob Kiefer
005813da21 Make update tests more composable.
This removes a lot of duplicated code across the two versions of
update tests (one with testing of constraints vs one without) and
potentially allows for further additions more easily. Also, this
splits Travis testing of updates into two jobs so they can run
concurrently and reduce the amount of turnaround time for PRs.
Finally, added versions since 0.8.0 that were not previously being
tested.
2018-08-03 10:07:09 -04:00
Erik Nordström
1f2d27671b Fix and improve show_indexes test support function
This fixes the show_indexes test support function to properly show the
columns of the indexes instead of the table. The function now also
shows the expressions of expression indexes.
2018-08-03 09:51:28 +02:00
Erik Nordström
77b00356c4 Enforce IMMUTABLE partitioning functions
This adds a simple check to enforce that partitioning functions
are IMMUTABLE. This is a requirement since a partitioning function
must always return the same value given the same input.
2018-08-02 20:45:10 +02:00
Erik Nordström
cbc5e60abe Block NO INHERIT constraints on hypertables
Constraints with the NO INHERIT option does not make sense on a
hypertable's root table since these will not be enforced.

Previously, NO INHERIT constraints were blocked on chunks, and were
thus not enforced until chunk creation time, allowing creation of NO
INHERIT constraints on empty hypertables, but then causing failure at
chunk-creation time. Instead, NO INHERIT constraints are now properly
blocked at the hypertable level.
2018-07-30 15:34:03 +02:00
Matvey Arye
e362e9cf18 Block mixing hypertables with postgres inheritance 2018-07-26 16:16:40 -04:00
Matvey Arye
011f12be71 Add support for CLUSTER ON and SET WITHOUT CLUSTER
Add support for:

  * ALTER TABLE ... CLUSTER ON
  * ALTER TABLE ... SET WITHOUT CLUSTER

on both hypertables and chunks. Commands on hypertables get
passed down to chunks.
2018-07-24 14:27:13 -04:00
Matvey Arye
e947c6be3a Improve handling of column settings
This PR adds better handling for the following commands:

* ALTER TABLE ... ALTER COLUMN ... SET (attribute_name = value)
* ALTER TABLE ... ALTER COLUMN ... RESET (attribute_name)
* ALTER TABLE ... ALTER COLUMN ... SET STATISTICS
* ALTER TABLE ... ALTER COLUMN ... SET STORAGE

For each of the above commands the associated settings are not properly
propagated to existing chunks and new chunks are created with the
same settings as the hypertable.

We also now allow these commands to be run on chunks.
2018-07-24 14:11:53 -04:00
Matvey Arye
6d1c4bc444 Test GENERATED AS IDENTITY Postgres commands.
PG 10 added the GENERATED AS IDENTITY feature. This
PR adds tests to make sure it works with TimescaleDB.
2018-07-24 12:54:10 -04:00
Matvey Arye
fc4957b90c Update statistics on parent table when doing ANALYZE
Previously, when running a VACUUM ANALYZE or ANALYZE on
a hypertable the statics on the parent table (hypertable)
were not correctly updated. This fixes that problem
and adds tests.
2018-07-24 12:38:16 -04:00
Matvey Arye
82942bf04e Enable backwards compatibility for loader for 0.9.0 and 0.9.1
Old versions used a GUC to determine whether the loader was present.
This PR sets that GUC in the loader so that those versions once
again work with the new loader.
2018-07-24 12:01:33 -04:00
Rob Kiefer
c810be99ef Remove unused files from scripts/
Both setup-db.sh and sql/setup_sample_hypertable.psql don't appear
to be used anywhere in our repo or mentioned in the docs. We have
code snippets and guides to replace them, so they are no longer
needed.
2018-07-24 10:03:30 -04:00
Matvey Arye
14967a03f6 Fix PG version in ABI tests 2018-07-17 18:52:36 -04:00
Matvey Arye
eb2e262619 Improve version checking
This PR adds a load-time check to the versioned extension for the
expected Postgres versions. This better handles the case where the
extension is distributed as a binary and compiled on a different
Postgres version than the one it is running on.

We also change the versioning to require:
PG >= 9.6.3 to avoid issues with missing functions in previous versions
OR
PG >= 10.2 to avoid issues with ABI incompatibility at PG 10.0 and 10.1
2018-07-16 14:06:13 -04:00
Rob Kiefer
d967bce275 Prepare the repo for next development cycle 2018-07-13 15:22:12 -04:00
Rob Kiefer
f06f853f89 Release 0.10.1 0.10.1 2018-07-12 15:54:17 -04:00
David Kohn
8b58500d76 Fix bug where dropping triggers caused dangling references in pg_depend, disallow disabling triggers on hypertables 2018-07-11 13:44:22 -04:00
Amy Tai
745b8ab95d Fixing CustomScan pruning whenever the subplan is NOT of a Scan type. This bug manifested in LATERAL joins that have a time restriction and a constraint referencing the upper-level plan. As an optimization, also added a special case when the subplan is of type T_Result, which enables chunk pruning in this special case. 2018-07-11 13:08:44 -04:00
Amy Tai
472bf6a298 Add runtime error for pgindent if objdump is not installed 2018-07-11 12:17:46 -04:00
Rob Kiefer
67a8a41e22 Make chunk identifiers formatting safe using format 2018-07-11 11:54:33 -04:00
Rob Kiefer
41af6ff3ae Fix misreported toast_size in chunk_relation_size funcs
A bug in the SQL for getting the size of chunks would use the
TOAST size of the main/dummy table as the toast size for the
chunks rather than each chunks' own toast size.
2018-07-11 11:54:33 -04:00
Matvey Arye
2ec065b538 Fix formatting to comply with pgindent
This PR fixes all the formatting to be inline with the latest version of
pgindent. Since pgindent does not like variables named `type`, those
have been appropriately renamed.
2018-07-11 09:40:29 -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
3c28f65f44 Release cache pin memory
Cache pins are allocated on the CacheMemoryContext in order to survive
subtransactions, and, optionally, main transactions (in case of, e.g.,
clustering or vaccuming). However, cache pins that are released also
needs to free memory on the CacheMemoryContext in order to avoid
leaking memory in a session.

This change ensures cache pin memory is freed when a cache pin is
released. It also allocates cache pins on a separate memory context,
which is a child of the CacheMemoryContext. This separate memory
context makes it easier to track the memory used by cache pins and
also release it when necessary.
2018-07-10 10:15:30 +02:00
Erik Nordström
abe76fc70a Add support for changing chunk schema and name
Previously, chunks could be renamed and have their schema changed, but
the metadata in the TimescaleDB catalog was not updated in a
corresponding way. Further, renaming a chunk column was possible,
which could break functionality on the hypertable.

Then catalog metadata is now properly updated on name and schema
changes applied to chunks. Renaming chunk columns have been blocked
with an informational error message.
2018-07-06 10:43:42 +02:00
Michael J. Freedman
6e193c6ec9 Add contributions section in README, error messages to style guide 2018-06-28 23:11:53 -04:00
Rob Kiefer
106adfb735 Prepare the repo for next development cycle 2018-06-28 15:38:50 -04:00
Rob Kiefer
5be8fb5301 Release 0.10.0 0.10.0 2018-06-27 11:36:38 -04:00
Erik Nordström
12bc1175f8 Fix static analyzer warning when checking for index attributes
This fixes a static analyzer warning about using an unititalized
pointer. The analyzer doesn't realize that elog() will generate an
exception, so that the unitialized NULL check will never occur. This
change will clarify the code and silence the static analyzer.
2018-06-26 15:01:54 +02:00
Erik Nordström
7d9f49b4c0 Fix missing NULL check when creating default indexes
This fixes a missing NULL check when creating default indexes that was
caught by a static analyzer.
2018-06-26 13:45:43 +02:00
Matvey Arye
ff1ab457e7 Bump minimum version for ABI test to 9.6.2
We need the function `convert_tuples_by_name_map` which only
appears in 9.6.2.
2018-06-25 10:27:58 -04:00
Erik Nordström
2e1f3b9fd0 Improve memory allocation during cache lookups
Previously, cache lookups were run on the cache's memory
context. While simple, this risked allocating transient (work) data on
that memory context, e.g., when scanning for new cache data during
cache misses.

This change makes scan functions take a memory context, which the
found data should be allocated on. All other data is allocated on the
current memory (typically the transaction's memory context). With this
functionality, a cache can pass its memory context to the scan, thus
avoiding taking on unnecessary memory allocations.
2018-06-22 16:45:07 +02: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
2de6b02c16 Add optimization to use HashAggregate more often
This optimization adds a HashAggregate plan to many group by queries.
In plain postgres, many time-series queries will not use the hash
aggregate because the planner will incorrectly assume that the number of
rows is much larger than it actually is and will use the less efficient
GroupAggregate instead of a HashAggregate to prevent running out of
memory.

The planner will assume a large number of rows because the statistics
planner for grouping assumes that the number of distinct items produced
by a function is the same as the number of distinct items going in. This
is not true for functions like time_bucket and date_trunc. This
optimization fixes the statistics and add the HashAggregate plan if
appropriate.

The statistics now rely on evaluating the spread of a variable and
dividing it by the interval in the time_bucket or date_trunc.  This is
still an overestimate of the total number of groups but is better than
before. A further improvement on this will be to evaluate the quals
(WHERE clauses) on the query to try to derive a tighter spread on the
variable. This is left to a future optimization.
2018-06-21 14:01:02 -04:00
Narek Galstyan
d1a05baac5 integrate code coverage through codecov.io 2018-06-21 13:03:35 -04:00
Rob Kiefer
cb9004c546 Remove include/ from non-Windows/FreeBSD builds
Windows and FreeBSD seem to need include/ to compile correctly
but on Ubuntu systems the header files in include/server/ and
include/ frequently get out of sync causing compile errors. This
change therefore only keeps that library included for Windows
and FreeBSD.
2018-06-21 12:13:07 -04:00
Matvey Arye
f765530e4b Remove superfluous parallel check
This check should not be necessary and causes problems
under Windows builds. So it is removed.
2018-06-20 11:18:39 -04:00
Narek Galstyan
4b4211fe94 Fix some external functions when setting a custom schema
Make sure internal references to timescale functions use the correct schema to refer to these functions. Fixes #554
2018-06-19 10:15:19 -04:00
Michael J. Freedman
3778bd733b Updated NOTICE from 440 Labs to Timescale 2018-06-08 11:16:42 -04:00
Matvey Arye
ad34d6f8f7 Bump pg version to test to 9.6.6
We hit a bug in 9.6.5 fixed in 9.6.6 by commit 77cd0dc.
Also changed extension is transitioning check to not palloc
anything. This is more efficient and probably has slightly
less side-effects on bugs like this.
2018-05-25 11:36:35 -04:00
Matvey Arye
b7257fc8f4 Optimize planning times when hypertables have many chunks
This planner optimization reduces planning times when a hypertable has many chunks.
It does this by expanding hypertable chunks manually, eliding the `expand_inherited_tables`
logic used by PG.

Slow planning time were previously seen because `expand_inherited_tables` expands all chunks of
a hypertable, without regard to constraints present in the query. Then, `get_relation_info` is
the called on all chunks before constraint exclusion. Getting the statistics an many chunks ends
up being expensive because RelationGetNumberOfBlocks has to open the file for each relation.
This gets even worse under high concurrency.

This logic solves this by expanding only the chunks needed to fulfil the query instead of all chunks.
In effect, it moves chunk exclusion up in the planning process. But, we actually don't use constraint
exclusion here, but rather a variant of range exclusion implemented
by HypertableRestrictInfo.
2018-05-25 11:36:35 -04:00
Rob Kiefer
c660fcd8ff Add hypertable_approximate_row_count convenience function
Getting an approximate row count for a hypertable involves getting
estimates for all of its chunks rather than just looking up a
single value in the catalog tables. This PR provides a convenience
function for doing the JOINs/summing.
2018-05-18 10:21:43 -04:00
Erik Nordström
9ce1576982 Fix a compilation issue on pre 9.6.3 versions
Macros that provide type assertion, like castNode() and lfirst_node()
were introduced in PG 9.6.3 and cannot be used if we want to support
the entire 9.6 series of releases. This change fixes usage of such
macros that was introduced as part of the 0.9.2 release of
TimescaleDB.
2018-05-09 19:09:04 +02:00
Rob Kiefer
02a8fc7e1a Prepare the repo for next development cycle 2018-05-07 11:09:19 -04:00
Rob Kiefer
ff3ab04bd9 Release 0.9.2 0.9.2 2018-05-04 13:41:39 -04:00
Erik Nordström
256b39491c Fix parsing of GrantRoleStmt
This corrects the way grantees are read from a GrantRoleStmt.
2018-05-04 14:59:34 +02:00
Erik Nordström
b78953b181 Fix datum conversion typo
Fixes a DatumGetInt64 that should really be a Int64GetDatum. Caused
segfaults on 32-bit (e.g., ARM) platforms.
2018-05-04 14:59:34 +02:00