Skip to content

Commit 3cf9495

Browse files
Skip default segmentby if orderby is explicitly set
Avoid assigning a default segmentby when the user specifies an orderby column. This prevents cases where both segmentby and orderby end up using the same column unintentionally.
1 parent 8698851 commit 3cf9495

36 files changed

+81
-201
lines changed

run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
#set -x
4+
5+
PGPATH=${PGPATH:-/usr/local/pgsql}
6+
PGBIN=${PGPATH}/bin
7+
PATH=${PGBIN}:$PATH
8+
DBCLUSTER=${DBCLUSTER:-~/dbcluster/}
9+
PGUSER=${PGUSER:-postgres}
10+
11+
export PATH
12+
13+
${PGBIN}/pg_ctl -D ${DBCLUSTER} stop
14+
15+
if [ "$1" = "stop" ]; then
16+
exit;
17+
elif [ "$1" = "init" ]; then
18+
echo "Initializing cluster in ${DBCLUSTER}"
19+
rm -rf ${DBCLUSTER}
20+
mkdir ${DBCLUSTER}
21+
${PGBIN}/initdb -U ${PGUSER} -D ${DBCLUSTER}
22+
fi
23+
24+
pushd build
25+
make
26+
sudo make install
27+
popd
28+
29+
${PGBIN}/pg_ctl -U ${PGUSER} -D ${DBCLUSTER} -l ${DBCLUSTER}/pg.log -o "-h 127.0.0.1 -p 5432 -cshared_preload_libraries='timescaledb'" start
30+
/usr/local/pgsql/bin/psql -U postgres -d postgres -c "create extension timescaledb;"

tsl/src/compression/create.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,8 @@ compression_settings_update(Hypertable *ht, CompressionSettings *settings,
12031203
{
12041204
settings->fd.segmentby = ts_compress_hypertable_parse_segment_by(with_clause_options, ht);
12051205
}
1206-
else if (!settings->fd.segmentby)
1206+
else if (!settings->fd.segmentby && !settings->fd.orderby &&
1207+
with_clause_options[AlterTableFlagCompressOrderBy].is_default)
12071208
{
12081209
settings->fd.segmentby = compression_setting_segmentby_get_default(ht);
12091210
}

tsl/test/expected/bgw_custom.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,6 @@ INSERT INTO sensor_data
882882
time;
883883
-- enable compression
884884
ALTER TABLE sensor_data SET (timescaledb.compress, timescaledb.compress_orderby = 'time DESC');
885-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
886-
NOTICE: default segment by for hypertable "sensor_data" is set to ""
887885
-- create new chunks
888886
INSERT INTO sensor_data
889887
SELECT

tsl/test/expected/bgw_db_scheduler_fixed.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,8 +1660,6 @@ select show_chunks('test_table_scheduler');
16601660
(8 rows)
16611661

16621662
alter table test_table_scheduler set (timescaledb.compress, timescaledb.compress_orderby = 'time DESC');
1663-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1664-
NOTICE: default segment by for hypertable "test_table_scheduler" is set to ""
16651663
select add_retention_policy('test_table_scheduler', interval '2 year', initial_start => :'init'::timestamptz, timezone => 'Europe/Berlin');
16661664
add_retention_policy
16671665
----------------------

tsl/test/expected/cagg_ddl-15.out

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
15201520
--try out 2 settings here --
15211521
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
15221522
NOTICE: defaulting compress_orderby to time_bucket
1523-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1524-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15251523
SELECT view_name, compression_enabled, materialized_only
15261524
FROM timescaledb_information.continuous_aggregates
15271525
where view_name = 'test_setting_cagg';
@@ -1540,8 +1538,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
15401538
--now set it back to false --
15411539
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
15421540
NOTICE: defaulting compress_orderby to time_bucket
1543-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1544-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15451541
SELECT view_name, compression_enabled, materialized_only
15461542
FROM timescaledb_information.continuous_aggregates
15471543
where view_name = 'test_setting_cagg';
@@ -1609,8 +1605,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
16091605
--try out 2 settings here --
16101606
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
16111607
NOTICE: defaulting compress_orderby to time_bucket
1612-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1613-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16141608
SELECT view_name, compression_enabled, materialized_only
16151609
FROM timescaledb_information.continuous_aggregates
16161610
where view_name = 'test_setting_cagg';
@@ -1629,8 +1623,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
16291623
--now set it back to false --
16301624
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
16311625
NOTICE: defaulting compress_orderby to time_bucket
1632-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1633-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16341626
SELECT view_name, compression_enabled, materialized_only
16351627
FROM timescaledb_information.continuous_aggregates
16361628
where view_name = 'test_setting_cagg';
@@ -2106,8 +2098,6 @@ CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_buck
21062098
NOTICE: refreshing continuous aggregate "cagg1"
21072099
ALTER MATERIALIZED VIEW cagg1 SET (timescaledb.compress);
21082100
NOTICE: defaulting compress_orderby to time_bucket
2109-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
2110-
NOTICE: default segment by for hypertable "_materialized_hypertable_56" is set to ""
21112101
SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch;
21122102
count
21132103
-------

tsl/test/expected/cagg_ddl-16.out

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
15201520
--try out 2 settings here --
15211521
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
15221522
NOTICE: defaulting compress_orderby to time_bucket
1523-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1524-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15251523
SELECT view_name, compression_enabled, materialized_only
15261524
FROM timescaledb_information.continuous_aggregates
15271525
where view_name = 'test_setting_cagg';
@@ -1540,8 +1538,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
15401538
--now set it back to false --
15411539
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
15421540
NOTICE: defaulting compress_orderby to time_bucket
1543-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1544-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15451541
SELECT view_name, compression_enabled, materialized_only
15461542
FROM timescaledb_information.continuous_aggregates
15471543
where view_name = 'test_setting_cagg';
@@ -1609,8 +1605,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
16091605
--try out 2 settings here --
16101606
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
16111607
NOTICE: defaulting compress_orderby to time_bucket
1612-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1613-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16141608
SELECT view_name, compression_enabled, materialized_only
16151609
FROM timescaledb_information.continuous_aggregates
16161610
where view_name = 'test_setting_cagg';
@@ -1629,8 +1623,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
16291623
--now set it back to false --
16301624
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
16311625
NOTICE: defaulting compress_orderby to time_bucket
1632-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1633-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16341626
SELECT view_name, compression_enabled, materialized_only
16351627
FROM timescaledb_information.continuous_aggregates
16361628
where view_name = 'test_setting_cagg';
@@ -2106,8 +2098,6 @@ CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_buck
21062098
NOTICE: refreshing continuous aggregate "cagg1"
21072099
ALTER MATERIALIZED VIEW cagg1 SET (timescaledb.compress);
21082100
NOTICE: defaulting compress_orderby to time_bucket
2109-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
2110-
NOTICE: default segment by for hypertable "_materialized_hypertable_56" is set to ""
21112101
SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch;
21122102
count
21132103
-------

tsl/test/expected/cagg_ddl-17.out

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
15201520
--try out 2 settings here --
15211521
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
15221522
NOTICE: defaulting compress_orderby to time_bucket
1523-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1524-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15251523
SELECT view_name, compression_enabled, materialized_only
15261524
FROM timescaledb_information.continuous_aggregates
15271525
where view_name = 'test_setting_cagg';
@@ -1540,8 +1538,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
15401538
--now set it back to false --
15411539
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
15421540
NOTICE: defaulting compress_orderby to time_bucket
1543-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1544-
NOTICE: default segment by for hypertable "_materialized_hypertable_40" is set to ""
15451541
SELECT view_name, compression_enabled, materialized_only
15461542
FROM timescaledb_information.continuous_aggregates
15471543
where view_name = 'test_setting_cagg';
@@ -1609,8 +1605,6 @@ INSERT INTO test_setting VALUES( '2020-11-01', 20);
16091605
--try out 2 settings here --
16101606
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'false', timescaledb.compress='true');
16111607
NOTICE: defaulting compress_orderby to time_bucket
1612-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1613-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16141608
SELECT view_name, compression_enabled, materialized_only
16151609
FROM timescaledb_information.continuous_aggregates
16161610
where view_name = 'test_setting_cagg';
@@ -1629,8 +1623,6 @@ SELECT count(*) from test_setting_cagg ORDER BY 1;
16291623
--now set it back to false --
16301624
ALTER MATERIALIZED VIEW test_setting_cagg SET (timescaledb.materialized_only = 'true', timescaledb.compress='true');
16311625
NOTICE: defaulting compress_orderby to time_bucket
1632-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
1633-
NOTICE: default segment by for hypertable "_materialized_hypertable_42" is set to ""
16341626
SELECT view_name, compression_enabled, materialized_only
16351627
FROM timescaledb_information.continuous_aggregates
16361628
where view_name = 'test_setting_cagg';
@@ -2106,8 +2098,6 @@ CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_buck
21062098
NOTICE: refreshing continuous aggregate "cagg1"
21072099
ALTER MATERIALIZED VIEW cagg1 SET (timescaledb.compress);
21082100
NOTICE: defaulting compress_orderby to time_bucket
2109-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
2110-
NOTICE: default segment by for hypertable "_materialized_hypertable_56" is set to ""
21112101
SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch;
21122102
count
21132103
-------

tsl/test/expected/cagg_errors.out

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,9 @@ NOTICE: defaulting compress_orderby to bucket
526526
ERROR: cannot use column "bucket" for both ordering and segmenting
527527
ALTER MATERIALIZED VIEW i2980_cagg2 SET ( timescaledb.compress,
528528
timescaledb.compress_orderby = 'bucket');
529-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
530-
NOTICE: default segment by for hypertable "_materialized_hypertable_14" is set to ""
531529
--enable compression and test re-enabling compression
532530
ALTER MATERIALIZED VIEW i2980_cagg2 SET ( timescaledb.compress);
533531
NOTICE: defaulting compress_orderby to bucket
534-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
535-
NOTICE: default segment by for hypertable "_materialized_hypertable_14" is set to ""
536532
insert into i2980 select now();
537533
call refresh_continuous_aggregate('i2980_cagg2', NULL, NULL);
538534
SELECT compress_chunk(ch) FROM show_chunks('i2980_cagg2') ch;
@@ -545,8 +541,6 @@ ALTER MATERIALIZED VIEW i2980_cagg2 SET ( timescaledb.compress = 'false');
545541
ERROR: cannot disable columnstore on hypertable with columnstore chunks
546542
ALTER MATERIALIZED VIEW i2980_cagg2 SET ( timescaledb.compress = 'true');
547543
NOTICE: defaulting compress_orderby to bucket
548-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
549-
NOTICE: default segment by for hypertable "_materialized_hypertable_14" is set to ""
550544
ALTER MATERIALIZED VIEW i2980_cagg2 SET ( timescaledb.compress, timescaledb.compress_segmentby = 'bucket');
551545
NOTICE: defaulting compress_orderby to bucket
552546
ERROR: cannot use column "bucket" for both ordering and segmenting
@@ -561,8 +555,6 @@ SELECT add_compression_policy('i2980_cagg', '8 day'::interval);
561555
ERROR: columnstore not enabled on continuous aggregate "i2980_cagg"
562556
ALTER MATERIALIZED VIEW i2980_cagg SET ( timescaledb.compress );
563557
NOTICE: defaulting compress_orderby to time_bucket
564-
WARNING: there was some uncertainty picking the default segment by for the hypertable: You do not have any indexes on columns that can be used for segment_by and thus we are not using segment_by for converting to columnstore. Please make sure you are not missing any indexes
565-
NOTICE: default segment by for hypertable "_materialized_hypertable_13" is set to ""
566558
SELECT add_continuous_aggregate_policy('i2980_cagg2', '10 day'::interval, '6 day'::interval);
567559
ERROR: function add_continuous_aggregate_policy(unknown, interval, interval) does not exist at character 8
568560
SELECT add_compression_policy('i2980_cagg2', '3'::integer);

0 commit comments

Comments
 (0)