2839 Commits

Author SHA1 Message Date
gayyappan
93be235d33 Support for inserts into compressed hypertables
Add CompressRowSingleState .
This has functions to compress a single row.
2021-05-24 18:03:47 -04:00
gayyappan
45462c775e Fix hypertable_chunk_local_size view
The view uses cached information from compression_chunk_size to
report the size of compressed chunks. Since compressed chunks
can be modified, we call pg_relation_size on the compressed chunk
while reporting the size

The view also incorrectly used the hypertable's reltoastrelid to
calculate toast bytes. It has been changed to use the chunk's
reltoastrelid.
2021-05-24 11:52:03 -04:00
Sven Klemm
4eff5b17c3 Explicitly install clang-9 in coverity workflow
GitHub only has the last 3 clang versions installed by default in
the virtual environment and no longer installed clang-9 when they
added clang-12. Since we need clang-9 to build postgres with
llvm support we need to explicitly install the required package.

https://github.com/actions/virtual-environments/pull/3381
2021-05-24 15:10:12 +02:00
Mats Kindahl
58b1eb83d4 Add TimescaleNode subclasses for TAP Testing
Use subclassing to inherit from `PostgresNode` and create a hierarchy
containing `AccessNode` and `DataNode` to simplify creating tests with
multiple nodes.

Also, two new functions are added:

`TimescaleNode::create`: Creates the new node by calling
`get_new_node`, `init` and `start` in that order.

`AccessNode::add_data_node`: Adds a new data node to the access node.

Also rewrite the test to use the new hierarchy.
2021-05-21 13:20:24 +02:00
Mats Kindahl
551ac56937 Add Perl code check GitHub action
Add a run of `perltidy` to make sure that all the Perl code is
correctly formatted. Also fix the formatting of one file that did not
follow the style in `scripts/perltidyrc`.
2021-05-21 12:50:51 +02:00
gayyappan
80b915d001 Fix segmentation fault due to incorrect call to chunk_scan_internal
chunk_scan_internal is called with 2 callback functions, a
filter function and a tuple_found function that
are invoked with the same argument. ts_chunk_set_compressed
and ts_chunk_clear_compressed use chunk_tuple_dropped_filter
but do not pass in the required ChunkStubScanCtx* as argument.
Instead an argument of type int* is passed in. This causes
 a segmentation fault.

Add a new chunk filter function that is compatible with
the tuple_found function used by ts_chunk_clear_compressed_chunk
and ts_chunk_set_compressed_chunk
Fixes #3158
2021-05-20 16:22:14 -04:00
Sven Klemm
99ffe8fd6c Fix blocking triggers with transition tables
Block creation of triggers with transition tables on trigger creation
instead of erroring out when a chunk is created.

Fixes #3234
2021-05-20 21:55:26 +02:00
Sven Klemm
3e28f10600 Fix constraint trigger on hypertables
When creating a constraint trigger on a hypertable the command
succeeds and the constraint trigger works correctly for existing
chunks but any chunk creation after that would fail with an
error, because the constraint trigger was treated like a normal
constraint. But since pg_get_constraintdef does not return a SQL
command for constraint triggers the corresponding command that was
created would throw an error.

Fixes #3235
2021-05-20 21:26:47 +02:00
Sven Klemm
72ed3a81c5 Explicitly install clang-9 in CI ubuntu images
GitHub removed default installation of clang-9 from the ubuntu
images but those are required to build postgres with llvm so we have
to explicitly install the required packages.

https://github.com/actions/virtual-environments/pull/3381
2021-05-20 21:26:47 +02:00
Sven Klemm
eef71fdfb1 Replace StrNCpy with strlcpy
PG14 removes StrNCpy and some Name helper functions.

https://github.com/postgres/postgres/commit/1784f278a6
2021-05-20 08:54:54 +02:00
Sven Klemm
4f72ab0377 Fix assertion failure in decompress_chunk_plan_create
decompress_chunk_plan_create used get_actual_clauses to extract
RestrictInfo clauses and adds them as quals. This function is only
supposed to be used when none of the RestrictInfos are pseudoconstant
leading to an assertion failure when the query has pseudoconstant
quals.

Fixes #3241
2021-05-19 19:02:28 +02:00
Erik Nordström
600d324898 Use correct lock mode when updating chunk
Use RowExclusive lock instead of AccessShareLock when updating a
chunk's metadata.
2021-05-19 13:29:59 +02:00
Nikhil
4efa51cd8d Add tap tests infrastructure support
The TAP testing PG framework meets our requirements for doing
multinode/stand-alone-binaries testing for scenarios which need
individual multiple PG instances (multi-node testing is a prime
example).

This commit adds the necessary wrappers to allow the use of the TAP
testing framework in timescale code base. The README in "test/perl"
directory gives a fair idea of how to write tap tests. A simple tap
test has been added to provide a reference point for developers to
write new ones.

One can go to "build/tsl/test" and invoke "make checkprove" to see
the tap test in action.

Also includes changes for enabling github CI to run these taptests by
installing the requisite dependencies.

Includes changes to license checking scripts to handle new *.pl and
*.pm files.

Also added a new scripts/perltidyrc to aid in formatting of these
files.
2021-05-19 13:49:02 +05:30
Markos Fountoulakis
adde40f548 Use chunk status for is_compressed field in view
The timescaledb_information.chunks view used to return NULL in the
is_compressed field for distributed chunks. This changes the view to
always return true or false, depending on the chunk status flags in the
Access Node. This is a hint and cannot be used as a source of truth for
the compression state of the actual chunks in the Data Nodes.
2021-05-19 10:57:24 +03:00
Sven Klemm
45384357bd Bump postgres versions used in CI
Change CI tests to run against pg 11.12, 12.7 and 13.3.

The latest postgres versions adjusts the event_trigger test to
output the list of currently defined event triggers making the
test output different when timescaledb is installed since we
define our own event triggers. Due to this change we have to
ignore the result of this test in our CI.

https://github.com/postgres/postgres/commit/f3c45378
2021-05-18 16:22:23 +02:00
Mats Kindahl
b788168e59 Propagate grants to compressed hypertable
Grants and revokes where not propagated to compressed hypertables, if
the hypertable had a compressed hypertable, meaning that `pg_dump` and
`pg_restore` would not be able to dump nor restore the compressed part
of a hypertable unless they were owners and/or was a superuser.

This commit fixes this by propagating grants and revokes on a
hypertable to the associated compressed hypertable, if one exists,
which will then include the compressed hypertable and the associated
chunks in the grant and revoke execution.

It also adds code to fix the permissions of compressed hypertables and
all associated chunks in an update and adds an update test to check
that the permissions match.

Fixes #3209
2021-05-13 08:43:07 +02:00
Erik Nordström
f6967b349f Use COPY when executing distributed INSERTs
A new custom plan/executor node is added that implements distributed
INSERT using COPY in the backend (between access node and data
nodes). COPY is significantly faster than the existing method that
sets up prepared INSERT statements on each data node. With COPY,
tuples are streamed to data nodes instead of batching them in order to
"fill" a configured prepared statement. A COPY also avoids the
overhead of having to plan the statement on each data node.

Using COPY doesn't work in all situations, however. Neither ON
CONFLICT nor RETURNING clauses work since COPY lacks support for
them. Still, RETURNING is possible if one knows that the tuples aren't
going to be modified by, e.g., a trigger. When tuples aren't modified,
one can return the original tuples on the access node.

In order to implement the new custom node, some refactoring has been
performed to the distributed COPY code. The basic COPY support
functions have been moved to the connection module so that switching
in and out of COPY_IN mode is part of the core connection
handling. This allows other parts of the code to manage the connection
mode, which is necessary when, e.g., creating a remote chunk. To
create a chunk, the connection needs to be switched out of COPY_IN
mode so that regular SQL statements can be executed again.

Partial fix for #3025.
2021-05-12 16:14:28 +02:00
Erik Nordström
39b9457540 Add trigger support on distributed hypertables
This change makes it possible to create and use triggers on
distributed hypertables. The DDL for `CREATE TRIGGER` and `DROP
TRIGGER` are now forwarded to data nodes. Previously, `CREATE TRIGGER`
worked, but didn't forward the DDL command.

Note that triggers exist only on the data nodes and on the data node's
root hypertable. Triggers need to execute on the data nodes where data
is stored; in particular, row-based "before" triggers might modify the
tuple. On the access node, chunks are foreign tables and such tables
do not support triggers.

Also note that statement-level triggers execute once on each node
involved, including the access node. So, if, e.g., two rows are
inserted into two different data nodes in the same statement, a
statement-level insert trigger will fire once on the access node and
once on each data node.

An issue with `RETURNING` handling for distributed insert is also
fixed (in the `DataNodeDispatch` executor node). The fix ensures that
the modified tuple is returned when a trigger modifies the tuple on a
data node.

Fixes #3201
2021-05-12 12:08:44 +02:00
Fabrízio de Royes Mello
5606bf8883 Added Postgres 13 prerequisites for compilation
Issue #2779 introduced support for PostgreSQL 13
2021-05-11 04:35:31 +02:00
Markos Fountoulakis
bc740a32fb Add distributed hypertable compression policies
Add support for compression policies on Access Nodes. Extend the
compress_chunk() function to maintain compression state per chunk
on the Access Node.
2021-05-07 16:50:12 +03:00
Erik Nordström
422440a2de Add GENERATED column support on distributed hypertables
Add support for deparsing `GENERATED` columns when creating
distributed hypertables, including support for generating values
"on-the-fly" when a `RETURNING` clause is used with an `INSERT`
statement.

Previously, using generated columns on a hypertable led to errors or
had unpredictible results.
2021-05-07 13:13:38 +02:00
Michael J. Freedman
490e940587 Fix accidental misused acronym for Data Manipulation Language
In the definition of "Timescale Data Manipulation Interfaces", the description of
Data Manipulation Language was accidentally and erroneously given the acronym
"DDL" as a parenthetical, when it should have been (and was meant to be) given
the proper acronym of "DML". No intent is changed with this correction.
2021-05-07 08:33:53 +02:00
Erik Nordström
2e444849fb Clean up cross-module function definitions
Use the `PGFunction` type on all PostgreSQL function definitions when
defining cross-module (TSL) functions.
2021-05-06 16:34:04 +02:00
Mats Kindahl
ec65866890 Add 2.2.1 to update test scripts
The update tests scripts for PG11, PG12, and PG13 are updated to
include 2.2.1.
2021-05-06 15:19:01 +02:00
Mats Kindahl
e7daf74d40 Release 2.2.1
This maintenance release contains bugfixes since the 2.2.0 release. We
deem it high priority for upgrading.

This release extends Skip Scan to multinode by enabling the pushdown
of `DISTINCT` to data nodes. It also fixes a number of bugs in the
implementation of Skip Scan, in distributed hypertables, in creation
of indexes, in compression, and in policies.

**Features**
* #3113 Pushdown "SELECT DISTINCT" in multi-node to allow use of Skip
  Scan

**Bugfixes**
* #3101 Use commit date in `get_git_commit()`
* #3102 Fix `REINDEX TABLE` for distributed hypertables
* #3104 Fix use after free in `add_reorder_policy`
* #3106 Fix use after free in `chunk_api_get_chunk_stats`
* #3109 Copy recreated object permissions on update
* #3111 Fix `CMAKE_BUILD_TYPE` check
* #3112 Use `%u` to format Oid instead of `%d`
* #3118 Fix use after free in cache
* #3123 Fix crash while using `REINDEX TABLE CONCURRENTLY`
* #3135 Fix SkipScan path generation in `DISTINCT` queries
  with expressions
* #3146 Fix SkipScan for IndexPaths without pathkeys
* #3147 Skip ChunkAppend if AppendPath has no children
* #3148 Make `SELECT DISTINCT` handle non-var targetlists
* #3151 Fix `fdw_relinfo_get` assertion failure on `DELETE`
* #3155 Inherit `CFLAGS` from PostgreSQL
* #3169 Fix incorrect type cast in compression policy
* #3183 Fix segfault in calculate_chunk_interval
* #3185 Fix wrong datatype in integer based retention policy

**Thanks**
* @Dead2, @dv8472 and @einsibjarni for reporting an issue with
  multinode queries and views
* @hperez75 for reporting an issue with Skip Scan
* @nathanloisel for reporting an issue with compression on hypertables
  with integer-based timestamps
* @xin-hedera for fixing an issue with compression on hypertables with
  integer-based timestamps
2021-05-05 08:50:39 +02:00
Sven Klemm
86bf122479 Fix segfault in calculate_chunk_interval
Block calling calculate_chunk_interval on distributed hypertables
to prevent segfault when finding min and max as distributed chunks
have no tableam since they are foreign tables.
2021-05-04 15:14:09 +02:00
Sven Klemm
d17e084705 Fix wrong datatype in integer based retention policy
When reading the configuration for retention policy of integer
based hypertables int32 was used instead of int64.

Fixes #2877
2021-05-04 14:54:17 +02:00
James Winegar
04328b51c9 Fix spelling error in time_bucket error message 2021-05-03 00:35:56 +02:00
Nikhil
6b2b4d936a Add a few miscellaneous code fixes
1) Quell a compiler warning about uninitialized use of "varno"
variable.

2) Fix ts_chunk_get_by_name to return early if rogue schema/table args
are passed in.
2021-04-29 17:41:43 +05:30
Sven Klemm
ff5f6056c3 Add changelog entry for #3169 2021-04-29 07:29:26 +02:00
Xin Li
37370908c8 Fix incorrect type cast in compression policy
Fix incorrect type cast when reading int64 compress after from compression policy

Fixes #3009

Signed-off-by: Xin Li <xin.li@hedera.com>
2021-04-29 07:29:26 +02:00
Sven Klemm
1499ed4f20 Add function to set chunk status
Add 2 helper functions to modify status of a chunk
ts_chunk_add_status(Chunk *chunk, int status);
ts_chunk_set_status(Chunk *chunk, int status);
2021-04-28 22:01:03 +02:00
Nikhil
1f0c591c88 Use no-unused-command-line-argument flag
We started inheriting CFLAGS from postgresql via ba51adc3. Although we
remove "-W" flags, we still end up accepting other options like "-L"
from postgresql. This can cause compilation to fail with compilers
like Clang which enable reporting of errors on unused command line
arguments.

This patch conditionally adds -Wno-unused-command-line-argument in
our cmake files to avoid unhelpful unused-command-line-argument
warnings/errors.
2021-04-28 17:31:33 +05:30
Sven Klemm
0a39e2ebff Add coredump support for 32bit ci runs
This patch adds coredump support for the 32bit CI runs. This patch
switches 32bit run to the debian base image and install postgres
from PGDG instead of using the alpine image so we don't have to
compile postgres ourselves and can just install the debugsymbol
package for postgres.
2021-04-27 12:15:07 +02:00
gayyappan
e0bff859e3 Add chunk_status column to catalog chunk table
Add a new column chunk_status to _timescaledb_catalog.chunk.
2021-04-26 16:26:47 -04:00
Sven Klemm
ba51adc3bd Inherit CFLAGS from postgresql
There are quite a few compiler flags that need to be identical
between postgresql and timescaledb otherwise there will be
seemingly unexplainable failures during execution.
We inherit all CFLAGS from postgresql except those starting
with -W as we have our own set of warning options.
2021-04-26 17:26:28 +02:00
Sven Klemm
0de39140c3 Fix fdw_relinfo_get assertion failure on DELETE
The code in fdw_relinfo_get assumed rel->fdw_private and
rel->fdw_private->fdw_relation_info were always allocated
which is not true for DELETEs for instance.
2021-04-26 14:43:32 +02:00
Mats Kindahl
aeb107659b Copy recreated object permissions on update
Tables, indexes, and sequences that are recreated as part of an update
does not propagate permissions to the recreated object. This commit
fixes that by saving away the permissions in `pg_class` temporarily and
then copying them back into the `pg_class` table.

If internal objects are created or re-created, they get the wrong
initial privileges, which result in privileges not being dumped when
using `pg_dump`. Save away the privileges before starting the update
and restore them afterwards to make sure that the privileges are
maintained over the update.

For new objects, we use the initial privileges of the `chunk` metadata
table, which should always have correct initial privileges.

Fixes #3078
2021-04-26 08:36:57 +02:00
Nikhil
255b5715ba Fix flaky dist_hypertable test
The chunks of the datanodes seem to contain very few rows. That can
cause PostgreSQL to choose a SeqScan plan in some cases. Add a few
more rows to make it choose IndexScan all of the time.
2021-04-26 10:46:33 +05:30
Sven Klemm
ec733de130 Add GitHub action for posting daily CI summary
This patch adds a GitHub action that posts all failed CI jobs in
the last 24 hours with link to the failed job.
2021-04-25 16:13:31 +02:00
Sven Klemm
85cb9aa722 Remove slack notification from individual workflows
The patch removes the Slack notification of individual workflows
in favor of the Slack summary message
2021-04-25 16:13:31 +02:00
Mats Kindahl
e7ffedbec7 Add update smoke test script
The update smoke test script can be used to test that an extension
works correctly. It will run the normal update tests, but do it against
a single server.

It also makes some minor refactorings of the update tests to make it
possible to run the tests against different versions of the server and
also support the smoke tests where some features cannot be tested.
2021-04-23 09:57:41 +02:00
Nikhil
a3d8f9fecd Make SELECT DISTINCT handle non-var targetlists
The current SELECT DISTINCT pushdown code assumed that the targetlist
will always contain references to column attributes of the target
table.

So, even a simple "SELECT DISTINCT 1 from table;" causes a segmentation
fault because the "varno" field is not assigned. Fix this oversight.

Issue reported by @svenklemm

Fixes timescale/timescaledb-private#920
2021-04-22 20:19:35 +05:30
Sven Klemm
fc3f8305e3 Skip ChunkAppend if AppendPath has no children
Since postgres has optimizations for Append paths without children
we do not replace those paths with ChunkAppend. While this will
prevent ChunkAppendPaths without children during planning, in the
executor it is still possible for ChunkAppend to have no children
as run-time exclusion may remove all of them.
2021-04-22 15:17:09 +02:00
Sven Klemm
8fd4ecbdd9 Fix SkipScan for IndexPaths without pathkeys
The SkipScan code assumed IndexPaths on ordered indexes always
have pathkeys which is not true when the pathkeys are not useful
for the query, leading to a segfault for those queries.
2021-04-22 14:06:25 +02:00
Sven Klemm
242919bc49 Fix flaky pg_dump test
This patch fixes the flaky pg_dump test by switching off the current
database before using it as template. It also disables background
job scheduling instead of stopping them before creating the new
database as stopping bgw jobs might not happen immediately.

Fixes #2847
2021-04-21 15:28:26 +02:00
Ruslan Fomkin
4e86a12ceb Run code style regression test on all PRs
Checking code formatting and other simple code style test is good to
perform on PRs to feature branches, not only the master branch. This
commit removes the limitation to perform tests only on PR to the
master.
2021-04-21 13:23:23 +02:00
Ruslan Fomkin
507b5e5c15 Ignore generated SQL test files from templates
`index` test was moved into SQL test template in #3123 and
`generated_columns` - in #2927. They are added to relevant gitignore.
2021-04-21 12:26:19 +02:00
Nikhil
425cdd16e4 Add "SELECT DISTINCT" pushdown in multi-node
Construct "SELECT DISTINCT target_list" or "SELECT DISTINCT ON (col1,
col..) target_list" statement to push down the DISTINCT clause to the
remote side.

We only allow references to basic "Vars" or constants in the DISTINCT
exprs

So, "SELECT DISTINCT col1" is fine but "SELECT DISTINCT 2*col1" is not.

"SELECT DISTINCT col1, 'const1', NULL, col2" which is a mix of column
references and constants is also supported. Everything else is not
supported.

This pushdown also needs to work when
timescaledb.enable_per_data_node_queries is disabled.

All existing test cases in which "SELECT DISTINCT" is now being pushed
down have been modified. New test cases have been added to check that
the remote side uses "Skip Scans" as is suitable in some cases.
2021-04-21 12:53:53 +05:30
Sven Klemm
202cceee56 Increase number of connections for tsl tests
Since we run 20 tests in parallel in the tsl tests multiple
multinode tests might exhaust the number of connections the
test instance allowed. This patch changes the number of connections
to 200 for regresscheck-t.
2021-04-20 19:16:26 +02:00