1800 Commits

Author SHA1 Message Date
Dmitry Simonenko
d0c92dd433 Fix crash on SELECT WHERE NOT with empty table
Modify table state is not created with an empty tables, which lead
to NULL pointer evaluation.

Starting from PG12 the planner injects a gating plan node above
any node that has pseusdo-constant quals.

To fix this, we need to check for such a gating node and handle the case.
We could optionally prune the extra node, since there's already
such a node below ChunkDispatch.

Fixes #1883.
2020-05-15 12:47:27 +03:00
Ruslan Fomkin
74dcff5807 Run Windows regression tests on PG12
Change appveyor script to run regression tests against PG12 on
Windows. It is short term solution with official PG alpine image.
No EXEC_BACKEND is enabled.
2020-05-14 14:27:22 +02:00
Ruslan Fomkin
8ae8bd3848 Remove unused static declaration of a function
This removes warning of a function declared static but never defined.
2020-05-12 20:12:08 +02:00
Brian Rowe
d4c655fb2f Change ChunkAppend leader to use worker subplan
When running a parallel ChunkAppend query, the code would use a
subplan selection routine for the leader that would return an empty
slot unless it determined there were no workers started. While this
had the desired effect of forcing the workers to do the work of
evaluating the subnodes, returning an empty slot is not always safe.
In particular, Append nodes will interpret an empty slot as a sign
that a given subplan has completed, so a plan resulting in a
parallel MergeAppend under an Append node (very possible under a
UNION of hypertables) might fail to execute some or all of the
subplans.

This change modifies the ChunkAppend so that the leader uses the
same subplan function as the workers. This may result in the leader
being less responsive as it try to fetch a batch of results on its
own if no worker has any results yet. However, if this isn't the
desired behavior, PostgresQL already exposes a GUC option,
parallel_leader_participation, which will prevent the leader from
executing any subplans.
2020-05-12 08:45:24 -07:00
Erik Nordström
a95308e917 Run Windows builds and tests using GitHub Actions
Windows builds, for Debug and Release configurations, are now tested
using GitHub Actions. The build test covers all currently supported
PostgreSQL versions (9.6, 10, 11, 12) using a build matrix.

Currently, the TimescaleDB regression test suite is not run since it
requires a Windows-specific test client that we do not
support. Instead, the binaries are tested by doing a `CREATE
EXTENSION` to verify that they load and run without, e.g., missing
symbols or similar.

The test configuration is optimized for speed by using a cache for the
PostgreSQL installation. This avoids repeated downloads and
installations of PostgreSQL from EnterpriseDB's servers. But it also
means that we won't have a full installation on cache hits, which
means no running PostgreSQL service. This requires manual PostgreSQL
starts, which is what we want anyway since we need to preload our
extension.

It's anticipated that this build configuration can be extended to
produce release binaries in the future.
2020-05-12 14:50:46 +02:00
Erik Nordström
db80ca7136 Remove DEBUG logging in extension check
This change removes a `DEBUG1` level log message that was added to the
`ts_extension_is_loaded` check. The problem with this message is that
it is called very frequently, e.g., in planning, and it will flood the
output log.
2020-05-11 14:03:07 +02:00
Joshua Lockerman
647657404e Improve time_bucket_gapfill optimizations
This commit adds the optimizations we do for regular time bucket,
pushing down sort orders to the underlying time column, to time_bucket_gapfill.
This is made slightly more invasive by the fact that time_bucket_gapfill is
marked as VOLATILE (to prevent postgres from moving it in inappropriate ways).
We handle this by time_bucket_gapfill EC as not volatile, and letting the ususal
sort machinery do its job. This should be safe since we've already planned all
the per-relation paths and have installed the appropriate metadata to know we
will gapfill.
2020-05-11 13:40:56 +03:00
Erik Nordström
db1fc4083d Fix flaky hypertable cache plan test
The `plan_hypertable_cache` test used `current_date` to generate data,
which is inherently flaky since it can create a different number of
chunks depending on which date you start at. When the number of chunks
differ, the test output changes too.
2020-05-11 09:51:58 +02:00
gayyappan
c13ef6df97 Support WHERE and HAVING clauses for real time aggregation
Continuous aggregates with real time support did not propagate
WHERE and HAVING clauses to the direct query on the table.

Fixes #1860
2020-05-08 12:11:49 -04:00
Oleg Smirnov
b368563e3f Fix reorder policy job to skip compressed chunks
Reorder policy does not skip compressed chunks when selecting
next chunk to apply reordering. This causes an error in job
execution since it's not possible to reorder compressed chunks.
With this fix the job excludes compressed chunks from selection.

Fixes #1810
2020-05-08 09:58:01 -04:00
Sven Klemm
853e37efbf Fix hypertable detection in subqueries
When classify_relation is called for relations of subqueries it
would not be able to correctly classify the relation unless it
was already in cache. This patch changes classify_relation to
call get_hypertable without CACHE_FLAG_NOCREATE when the RangeTblEntry
has the inheritance flag set.
2020-05-07 18:21:07 +02:00
Ruslan Fomkin
5e1c4e614d Ignore Windows build files
Adds build output on Windows and CMake settings for VS to gitignore.
2020-05-07 15:39:09 +02:00
Mats Kindahl
730822127d Don't rely on timescaledb.restoring for upgrade
If a binary upgrade is in progress (when using `pg_upgrade`) the
per-database setting of `timescaledb.restoring` can be included in the
dump, which causes `pg_upgrade` to fail.

This commit fixes this by checking the global variable
`IsBinaryUpgrade` and not refreshing cache if we are in the middle of
doing a binary upgrade.

Fixes #1844
2020-05-07 07:30:33 +02:00
Ruslan Fomkin
2574e5a563 Add 12 folder to search for PG bin in CMake
CMake file is missing the path suffix for PG 12 when searching for
PostgreSQL binaries. This commit adds the path suffix for 12.
2020-05-05 15:45:21 +02:00
gayyappan
49a56f7826 Fix qual pushdown for compression
Operators used for qual pushdown for compressed chunks
should take the RHS expression's type into account.

Fixes #1855
2020-04-29 10:34:26 -04:00
Erik Nordström
28e9a443b3 Improve handling of "dropped" chunks
The internal chunk API is updated to avoid returning `Chunk` objects
that are marked `dropped=true` along with some refactoring, hardening,
and cleanup of the internal chunk APIs. In particular, apart from
being returned in a dropped state, chunks could also be returned in a
partial state (without all fields set, partial constraints,
etc.). None of this is allowed as of this change. Further, lock
handling was unclear when joining chunk metadata from different
catalog tables. This is made clear by having chunks built within
nested scan loops so that proper locks are held when joining in
additional metadata (such as constraints).

This change also fixes issues with dropped chunks that caused chunk
metadata to be processed many times instead of just once, leading to
potential bugs or bad performance.

In particular, since the introduction of the “dropped” flag, chunk
metadata can exist in two states: 1. `dropped=false`
2. `dropped=true`. When dropping chunks (e.g., via `drop_chunks`,
`DROP TABLE <chunk>`, or `DROP TABLE <hypertable>`) there are also two
modes of dropping: 1. DELETE row and 2. UPDATE row and SET
dropped=true.

The deletion mode and the current state of chunk lead to a
cross-product resulting in 4 cases when dropping/deleting a chunk:

1. DELETE row when dropped=false
2. DELETE row when dropped=true
3. UPDATE row when dropped=false
4. UPDATE row when dropped=true

Unfortunately, the code didn't distinguish between these cases. In
particular, case (4) should not be able to happen, but since it did it
lead to a recursing loop where an UPDATE created a new tuple that then
is recursed to in the same loop, and so on.

To fix this recursing loop and make the code for dropping chunks less
error prone, a number of assertions have been added, including some
new light-weight scan functions to access chunk information without
building a full-blown chunk.

This change also removes the need to provide the number of constraints
when scanning for chunks. This was really just a hint anyway, but this
is no longer needed since all constraints are joined in anyway.
2020-04-28 13:49:14 +02:00
Mats Kindahl
b34363edc2 Change lookup of clang-format version
The formatting requires `clang-format` version 7 or 8, but if a later
distro is used it will find a version that cannot be used and default
to using docker even if the user installs an earlier version of
`clang-format` in parallel with the default version.

This commit fixes this by looking for `clang-format-8` and
`clang-format-7` before `clang-format`.
2020-04-28 09:10:23 +02:00
gayyappan
52e23773dc Validate job time to avoid error thrown by scheduler
Trying to use an invalid time for a job raises an error.
This case should be checked  by the scheduler. Failure to
do so results in the scheduler being killed.
2020-04-27 16:08:12 -04:00
Erik Nordström
0e9461251b Silence various compiler warnings
This change fixes various compiler warnings that show up on different
compilers and platforms. In particular, MSVC is sensitive to functions
that do not return a value after throwing an error since it doesn't
realize that the code path is not reachable.
2020-04-27 15:02:18 +02:00
Mats Kindahl
7d78540a22 Fix segfault on COPY to hypertable
When copying from standard input the range table was not set up to
handle the constraints for the target table and instead is initialized
to null. In addition, the range table index was set to zero, causing an
underflow when executing the constraint check. This commit fixes this
by initializing the range table and setting the index correctly.

The code worked correctly for PG12, so the code is also refactored to
ensure that the range table and index is set the same way in all
versions.

Fixes #1840
2020-04-27 08:49:24 +02:00
Sven Klemm
0a7e9722f6 Fix hypertable expansion for UNION ALL
When doing a UNION ALL query between a hypertable and a regular
table the hypertable would not get expanded leading to
no data of the hypertable included in the resultset.
2020-04-24 16:01:05 +02:00
Ruslan Fomkin
966c34fdba Update build from source instructions for 1.7
PostgreSQL 12 is supported since 1.7, while 9.6 and 10 are deprecated.
This PR updates the building from source instruction with this change
and uses 1.7.0 in examples.
2020-04-22 19:15:14 +02:00
Mats Kindahl
685f8bf9f0 Enable clang-tidy
Adding a custom target `clang-tidy` that will run `run-clang-tidy` if
it is available and the compiler database is enabled. If the compiler
database is not enabled but `run-clang-tidy` is found, a warning will
be printed and the custom command will not be added.
2020-04-21 11:47:47 +02:00
Sven Klemm
5a6fd603e6 Add 1.7.0 to update test scripts
Due to the changes of the default view behaviour of continuous
aggregates we need a new testsuite for the update tests for 1.7.0

This patch also changes the update test for 9.6 and 10 to run on
cron and 11 and 12 on pull request.
2020-04-21 01:39:00 +02:00
Sven Klemm
8804b57cfb Move catalog missing column check into separate file 2020-04-21 01:39:00 +02:00
Sven Klemm
ed3eda2ceb Add missing ORDER BY clause to update test queries 2020-04-21 01:39:00 +02:00
Sven Klemm
d9bf54c604 Use OID const in cagg_watermark call
The view definition for the realtime aggregation union view
would use a INT Const as argument to cagg_watermark, but
the function argument is defined as OID leading to a cast being
inserted in a view definition restored from backup. This leads
to a difference between the original view definition and a view
definition from a restored view.
2020-04-21 01:39:00 +02:00
Mats Kindahl
8e94875d85 Define strerror() for Windows
The symbol `pgwin32_socket_strerror` was undefined on windows builds at
PG12 and later. This because the function was removed and instead
`pg_strerror` was introduced to be used on all platforms.

This commit fixes the issue by ensuring to use `pg_strerror` on PG12
and later, and `pgwin32_socket_strerror` on Windows builds before PG12.

Found using `clang-tidy`
2020-04-20 14:54:06 +02:00
Dmitry Simonenko
ed12257810 Improve cmake PostgreSQL version check
This change improves cmake check for PostgreSQL minor/patch versions
and makes it consistent with src/compat.h version check
2020-04-20 13:16:19 +03:00
Sven Klemm
5e678610bf Release 1.7.0
This release adds major new features and bugfixes since the 1.6.1 release.
We deem it moderate priority for upgrading.

This release adds the long-awaited support for PostgreSQL 12 to TimescaleDB.

This release also adds a new default behavior when querying continuous
aggregates that we call real-time aggregation. A query on a continuous
aggregate will now combine materialized data with recent data that has
yet to be materialized.

Note that only newly created continuous aggregates will have this
real-time query behavior, although it can be enabled on existing
continuous aggregates with a configuration setting as follows:

ALTER VIEW continuous_view_name SET (timescaledb.materialized_only=false);

This release also moves several data management lifecycle features
to the Community version of TimescaleDB (from Enterprise), including
data reordering and data retention policies.

**Major Features**
* #1456 Add support for PostgreSQL 12
* #1685 Add support for real-time aggregation on continuous aggregates

**Bugfixes**
* #1665 Add ignore_invalidation_older_than to timescaledb_information.continuous_aggregates view
* #1750 Handle undefined ignore_invalidation_older_than
* #1757 Restrict watermark to max for continuous aggregates
* #1769 Add rescan function to CompressChunkDml CustomScan node
* #1785 Fix last_run_success value in continuous_aggregate_stats view
* #1801 Include parallel leader in plan execution
* #1808 Fix ts_hypertable_get_all for compressed tables
* #1828 Ignore dropped chunks in compressed_chunk_stats

**Licensing changes**
* Reorder and policies around reorder and drop chunks are now
  accessible to community users, not just enterprise
* Gapfill functionality no longer warns about expired license

**Thanks**

* @t0k4rt for reporting an issue with parallel chunk append plans
* @alxndrdude for reporting an issue when trying to insert into compressed chunks
* @Olernov for reporting and fixing an issue with show_chunks and drop_chunks for compressed hypertables
* @mjb512 for reporting an issue with INSERTs in CTEs in cached plans
* @dmarsh19 for reporting and fixing an issue with dropped chunks in compressed_chunk_stats
2020-04-16 17:42:36 +02:00
Derek Marsh
88773323f4 Ignore dropped chunks in compressed_chunk_stats 2020-04-16 16:34:46 +02:00
Sven Klemm
57327b52c8 Update CHANGELOG 2020-04-16 11:06:21 +02:00
Mats Kindahl
1f37c1813f Fix null pointer deref in continuous aggregates
There is a potential null pointer dereference in that `raw_hypertable`
might be NULL when counting the number of continuous aggregates
attached. This commit fixes this by assuming that no continuous
aggregates are attached if `raw_hypertable` is NULL.

Found using `clang-tidy`.
2020-04-16 10:12:27 +02:00
Oleg Smirnov
e7f70e354e Fix ts_hypertable_get_all for compressed tables
When calling show_chunks or drop_chunks without specifying
a particular hypertable TimescaleDB iterates through all
existing hypertables and builds a list. While doing this
it adds the internal '_compressed_hypertable_*' tables
which leads to incorrect behaviour of
ts_chunk_get_chunks_in_time_range function. This fix
filters out the internal compressed tables while scanning
at ts_hypertable_get_all function.
2020-04-15 15:13:59 +02:00
Sven Klemm
be47dd0020 Simplify postgres version check 2020-04-15 12:07:19 +02:00
Sven Klemm
c5e983e422 Add test for INSERT in cached plans
This adds a test for INSERTs with cached plans. This test causes
a segfault before 1.7 but was fixed independently by the refactoring
of the INSERT path when adding PG12 support.
2020-04-15 12:07:19 +02:00
Michael J. Freedman
5b5240c00c Point to Timescale Code of Conduct
Create file that points to Timescale Code of Conduct on webpage
2020-04-15 11:03:13 +02:00
Ruslan Fomkin
3efc59e8ac Update change log with support for PG12 2020-04-14 23:12:15 +02:00
Ruslan Fomkin
fc92651738 Fix uninitialized warnings due to different scans
Fixes uninitialized warnings due to disjoint paths of scans.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
eaf0211012 Run coverity test on PG11 and PG12
Changes coverity test to run on PostgreSQL 11 and 12 instead of 9.6.
2020-04-14 23:12:15 +02:00
Mats Kindahl
7776062638 Remove pull of TSDB dev tools
The memory leak job pulls TSDB dev tools from bitbucket but only two
files from that repository are needed.

This commit copy the files from the `tsdb-dev-tools` repository, remove
the need to clone the repository, update the memory leak job to use
these files, and remove the two secrets containing the environment
variables `USR` and `PASSWORD`.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
bd9a755298 Remove unnecessary null check
Removes NULL check on variable, which has already been used. Fixes an
issue reported by coverity scan.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
5df7946e88 Make code logic clear for coverity test
Homogenizes condition for using correct scan method and resolving
coverity test complain.
2020-04-14 23:12:15 +02:00
Erik Nordström
dd753f2a3c Remove INSTEAD OF trigger in copy path
This change removes some place-holder code for supporting `INSTEAD OF`
triggers in the code that implements `COPY` support on
hypertables. The code was introduced when updating the copy path with
PostgreSQL 12 changes. However, such triggers are only supported on
views, and, since the hypertable copy path only inserts on chunks, the
code isn't needed.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
5cc91e34de Add CRON jobs for PG12
Adds several jobs to run on PG12 as they run on all other PG major
versions in CRON builds. Fixes 32-bits jobs.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
21d81ff602 Add test to contrast MATERIALIZED in WITH queries
PG12 by default optimizes CTEs from WITH clause with the rest of the
queries. MATERIALIZED is used in rowsecurity tests to produce the same
query plans as in PG11. This commit adds query plans tests with
default behavior, which is equivalent to NOT MATERIALIZED.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
a0d320ae2f Run CodeCov on PG12 for every PR
Switching mandatory CodeCov test from PG11.0 to PG12.0.
2020-04-14 23:12:15 +02:00
Ruslan Fomkin
6724b132bb Fix version comparison in CMake to work on 9.6.6
CMake version in PG image 9.6.6 doesn't support VERSION_GREATER_EQUAL
in its CMake version. Fixing with two separate conditions.
2020-04-14 23:12:15 +02:00
Sven Klemm
3b88e10d51 Add ordered_append test output for PG12
This patch also fixes one query in the ordered append test that had
non-deterministic output.
2020-04-14 23:12:15 +02:00
Sven Klemm
d31184b13a Fix constraint propagation for PG12
Since hypertable expansion happens later in PG12 the propagated
constraints will not be pushed down to the actual scans but stay
as join filter. This patch adds the constraint to baserestrictinfo
or as joinfilter depending on the constraint type.
2020-04-14 23:12:15 +02:00