1666 Commits

Author SHA1 Message Date
Erik Nordström
a4fb0cec3f Cleanup compression-related errors
This change fixes a number of typos and issues with inconsistent
formatting for compression-related code. A couple of other fixes for
variable names, etc. have also been applied.
2020-03-11 13:27:16 +01:00
Sven Klemm
3ae9d6ca18 Fix flaky gapfill test
The gapfill test assumed 1 day is always <= 24 hours which is not
true during DST switch leading to a failing test when run in that
time. This PR fixes the test to have reproducable output even
when run during DST switch.
2020-03-10 16:31:43 +01:00
David Kohn
ad97d266c0 Fix restoring/scheduler entrypoint to avoid BGW death
There was a race condition between the post_restore function
restarting the background worker and the setting of the
restoring flag to "off". If the worker started before the
change to the restoring flag had been committed, it would not
see the change and then die because the worker should exit
when the db is in a restoring state. This modifies the
post_restore function to use a restart instead of a start
so that it waits on the commit to start up. It also adds
logic to the entrypoint to reload config changes caused
by an `ALTER DATABASE SET` command. These changes are
normally only seen at connection startup but we have to
wait until after our lock on the modifying transaction is
released to know whether we should adopt them.
2020-03-10 11:02:18 -04:00
Sven Klemm
a19be04d7b Handle Sort nodes in ConstraintAwareAppend
When a MergeAppendPath has children that do not produce sorted
output a Sort node will be injected during plan creation, those
plans would trigger an error about invalid child nodes in
ConstraintAwareAppend. This PR makes ConstraintAwareAppend handle
those plans correctly.
2020-03-10 14:19:57 +01:00
gayyappan
d1700711cf Fix copy of continuous agg invalidation entries
When we copy the invalidation logs for individual continuous
aggregates, the lowest-value was globally overwritten. Fix this
so that the change is specific to a continuous aggregate.
This bug could result in missing invalidations.
2020-03-10 08:37:16 -04:00
Matvey Arye
bfab289121 Handle many BGW jobs better
This PR improves the scheduling of jobs when the number of
jobs exceeds the amount of background workers. Previously,
this was not a case the scheduler handled well.

The basic strategy we employ to handle this case better is to
use a job's next_start field to create a priority for jobs.
More concretely, jobs are scheduled in increasing order of
next_start. If the scheduler runs out of bgw's it waits to
until bgws become available and then retries again, also
in increasing next_start order.

The first change this PR implements is start jobs in order
of increasing next_start. We also make sure that if we run
out of BGWs, the scheduler will try again in START_RETRY_MS
(1 second by default).

This PR also needed to change the logic of what happens when
a job fails to start because BGWs have run out. Previously,
such jobs were marked as failed and their next_start was reset
using the regular post-failure backoff logic. But, this means
that a job looses its priority every time we run out of BGWs.
Thus, we changed this logic so that next_start does not change
when we encounter this situation.

There are actually 2 ways to run out of BGWs:
1) We run out of the timescale limit on BGWs - in this case
the job is simply put back into the scheduled state, and it
will be retried in START_RETRY_MS. The job is not marked
started or failed. This is the common error.

2) We run out of PostgreSQL workers. We won't know if this
failed until we try to start the worker, by which time the
job must be in the started state. Thus if we run into this
error we must mark the job as failed. But we don't change
next_start. To do this we create a new job result type
called JOB_FAILURE_TO_START.
2020-03-09 15:22:21 -04:00
Sven Klemm
99381fc2cc Adjust index predicate attnos when creating chunk index
When the index for a chunk was created the attnos for the index
predicate were not adjusted leading to insert errors on hypertables
with dropped columns that had indexes with predicates.
This PR adjust index predicate attnos when creating the chunk index
to match the chunk attno.
2020-03-09 16:57:49 +01:00
Mats Kindahl
d3966cead3 Remove usage of uninitilized value
Function `timescaledb_CopyFrom` created a variable `errcallback` to
save away the previous error callback and restoring it afterwards.
However, if `ccstate->cstate` was false, the variable would not be set
and the later restore of the error callback would use a random value.

This commit fixes the issue by initializing `errcallback` to all zeroes
and checking if a callback has been saved away before restoring it.
2020-03-09 15:01:56 +01:00
Mats Kindahl
18c9cf1c0b Fix typo of "continuous" 2020-03-09 09:02:51 +01:00
Brian Rowe
25eb98c0ec Prevent starting background workers with NOLOGIN
This change will check sql commands which start a background worker
on a hypertable to verify that the table owner has permission to
log into the database.  This is necessary, as background workers for
these commands will run with the permissions of the table owner, and
thus immediately fail if unable to log in.
2020-03-08 15:09:23 -07:00
Sven Klemm
030443a8e2 Fix compressing interval columns
When trying to compress a chunk that had a column of datatype
interval delta-delta compression would be selected for the column
but our delta-delta compression does not support interval and
would throw an errow when trying to compress a chunk.

This PR changes the compression selected for interval to dictionary
compression.
2020-03-06 21:44:31 +01:00
Sven Klemm
0cc22ad278 Stop background worker in tests
To make tests more stable and to remove some repeated code in the
tests this PR changes the test runner to stop background workers.
Individual tests that need background workers can still start them
and this PR will only stop background workers for the initial database
for the test, behaviour for additional databases created during the
tests will not change.
2020-03-06 15:27:53 +01:00
Sven Klemm
08c3d9015f Change log level for cagg materialization messages
The log level used for continuous aggregate materialization messages
was INFO which is for requested information. Since there is no way to
control the behaviour externally INFO is a suboptimal choice because
INFO messages cannot be easily suppressed leading to irreproducable
test output. Even though time can be mocked to make output consistent
this is only available in debug builds.

This patch changes the log level of those messages to LOG, so
clients can easily control the ouput by setting client_min_messages.
2020-03-06 01:09:08 +01:00
Michael J. Freedman
416cf13385 Clarify supported intervals in error msg
Error message used to specify that interval must be defined in terms
of days or smaller, which was confusing because we really meant any
fixed interval (e.g., weeks, days, hours, minutes, etc.), but not an
interval that is not of fixed duration (e.g., months or years).
2020-03-05 13:13:04 -05:00
gayyappan
7de3564d18 Catch elog errors in scheduler code
Direct function calls to PG functions can throw
errors for bad inputs. If these are not handled
when called by the scheduler, the process dies
and background workers cannot be scheduled.
2020-03-04 13:53:15 -05:00
gayyappan
b363e8a379 Fix cache invalidation code
Cache invalidation code does not call the
bgw invalidate cache callback when all caches
have to be invalidated.
2020-03-04 13:53:15 -05:00
Erik Nordström
84f0c8977e Fix incorrect chunk exclusion and broken test
This change fixes the `plan_expand_hypertable` test, which was broken
and never ran the output comparison due to prematurely ending in an
uncaught error. The test appeared to succeeded, however, since also
the broken test "expected" files were committed to the repo.

Fixing the test revealed that the query output with our optimizations
enabled is incorrect for outer joins (i.e., the output from the query
differed from regular PostgreSQL). Restriction clauses were too
aggressively pushed down to outer relations, leading to chunk
exclusion when it shouldn't happen. This incorrect behavior has also
been fixed.
2020-03-03 17:07:37 +01:00
Michael J. Freedman
8d81a83717 Update copyright year to 2020 2020-02-29 15:38:36 -05:00
gayyappan
91fe723d3a Drop chunks from materialized hypertables
Add support for dropping chunks from materialized
hypertables. drop_chunks_policy can now be set up
for materialized hypertables.
2020-02-26 11:50:58 -05:00
Sven Klemm
f49d00c4ec Remove plan costs from test output
Since planning costs are not stable across platforms they should not
be included in test output.
2020-02-26 09:03:40 +01:00
gayyappan
ca9363af8b Fix bad plan for materialization
REFRESH MATERIALIZED VIEW statements sometimes crash
because the generated plan has a HashAgg node
instead of a Partial Aggregate node when executing
INSERT INTO <materialization_table>
       SELECT * FROM <view>

Where the view stmt itself is along these lines
SELECT time_bucket('1 day'::interval, cpu."time") ,
 ......
 _timescaledb_internal.partialize_agg(avg(...))
FROM <table>
2020-02-24 15:27:11 -05:00
Erik Nordström
9da50cc686 Move enterprise features to community
As of this change, a number of enterprise features are accessible to
community users. These features include:

* reorder
* policies around reorder and drop chunks

The move chunks feature is still covered by enterprise. Gapfill no
longer warns about expired enterprise license.

Tests have been updated to reflect these changes.
2020-02-20 17:08:03 +01:00
Lacey Butler
66f47c0857 Update README with addt resources, build instructions to separate file
This commit updates the README with updated resources, including Timescale
Cloud, new support options, release notes, and others. For readability, it
also moves instructions for building from source to a separate readme file.
2020-02-18 22:27:44 -05:00
gayyappan
8864239187 Fix segment_by var for decompress chunk node
Fix order by queries on compressed hypertables that
have char segment by column.
The segment by var column for decompressed chunks should be
created after setting the typmod and collation ids. Otherwise, we
get failures with char datatypes while decompressing.

Fixes #1650
2020-02-14 23:30:12 -05:00
gayyappan
565cca795a Support disabling compression when foreign keys are present
Fix failure with disabling compression when no
compressed chunks are present and the table has foreign
key constraints
2020-02-14 08:54:58 -05:00
gayyappan
2702140fa3 Cannot add dimension if table has empty chunks
add_dimension should fail when table has no
data but still has empty chunks.
Fixes #1623
2020-02-10 10:47:23 -05:00
Mats Kindahl
1880196ab4 Fix crash when interrupting create_hypertable
When doing a migrate of table data to a hypertable during a call of
`create_hypertable`, any error (including an interrupt signal) would
cause the signal handling to call `CopyFromErrorCallback` which would
read garbage data because a heap scan descriptor is read as if it was a
`CopyState` structure.

This commit fixes that by not adding a new context to the error context
stack when migrating data, which will ensure that the error context
strack does not contain garbage data.

Fixes #1651
2020-02-06 21:42:10 +01:00
Joshua Lockerman
df0acb161e Fix GapFill with ReScan
The GapFill node was not fully reset on a ReScan, so if there was a
GapFill within a NestedLoop, only the first iteration would return
results. This commit fixes this issues.
2020-02-05 14:50:10 -05:00
Mike Freedman
0ae37ba864 Small grammar nits to CHANGELOG 2020-02-05 10:02:38 +01:00
gayyappan
a2629cbff2 Add ignore_invalidation_older_than to view
Add ignore_invalidation_older_than parameter to
timescaledb_information.continuous_aggregates view

Fixes #1664
2020-02-03 11:31:12 -05:00
Ruslan Fomkin
4dc0693d1f Unify error message if hypertable not found
Refactors multiple implementations of finding hypertables in cache
and failing with different error messages if not found. The
implementations are replaced with calling functions, which encapsulate
a single error message. This provides the unified error message and
removes need for copy-paste.
2020-01-29 08:10:27 +01:00
gayyappan
b1b840f00e Use timescaledb prefix for compression errors
Modify compression parameter related error messages
to make them consistent.
2020-01-28 09:08:58 -05:00
gayyappan
783c8e80ea Drop chunks for materialized hypertable
When drop_chunks is called with cascade_to_materialization = true,
 the materialized data is deleted from the materialization
hypertable, but the chunks are not dropped. This fix drops chunks
if possible and deletes the data only if the materialized chunk
cannot be dropped (which is the case if the materialzied chunk
contains data from multiple raw chunks and some of the raw chunks
are not dropped).

Fixes #1644
2020-01-27 15:27:50 -05:00
Sven Klemm
8f2d6b1d2f Increase wait time for bgw tests
TEST_SPINWAIT_ITERS is used as maximum number of iterations to wait
for background worker results. Each iteration has a 0.1 second sleep
so a setting of 10 makes the test wait 1 second for the desired result.
This PR changes the iterations to 100 to wait at most 10 seconds
which should help with some flaky bgw tests.
2020-01-23 14:07:19 +01:00
Erik Nordström
ab5d06245f Add CODEOWNERS file to auto-assign reviewers
A `CODEOWNERS` file allows assigning default reviewers for a branch,
obviating the need to add reviewers manually.
2020-01-23 13:16:20 +01:00
Sven Klemm
f298ff0079 Exclude costs from test query plans
The continuous aggs query test included costs for the query plans
in the test output leading to flaky tests. This PR removes costs
from plan output.
2020-01-20 15:20:03 +01:00
Sven Klemm
442a173ad6 Add 1.5.1 and 1.6.0 to update test scripts 2020-01-20 14:36:22 +01:00
Sven Klemm
bae083823d Remove -Wdeclaration-after-statement from PG_CFLAGS
Postgres CFLAGS includes -Wdeclaration-after-statement which leads
to problems when compiling with -Werror since we aim for C99 and allow
that so we strip this flag from PG_CFLAGS before adding postgres flags
to our own
2020-01-17 12:47:05 +01:00
Mats Kindahl
38654b2158 Print notice for COPY TO on hypertable
When using `COPY TO` on a hypertable (which copies from the hypertable
to some other destination), nothing will be printed and nothing will be
copied. Since this can be potentially confusing for users, this commit
print a notice when an attempt is made to copy from a hypertable
directly (not using a query) to some other destination.
2020-01-16 13:19:08 +01:00
Sven Klemm
2728658a0e Release 1.6.0
This release adds major new features and bugfixes since the 1.5.1 release.
We deem it moderate priority for upgrading.

The major new feature in this release allows users to keep the aggregated
data in a continuous aggregate while dropping the raw data with drop_chunks.
This allows users to save storage by keeping only the aggregates.

The semantics of the refresh_lag parameter for continuous aggregates has
been changed to be relative to the current timestamp instead of the maximum
value in the table. This change requires that an integer_now func be set on
hypertables with integer-based time columns to use continuous aggregates on
this table.

We added a timescaledb.ignore_invalidation_older_than parameter for continuous
aggregatess. This parameter accept a time-interval (e.g. 1 month). if set,
it limits the amount of time for which to process invalidation. Thus, if
timescaledb.ignore_invalidation_older_than = '1 month', then any modifications
for data older than 1 month from the current timestamp at modification time may
not cause continuous aggregate to be updated. This limits the amount of work
that a backfill can trigger. By default, all invalidations are processed.

**Major Features**
* #1589 Allow drop_chunks while keeping continuous aggregates

**Minor Features**
* #1568 Add ignore_invalidation_older_than option to continuous aggs
* #1575 Reorder group-by clause for continuous aggregates
* #1592 Improve continuous agg user messages

**Bugfixes**
* #1565 Fix partial select query for continuous aggregate
* #1591 Fix locf treat_null_as_missing option
* #1594 Fix error in compression constraint check
* #1603 Add join info to compressed chunk
* #1606 Fix constify params during runtime exclusion
* #1607 Delete compression policy when drop hypertable
* #1608 Add jobs to timescaledb_information.policy_stats
* #1609 Fix bug with parent table in decompression
* #1624 Fix drop_chunks for ApacheOnly
* #1632 Check for NULL before dereferencing variable

**Thanks**
* @optijon for reporting an issue with locf treat_null_as_missing option
* @acarrera42 for reporting an issue with constify params during runtime exclusion
* @ChristopherZellermann for reporting an issue with the compression constraint check
* @SimonDelamare for reporting an issue with joining hypertables with compression
2020-01-15 18:20:30 +01:00
Sven Klemm
6590858cd2 Ignore parallel test result in 32 bit tests
The worker assignment for parallel queries behaves differently
from the 64 bit builds leading to differences in plan output
and failing tests. This commit ignores the results of the parallel
tests for 32 bit builds.
2020-01-15 18:20:30 +01:00
Sven Klemm
8f25517d4b Check for NULL before dereferencing variable
Move the NULL-check in continuous_agg_execute_materialization before
the first dereferencing of the variable.
2020-01-15 15:52:38 +01:00
Sven Klemm
59c04767a6 Fix tests with drop_chunks for ApacheOnly
The drop_chunks function would call continuous_agg_drop_chunks_by_chunk_id
even for hypertables without continuous aggregates leading to license
errors when compiled as Apache-only. This PR skips the call when the
hypertable has no continuous aggregates.
2020-01-14 10:37:07 +01:00
Matvey Arye
94f3cff709 Fix bug with parent table in decompression
Fix bug with transparent decompression getting the
hypertable parent table. This can happen with self-referencing
updates.

Fixes #1555
2020-01-07 17:33:01 -05:00
Matvey Arye
599a877854 Fix constify params during runtime exclusion
Descending into subplans during constification of params
seems unsafe and has led to bugs. Turning this off seems
to be safe and not regress any tested optimizations.

In the future we may want to find a way to optimize this
case as well.

Fixes #1598.
2020-01-07 14:55:02 -05:00
Erik Nordström
f8d4e7f641 Fix crash when partializing agg with HAVING
This change fixes an assertion-based crash that happened when using
the `partialize_agg` function together with HAVING clauses. For
instance,

```
SELECT time_bucket('1 day', time), device,
__timescaledb_internal.partialize_agg(avg(temp))
GROUP BY 1, 2
HAVING avg(temp) > 3;
```

would crash because the HAVING clause's aggregate didn't have its
`Aggref` node set to partial aggregate mode.

Regular partial aggregations executed by the planner (i.e., those not
induced by the `partialize_agg` function) have their HAVING aggs
transparently moved to the target list during planning so that the
finalize node can use it when applying the final filter on the
resulting groups. However, it doesn't make much sense to transparently
do that when partializing with `partialize_agg` since it would be odd
to return more columns than requested by the user. Therefore, the
caller would have to do that manually. This, in fact, is also done
when materializing continuous aggregates.

For this reason, HAVING clauses with `partialize_agg` are blocked,
except in cases where the planner transparently reduces the HAVING
expression to a simple filter (e.g., `HAVING device > 3`).

Apart from fixing this issue, this change also refectors some of the
related code and adds tests for some error cases.
2020-01-07 15:52:28 +01:00
Matvey Arye
e44be9c03a Add jobs to timescaledb_information.policy_stats
Add the compression and continuous aggs job types to the
timescaledb_information.policy_stats view. It is a bug
that it wasn't there before.
2020-01-03 14:18:13 -05:00
Matvey Arye
d52b48e0c3 Delete compression policy when drop hypertable
Previously we could have a dangling policy and job referring
to a now-dropped hypertable.

We also block changing the compression options if a policy exists.

Fixes #1570
2020-01-02 16:40:59 -05:00
Matvey Arye
ef77c2ace8 Improve continuous agg user messages
Switch from using internal timestamps to more user-friendly
timestamps in our log messages and clean up some messages.
2020-01-02 15:49:04 -05:00
Matvey Arye
6122e08fcb Fix error in compression constraint check
The constraint check previously assumed that the col_meta
offset for a column was equal to that columns attribute
offset. This is incorrect in the presence of dropped columns.

Fixed to match on column names.

Fixes #1590
2020-01-02 13:56:46 -05:00