Skip to content

Commit

Permalink
Don't disable batch sorted merge plan with enable_sort GUC
Browse files Browse the repository at this point in the history
We have a separate GUC for it, this way it's more convenient to test
various plans.
  • Loading branch information
akuzm committed Nov 20, 2023
1 parent e3c4596 commit 3c860cc
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tsl/src/nodes/decompress_chunk/decompress_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ cost_decompress_sorted_merge_append(PlannerInfo *root, DecompressChunkPath *dcpa
{
Path sort_path; /* dummy for result of cost_sort */

/*
* Don't disable the compressed batch sorted merge plan with the enable_sort
* GUC. We have a separate GUC for it, and this way you can try to force the
* batch sorted merge plan by disabling sort.
*/
const bool old_enable_sort = enable_sort;
enable_sort = true;
cost_sort(&sort_path,
root,
dcpath->compressed_pathkeys,
Expand All @@ -358,6 +365,7 @@ cost_decompress_sorted_merge_append(PlannerInfo *root, DecompressChunkPath *dcpa
0.0,
work_mem,
-1);
enable_sort = old_enable_sort;

/* startup_cost is cost before fetching first tuple */
dcpath->custom_path.path.startup_cost = sort_path.total_cost;
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/compression_sorted_merge-13.out
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ SELECT * FROM test1 WHERE x4 > 100 ORDER BY time ASC, x3, x4;
Rows Removed by Filter: 3
(12 rows)

-- Test that the enable_sort GUC doesn't disable the batch sorted merge plan.
SET enable_sort TO OFF;
:PREFIX
SELECT * FROM test1 ORDER BY time DESC;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_1_1_chunk (actual rows=4 loops=1)
Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.x1, _hyper_1_1_chunk.x2, _hyper_1_1_chunk.x3, _hyper_1_1_chunk.x4, _hyper_1_1_chunk.x5
Sorted merge append: true
Bulk Decompression: false
-> Sort (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
Sort Key: compress_hyper_2_2_chunk._ts_meta_max_1 DESC
Sort Method: quicksort
-> Seq Scan on _timescaledb_internal.compress_hyper_2_2_chunk (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
(10 rows)

RESET enable_sort;
------
-- Tests based on results
------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/compression_sorted_merge-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ SELECT * FROM test1 WHERE x4 > 100 ORDER BY time ASC, x3, x4;
Rows Removed by Filter: 3
(12 rows)

-- Test that the enable_sort GUC doesn't disable the batch sorted merge plan.
SET enable_sort TO OFF;
:PREFIX
SELECT * FROM test1 ORDER BY time DESC;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_1_1_chunk (actual rows=4 loops=1)
Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.x1, _hyper_1_1_chunk.x2, _hyper_1_1_chunk.x3, _hyper_1_1_chunk.x4, _hyper_1_1_chunk.x5
Sorted merge append: true
Bulk Decompression: false
-> Sort (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
Sort Key: compress_hyper_2_2_chunk._ts_meta_max_1 DESC
Sort Method: quicksort
-> Seq Scan on _timescaledb_internal.compress_hyper_2_2_chunk (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
(10 rows)

RESET enable_sort;
------
-- Tests based on results
------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/compression_sorted_merge-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ SELECT * FROM test1 WHERE x4 > 100 ORDER BY time ASC, x3, x4;
Rows Removed by Filter: 3
(12 rows)

-- Test that the enable_sort GUC doesn't disable the batch sorted merge plan.
SET enable_sort TO OFF;
:PREFIX
SELECT * FROM test1 ORDER BY time DESC;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_1_1_chunk (actual rows=4 loops=1)
Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.x1, _hyper_1_1_chunk.x2, _hyper_1_1_chunk.x3, _hyper_1_1_chunk.x4, _hyper_1_1_chunk.x5
Sorted merge append: true
Bulk Decompression: false
-> Sort (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
Sort Key: compress_hyper_2_2_chunk._ts_meta_max_1 DESC
Sort Method: quicksort
-> Seq Scan on _timescaledb_internal.compress_hyper_2_2_chunk (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
(10 rows)

RESET enable_sort;
------
-- Tests based on results
------
Expand Down
19 changes: 19 additions & 0 deletions tsl/test/expected/compression_sorted_merge-16.out
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,25 @@ SELECT * FROM test1 WHERE x4 > 100 ORDER BY time ASC, x3, x4;
Rows Removed by Filter: 3
(12 rows)

-- Test that the enable_sort GUC doesn't disable the batch sorted merge plan.
SET enable_sort TO OFF;
:PREFIX
SELECT * FROM test1 ORDER BY time DESC;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Custom Scan (DecompressChunk) on _timescaledb_internal._hyper_1_1_chunk (actual rows=4 loops=1)
Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.x1, _hyper_1_1_chunk.x2, _hyper_1_1_chunk.x3, _hyper_1_1_chunk.x4, _hyper_1_1_chunk.x5
Sorted merge append: true
Bulk Decompression: false
-> Sort (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
Sort Key: compress_hyper_2_2_chunk._ts_meta_max_1 DESC
Sort Method: quicksort
-> Seq Scan on _timescaledb_internal.compress_hyper_2_2_chunk (actual rows=3 loops=1)
Output: compress_hyper_2_2_chunk."time", compress_hyper_2_2_chunk.x1, compress_hyper_2_2_chunk.x2, compress_hyper_2_2_chunk.x3, compress_hyper_2_2_chunk.x4, compress_hyper_2_2_chunk.x5, compress_hyper_2_2_chunk._ts_meta_count, compress_hyper_2_2_chunk._ts_meta_sequence_num, compress_hyper_2_2_chunk._ts_meta_min_1, compress_hyper_2_2_chunk._ts_meta_max_1, compress_hyper_2_2_chunk._ts_meta_min_2, compress_hyper_2_2_chunk._ts_meta_max_2, compress_hyper_2_2_chunk._ts_meta_min_3, compress_hyper_2_2_chunk._ts_meta_max_3
(10 rows)

RESET enable_sort;
------
-- Tests based on results
------
Expand Down
6 changes: 6 additions & 0 deletions tsl/test/sql/compression_sorted_merge.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ SELECT * FROM test1 WHERE x4 > 100 ORDER BY time DESC, x4, x3;
:PREFIX
SELECT * FROM test1 WHERE x4 > 100 ORDER BY time ASC, x3, x4;

-- Test that the enable_sort GUC doesn't disable the batch sorted merge plan.
SET enable_sort TO OFF;
:PREFIX
SELECT * FROM test1 ORDER BY time DESC;
RESET enable_sort;

------
-- Tests based on results
------
Expand Down

0 comments on commit 3c860cc

Please sign in to comment.