Skip to content

Commit 9393f74

Browse files
authored
Disable DML optimizations with enable_optimizations GUC (#9923)
Same logic as before, we want to execute the queries but using the most basic unoptimized mechanism, so that we can then compare the results to verify our optimizations. Extend this GUC to cover some DML optimizations too.
1 parent 8dfa8ec commit 9393f74

9 files changed

Lines changed: 72 additions & 4 deletions

File tree

src/copy.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,14 @@ copy_table_to_chunk_error_callback(void *arg)
794794
static TSCopyInsertMethod
795795
choose_copy_method(Hypertable *ht, CopyChunkState *ccstate, ResultRelInfo *resultRelInfo)
796796
{
797+
if (!ts_guc_enable_optimizations)
798+
{
799+
ereport(DEBUG1,
800+
(errmsg("Using normal unbuffered copy operation (TS_CIM_SINGLE) "
801+
"because the optimizations are disabled.")));
802+
return TS_CIM_SINGLE;
803+
}
804+
797805
/*
798806
* Multi-insert buffers (TS_CIM_MULTI_CONDITIONAL) can only be used if no triggers are
799807
* defined on the target table. Otherwise, the tuples may be inserted in an out-of-order

src/nodes/modify_hypertable.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
static bool
2424
should_use_direct_compress(ModifyHypertableState *state)
2525
{
26+
if (!ts_guc_enable_optimizations)
27+
{
28+
return false;
29+
}
30+
2631
if (!ts_guc_enable_direct_compress_insert)
2732
{
2833
return false;

test/expected/copy.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ SELECT count(*) FROM hyper_copy;
242242
-------
243243
154
244244

245+
-- Disabled by the debug GUC
246+
SET timescaledb.enable_optimizations TO OFF;
247+
\copy hyper_copy FROM data/copy_data.csv WITH csv header;
248+
DEBUG: Using normal unbuffered copy operation (TS_CIM_SINGLE) because the optimizations are disabled.
249+
RESET timescaledb.enable_optimizations;
250+
SELECT count(*) FROM hyper_copy;
251+
count
252+
-------
253+
179
254+
245255
RESET client_min_messages;
246256
RESET timescaledb.max_open_chunks_per_insert;
247257
----------------------------------------------------------------

test/sql/copy.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ COPY hyper_copy FROM STDIN DELIMITER ',' NULL AS 'null';
214214

215215
SELECT count(*) FROM hyper_copy;
216216

217+
-- Disabled by the debug GUC
218+
SET timescaledb.enable_optimizations TO OFF;
219+
\copy hyper_copy FROM data/copy_data.csv WITH csv header;
220+
RESET timescaledb.enable_optimizations;
221+
222+
SELECT count(*) FROM hyper_copy;
223+
224+
217225
RESET client_min_messages;
218226
RESET timescaledb.max_open_chunks_per_insert;
219227

tsl/src/compression/compression_dml.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ init_decompress_state_for_insert(ChunkInsertState *cis, TupleTableSlot *slot)
350350
Bitmapset *index_columns = NULL;
351351
Relation index_rel = NULL;
352352

353-
if (ts_guc_enable_dml_decompression_tuple_filtering)
353+
if (ts_guc_enable_optimizations && ts_guc_enable_dml_decompression_tuple_filtering)
354354
{
355355
cdst->mem_scankeys.scankeys =
356356
build_mem_scankeys_from_slot(cis->hypertable_relid,
@@ -1769,7 +1769,7 @@ process_predicates(Chunk *ch, CompressionSettings *settings, List *predicates,
17691769
/*
17701770
* Segmentby columns are checked as part of batch scan so no need to redo the check.
17711771
*/
1772-
if (ts_guc_enable_dml_decompression_tuple_filtering)
1772+
if (ts_guc_enable_optimizations && ts_guc_enable_dml_decompression_tuple_filtering)
17731773
{
17741774
ScanKeyEntryInitialize(&(*mem_scankeys)[(*num_mem_scankeys)++],
17751775
arg_value->constisnull ? SK_ISNULL : 0,
@@ -2025,7 +2025,8 @@ process_predicates(Chunk *ch, CompressionSettings *settings, List *predicates,
20252025
* equality predicates, compute hashes, and collect matches.
20262026
* Results are sorted by selectivity (most columns first).
20272027
*/
2028-
if (eq_preds != NIL && settings->fd.index != NULL && ts_guc_enable_dml_bloom_filter)
2028+
if (eq_preds != NIL && settings->fd.index != NULL && ts_guc_enable_dml_bloom_filter &&
2029+
ts_guc_enable_optimizations)
20292030
{
20302031
SparseIndexSettings *parsed = ts_convert_to_sparse_index_settings(settings->fd.index);
20312032
TsBmsList per_column_attnos =
@@ -2358,7 +2359,7 @@ can_delete_without_decompression(ModifyHypertableState *ht_state, CompressionSet
23582359
{
23592360
ListCell *lc;
23602361

2361-
if (!ts_guc_enable_compressed_direct_batch_delete)
2362+
if (!ts_guc_enable_compressed_direct_batch_delete || !ts_guc_enable_optimizations)
23622363
{
23632364
return false;
23642365
}

tsl/test/expected/direct_compress_insert.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF) INSERT INTO metrics SE
3939
-> Insert on metrics
4040
-> Function Scan on generate_series i
4141

42+
-- EXPLAIN with debug GUC disabled
43+
SET timescaledb.enable_optimizations TO OFF;
44+
EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF) INSERT INTO metrics SELECT '2025-01-01'::timestamptz, 'd1', i::float FROM generate_series(0,500) i;
45+
--- QUERY PLAN ---
46+
Custom Scan (ModifyHypertable)
47+
Direct Compress: false
48+
-> Insert on metrics
49+
-> Function Scan on generate_series i
50+
51+
RESET timescaledb.enable_optimizations;
4252
-- simple test with compressed insert enabled
4353
BEGIN;
4454
INSERT INTO metrics SELECT '2025-01-01'::timestamptz + (i || ' minute')::interval, 'd1', i::float FROM generate_series(0,3000) i;

tsl/test/shared/expected/compression_dml.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ BEGIN; :ANALYZE UPDATE lazy_decompress SET value = 3.14 WHERE value = 0 AND devi
323323
Rows Removed by Filter: 6000
324324

325325
RESET timescaledb.enable_dml_decompression_tuple_filtering;
326+
-- Same for the debug GUC
327+
SET timescaledb.enable_optimizations TO off;
328+
BEGIN; :ANALYZE UPDATE lazy_decompress SET value = 3.14 WHERE value = 0 AND device='d1'; ROLLBACK;
329+
--- QUERY PLAN ---
330+
Custom Scan (ModifyHypertable) (actual rows=0.00 loops=1)
331+
Batches scanned: 6
332+
Batches decompressed: 6
333+
Tuples decompressed: 6000
334+
-> Update on lazy_decompress (actual rows=0.00 loops=1)
335+
Update on _hyper_X_X_chunk lazy_decompress_1
336+
-> Result (actual rows=0.00 loops=1)
337+
-> Seq Scan on _hyper_X_X_chunk lazy_decompress_1 (actual rows=0.00 loops=1)
338+
Filter: ((value = '0'::double precision) AND (device = 'd1'::text))
339+
Rows Removed by Filter: 6000
340+
341+
RESET timescaledb.enable_optimizations;
326342
-- no decompression cause no match in batch
327343
BEGIN; :ANALYZE DELETE FROM lazy_decompress WHERE value = 0; ROLLBACK;
328344
--- QUERY PLAN ---

tsl/test/shared/sql/compression_dml.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ SET timescaledb.enable_dml_decompression_tuple_filtering TO off;
173173
BEGIN; :ANALYZE UPDATE lazy_decompress SET value = 3.14 WHERE value = 0 AND device='d1'; ROLLBACK;
174174
RESET timescaledb.enable_dml_decompression_tuple_filtering;
175175

176+
-- Same for the debug GUC
177+
SET timescaledb.enable_optimizations TO off;
178+
BEGIN; :ANALYZE UPDATE lazy_decompress SET value = 3.14 WHERE value = 0 AND device='d1'; ROLLBACK;
179+
RESET timescaledb.enable_optimizations;
180+
176181
-- no decompression cause no match in batch
177182
BEGIN; :ANALYZE DELETE FROM lazy_decompress WHERE value = 0; ROLLBACK;
178183
BEGIN; :ANALYZE DELETE FROM lazy_decompress WHERE value = 0 AND device='d1'; ROLLBACK;

tsl/test/sql/direct_compress_insert.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF) INSERT INTO metrics SE
2121
-- EXPLAIN with large enough batch
2222
EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF) INSERT INTO metrics SELECT '2025-01-01'::timestamptz, 'd1', i::float FROM generate_series(0,500) i;
2323

24+
-- EXPLAIN with debug GUC disabled
25+
SET timescaledb.enable_optimizations TO OFF;
26+
EXPLAIN (BUFFERS OFF, COSTS OFF, SUMMARY OFF, TIMING OFF) INSERT INTO metrics SELECT '2025-01-01'::timestamptz, 'd1', i::float FROM generate_series(0,500) i;
27+
RESET timescaledb.enable_optimizations;
28+
2429
-- simple test with compressed insert enabled
2530
BEGIN;
2631
INSERT INTO metrics SELECT '2025-01-01'::timestamptz + (i || ' minute')::interval, 'd1', i::float FROM generate_series(0,3000) i;

0 commit comments

Comments
 (0)