@@ -848,3 +848,53 @@ select * from settings;
848848
849849reset timescaledb.auto_sparse_indexes;
850850drop 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;
0 commit comments