-
Notifications
You must be signed in to change notification settings - Fork 859
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not decompress batches for COPY with potentially invalid slot (#6931)
We don't have to decompress anything more when we re-lookup the chunk insert state on COPY buffer flush. Moreover, `ChunkInsertState.slots[0]` is incorrect slot type for `decompress_batches_for_insert()`, because it is a chunk slot, not a hypertable slot. This can lead to rare errors when the chunk insert states go out of cache. Just don't do this unnecessary lookup, and move decompression to a separate function for clarity. Add an assertion and test that detect the slot type mismatch on main.
- Loading branch information
Showing
9 changed files
with
214 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
-- This file and its contents are licensed under the Timescale License. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-TIMESCALE for a copy of the license. | ||
-- Test various cases of COPY with decompression and different chunk layouts. | ||
create table cdmlcopy(filler bigint, ts int, value float, metric text); | ||
select create_hypertable('cdmlcopy', 'ts', chunk_time_interval => 1000); | ||
NOTICE: adding not-null constraint to column "ts" | ||
create_hypertable | ||
----------------------- | ||
(1,public,cdmlcopy,t) | ||
(1 row) | ||
|
||
alter table cdmlcopy add unique (metric, ts); | ||
alter table cdmlcopy set (timescaledb.compress, timescaledb.compress_segmentby = 'metric'); | ||
NOTICE: default order by for hypertable "cdmlcopy" is set to "ts DESC" | ||
\copy cdmlcopy from stdin | ||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
count | ||
------- | ||
1 | ||
(1 row) | ||
|
||
alter table cdmlcopy drop column filler; | ||
\copy cdmlcopy from stdin | ||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
NOTICE: chunk "_hyper_1_1_chunk" is already compressed | ||
count | ||
------- | ||
2 | ||
(1 row) | ||
|
||
\set ON_ERROR_STOP 0 | ||
\copy cdmlcopy from stdin | ||
ERROR: duplicate key value violates unique constraint "1_1_cdmlcopy_metric_ts_key" | ||
\copy cdmlcopy from stdin | ||
ERROR: duplicate key value violates unique constraint "3_2_cdmlcopy_metric_ts_key" | ||
\set ON_ERROR_STOP 1 | ||
-- Also test the code path where the chunk insert state goes out of cache. | ||
set timescaledb.max_open_chunks_per_insert = 1; | ||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
NOTICE: chunk "_hyper_1_1_chunk" is already compressed | ||
NOTICE: chunk "_hyper_1_3_chunk" is already compressed | ||
count | ||
------- | ||
2 | ||
(1 row) | ||
|
||
\copy cdmlcopy from stdin | ||
reset timescaledb.max_open_chunks_per_insert; | ||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
count | ||
------- | ||
2 | ||
(1 row) | ||
|
||
drop table cdmlcopy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
-- This file and its contents are licensed under the Timescale License. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-TIMESCALE for a copy of the license. | ||
|
||
-- Test various cases of COPY with decompression and different chunk layouts. | ||
|
||
create table cdmlcopy(filler bigint, ts int, value float, metric text); | ||
|
||
select create_hypertable('cdmlcopy', 'ts', chunk_time_interval => 1000); | ||
|
||
alter table cdmlcopy add unique (metric, ts); | ||
|
||
alter table cdmlcopy set (timescaledb.compress, timescaledb.compress_segmentby = 'metric'); | ||
|
||
\copy cdmlcopy from stdin | ||
0 1 1.1 'metric1' | ||
0 1 1.2 'metric2' | ||
\. | ||
|
||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
|
||
alter table cdmlcopy drop column filler; | ||
|
||
\copy cdmlcopy from stdin | ||
1001 1.1 'metric1' | ||
1001 1.2 'metric2' | ||
\. | ||
|
||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
|
||
\set ON_ERROR_STOP 0 | ||
\copy cdmlcopy from stdin | ||
1 1.1 'metric1' | ||
1 1.2 'metric2' | ||
\. | ||
|
||
\copy cdmlcopy from stdin | ||
1001 1.1 'metric1' | ||
1001 1.2 'metric2' | ||
\. | ||
\set ON_ERROR_STOP 1 | ||
|
||
|
||
-- Also test the code path where the chunk insert state goes out of cache. | ||
set timescaledb.max_open_chunks_per_insert = 1; | ||
|
||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
|
||
\copy cdmlcopy from stdin | ||
2 2.1 'metric1' | ||
1002 2.2 'metric2' | ||
2 2.2 'metric2' | ||
1002 2.1 'metric1' | ||
\. | ||
|
||
reset timescaledb.max_open_chunks_per_insert; | ||
|
||
select count(compress_chunk(x)) from show_chunks('cdmlcopy') x; | ||
|
||
drop table cdmlcopy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters