mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 19:13:16 +08:00
Do not use partial indexes for compression
They refer only to a subset of the table.
This commit is contained in:
parent
2422f51f69
commit
c34fd0b06c
1
.unreleased/fix_partial_index
Normal file
1
.unreleased/fix_partial_index
Normal file
@ -0,0 +1 @@
|
||||
Fixes: #6280 Potential data loss when compressing a table with a partial index that matches compression order.
|
@ -291,6 +291,17 @@ compress_chunk(Oid in_table, Oid out_table, const ColumnCompressionInfo **column
|
||||
Oid index_oid = lfirst_oid(lc);
|
||||
Relation index_rel = index_open(index_oid, AccessShareLock);
|
||||
IndexInfo *index_info = BuildIndexInfo(index_rel);
|
||||
|
||||
if (index_info->ii_Predicate != 0)
|
||||
{
|
||||
/*
|
||||
* Can't use partial indexes for compression because they refer
|
||||
* only to a subset of all rows.
|
||||
*/
|
||||
index_close(index_rel, AccessShareLock);
|
||||
continue;
|
||||
}
|
||||
|
||||
int previous_direction = NoMovementScanDirection;
|
||||
int current_direction = NoMovementScanDirection;
|
||||
|
||||
|
@ -912,6 +912,43 @@ SELECT decompress_chunk(show_chunks('tab1'));
|
||||
(4 rows)
|
||||
|
||||
DROP INDEX idx_asc_null_first;
|
||||
-- Can't use partial indexes for compression because they refer only to a subset of the table.
|
||||
create index predicate on tab1(id, c1, time nulls first) where c2 = 0;
|
||||
select count(*) from tab1;
|
||||
count
|
||||
-------
|
||||
62400
|
||||
(1 row)
|
||||
|
||||
select compress_chunk(show_chunks('tab1'));
|
||||
INFO: compress_chunk_tuplesort_start
|
||||
INFO: compress_chunk_tuplesort_start
|
||||
INFO: compress_chunk_tuplesort_start
|
||||
INFO: compress_chunk_tuplesort_start
|
||||
compress_chunk
|
||||
----------------------------------------
|
||||
_timescaledb_internal._hyper_1_1_chunk
|
||||
_timescaledb_internal._hyper_1_2_chunk
|
||||
_timescaledb_internal._hyper_1_3_chunk
|
||||
_timescaledb_internal._hyper_1_4_chunk
|
||||
(4 rows)
|
||||
|
||||
select decompress_chunk(show_chunks('tab1'));
|
||||
decompress_chunk
|
||||
----------------------------------------
|
||||
_timescaledb_internal._hyper_1_1_chunk
|
||||
_timescaledb_internal._hyper_1_2_chunk
|
||||
_timescaledb_internal._hyper_1_3_chunk
|
||||
_timescaledb_internal._hyper_1_4_chunk
|
||||
(4 rows)
|
||||
|
||||
select count(*) from tab1;
|
||||
count
|
||||
-------
|
||||
62400
|
||||
(1 row)
|
||||
|
||||
drop index predicate;
|
||||
--Tear down
|
||||
DROP TABLE tab1;
|
||||
DROP TABLE tab2;
|
||||
|
@ -251,8 +251,16 @@ SELECT compress_chunk(show_chunks('tab1'));
|
||||
SELECT decompress_chunk(show_chunks('tab1'));
|
||||
DROP INDEX idx_asc_null_first;
|
||||
|
||||
-- Can't use partial indexes for compression because they refer only to a subset of the table.
|
||||
create index predicate on tab1(id, c1, time nulls first) where c2 = 0;
|
||||
select count(*) from tab1;
|
||||
select compress_chunk(show_chunks('tab1'));
|
||||
select decompress_chunk(show_chunks('tab1'));
|
||||
select count(*) from tab1;
|
||||
drop index predicate;
|
||||
|
||||
--Tear down
|
||||
DROP TABLE tab1;
|
||||
DROP TABLE tab2;
|
||||
DROP TABLE tab3;
|
||||
SET timescaledb.show_compression_path_info = 'off';
|
||||
SET timescaledb.show_compression_path_info = 'off';
|
||||
|
Loading…
x
Reference in New Issue
Block a user