Skip to content

Commit b2aff6d

Browse files
committed
Fix column rename for compressed chunks
Column rename would try to replace all values matching the column name in the sparse index configuration leading to errors when column names matched sparse index types.
1 parent 8cc5a35 commit b2aff6d

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

.unreleased/pr_10091

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #10091 Fix column rename for compressed chunks

src/ts_catalog/compression_settings.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,12 @@ compression_settings_rename_column(CompressionSettings *settings, const char *ol
633633
continue;
634634
}
635635

636+
/* Skip all but `column` key. */
637+
if (strcmp(pair->key, ts_sparse_index_common_keys[SparseIndexKeyCol]) != 0)
638+
{
639+
continue;
640+
}
641+
636642
ListCell *value_cell = NULL;
637643
foreach (value_cell, pair->values)
638644
{

tsl/test/expected/compress_sparse_config.out

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,53 @@ select * from settings;
848848

849849
reset timescaledb.auto_sparse_indexes;
850850
drop table test_orderby_default_noguc;
851+
-- Rename a column to a name that matches a sparse index type token
852+
create table test_rename_token(ts int not null, minmax int not null);
853+
select create_hypertable('test_rename_token', 'ts', chunk_time_interval => 100);
854+
create_hypertable
855+
---------------------------------
856+
(13,public,test_rename_token,t)
857+
858+
alter table test_rename_token set (timescaledb.compress, timescaledb.compress_orderby = 'ts');
859+
insert into test_rename_token select 1,1;
860+
select compress_chunk(show_chunks('test_rename_token'));
861+
compress_chunk
862+
------------------------------------------
863+
_timescaledb_internal._hyper_13_17_chunk
864+
865+
select * from settings;
866+
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst | index
867+
------------------------------------------+--------------------------------------------------+-----------+---------+--------------+--------------------+-----------------------------------------------------------------------------------------------------------------------
868+
test_rename_token | | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
869+
_timescaledb_internal._hyper_13_17_chunk | _timescaledb_internal.compress_hyper_14_18_chunk | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
870+
871+
-- renaming to a type token must not corrupt the orderby minmax index
872+
alter table test_rename_token rename column minmax to bloom;
873+
select * from settings;
874+
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst | index
875+
------------------------------------------+--------------------------------------------------+-----------+---------+--------------+--------------------+-----------------------------------------------------------------------------------------------------------------------
876+
test_rename_token | | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
877+
_timescaledb_internal._hyper_13_17_chunk | _timescaledb_internal.compress_hyper_14_18_chunk | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
878+
879+
alter table test_rename_token rename column bloom to firstlast;
880+
select * from settings;
881+
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst | index
882+
------------------------------------------+--------------------------------------------------+-----------+---------+--------------+--------------------+-----------------------------------------------------------------------------------------------------------------------
883+
test_rename_token | | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
884+
_timescaledb_internal._hyper_13_17_chunk | _timescaledb_internal.compress_hyper_14_18_chunk | | {ts} | {f} | {f} | [{"type": "minmax", "column": "ts", "source": "orderby"}, {"type": "firstlast", "column": "ts", "source": "orderby"}]
885+
886+
-- renaming an indexed column to a type token keeps the index intact
887+
alter table test_rename_token rename column ts to minmax;
888+
select * from settings;
889+
relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst | index
890+
------------------------------------------+--------------------------------------------------+-----------+----------+--------------+--------------------+-------------------------------------------------------------------------------------------------------------------------------
891+
test_rename_token | | | {minmax} | {f} | {f} | [{"type": "minmax", "column": "minmax", "source": "orderby"}, {"type": "firstlast", "column": "minmax", "source": "orderby"}]
892+
_timescaledb_internal._hyper_13_17_chunk | _timescaledb_internal.compress_hyper_14_18_chunk | | {minmax} | {f} | {f} | [{"type": "minmax", "column": "minmax", "source": "orderby"}, {"type": "firstlast", "column": "minmax", "source": "orderby"}]
893+
894+
\set ON_ERROR_STOP 0
895+
alter table test_rename_token rename column minmax to _ts_meta_v2_first_minmax;
896+
ERROR: cannot convert tables with reserved column prefix '_ts_meta_' to columnstore
897+
alter table test_rename_token rename column minmax to _ts_meta_count;
898+
ERROR: cannot convert tables with reserved column prefix '_ts_meta_' to columnstore
899+
\set ON_ERROR_STOP 1
900+
drop table test_rename_token;

tsl/test/sql/compress_sparse_config.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,27 @@ select * from settings;
511511

512512
reset timescaledb.auto_sparse_indexes;
513513
drop table test_orderby_default_noguc;
514+
515+
-- Rename a column to a name that matches a sparse index type token
516+
create table test_rename_token(ts int not null, minmax int not null);
517+
select create_hypertable('test_rename_token', 'ts', chunk_time_interval => 100);
518+
alter table test_rename_token set (timescaledb.compress, timescaledb.compress_orderby = 'ts');
519+
insert into test_rename_token select 1,1;
520+
select compress_chunk(show_chunks('test_rename_token'));
521+
select * from settings;
522+
-- renaming to a type token must not corrupt the orderby minmax index
523+
alter table test_rename_token rename column minmax to bloom;
524+
select * from settings;
525+
alter table test_rename_token rename column bloom to firstlast;
526+
select * from settings;
527+
-- renaming an indexed column to a type token keeps the index intact
528+
alter table test_rename_token rename column ts to minmax;
529+
select * from settings;
530+
531+
\set ON_ERROR_STOP 0
532+
alter table test_rename_token rename column minmax to _ts_meta_v2_first_minmax;
533+
alter table test_rename_token rename column minmax to _ts_meta_count;
534+
\set ON_ERROR_STOP 1
535+
536+
drop table test_rename_token;
537+

0 commit comments

Comments
 (0)