Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10fcb83

Browse filesBrowse files
committed
Fix YA incremental sort bug.
switchToPresortedPrefixMode() did the wrong thing if it detected a batch boundary just at the last tuple of a fullsort group. The initially-reported symptom was a "retrieved too many tuples in a bounded sort" error, but the test case added here just silently gives the wrong answer without this patch. I (tgl) am not really happy about committing this patch without review from the incremental-sort authors, but they seem AWOL and we are hard against a release deadline. This does demonstrably make some cases better, anyway. Per bug #16846 from Yoran Heling. Back-patch to v13 where incremental sort was introduced. Neil Chen Discussion: https://postgr.es/m/16846-ae49f51ac379a4cb@postgresql.org
1 parent 57868d9 commit 10fcb83
Copy full SHA for 10fcb83

File tree

Expand file treeCollapse file tree

3 files changed

+21
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-0
lines changed

‎src/backend/executor/nodeIncrementalSort.c

Copy file name to clipboardExpand all lines: src/backend/executor/nodeIncrementalSort.c
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ switchToPresortedPrefixMode(PlanState *pstate)
394394
* current prefix key group.
395395
*/
396396
ExecClearTuple(node->group_pivot);
397+
398+
/*
399+
* Also make sure we take the didn't-consume-all-the-tuples
400+
* path below, even if this happened to be the last tuple of
401+
* the batch.
402+
*/
403+
lastTuple = false;
397404
break;
398405
}
399406
}

‎src/test/regress/expected/incremental_sort.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/incremental_sort.out
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ select * from (select * from t order by a) s order by a, b limit 70;
675675
9 | 70
676676
(70 rows)
677677

678+
-- Checks case where we hit a group boundary at the last tuple of a batch.
679+
select * from (select * from t order by a) s order by a, b limit 5;
680+
a | b
681+
---+---
682+
1 | 1
683+
2 | 2
684+
3 | 3
685+
4 | 4
686+
9 | 5
687+
(5 rows)
688+
678689
-- Test rescan.
679690
begin;
680691
-- We force the planner to choose a plan with incremental sort on the right side

‎src/test/regress/sql/incremental_sort.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/incremental_sort.sql
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_
149149
analyze t;
150150
explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
151151
select * from (select * from t order by a) s order by a, b limit 70;
152+
-- Checks case where we hit a group boundary at the last tuple of a batch.
153+
select * from (select * from t order by a) s order by a, b limit 5;
154+
152155
-- Test rescan.
153156
begin;
154157
-- We force the planner to choose a plan with incremental sort on the right side

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.