mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-07-16 22:01:08 +02:00
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
This commit is contained in:
parent
57868d957e
commit
10fcb83da6
@ -394,6 +394,13 @@ switchToPresortedPrefixMode(PlanState *pstate)
|
|||||||
* current prefix key group.
|
* current prefix key group.
|
||||||
*/
|
*/
|
||||||
ExecClearTuple(node->group_pivot);
|
ExecClearTuple(node->group_pivot);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Also make sure we take the didn't-consume-all-the-tuples
|
||||||
|
* path below, even if this happened to be the last tuple of
|
||||||
|
* the batch.
|
||||||
|
*/
|
||||||
|
lastTuple = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -675,6 +675,17 @@ select * from (select * from t order by a) s order by a, b limit 70;
|
|||||||
9 | 70
|
9 | 70
|
||||||
(70 rows)
|
(70 rows)
|
||||||
|
|
||||||
|
-- Checks case where we hit a group boundary at the last tuple of a batch.
|
||||||
|
select * from (select * from t order by a) s order by a, b limit 5;
|
||||||
|
a | b
|
||||||
|
---+---
|
||||||
|
1 | 1
|
||||||
|
2 | 2
|
||||||
|
3 | 3
|
||||||
|
4 | 4
|
||||||
|
9 | 5
|
||||||
|
(5 rows)
|
||||||
|
|
||||||
-- Test rescan.
|
-- Test rescan.
|
||||||
begin;
|
begin;
|
||||||
-- We force the planner to choose a plan with incremental sort on the right side
|
-- We force the planner to choose a plan with incremental sort on the right side
|
||||||
|
@ -149,6 +149,9 @@ insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_
|
|||||||
analyze t;
|
analyze t;
|
||||||
explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
|
explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
|
||||||
select * from (select * from t order by a) s order by a, b limit 70;
|
select * from (select * from t order by a) s order by a, b limit 70;
|
||||||
|
-- Checks case where we hit a group boundary at the last tuple of a batch.
|
||||||
|
select * from (select * from t order by a) s order by a, b limit 5;
|
||||||
|
|
||||||
-- Test rescan.
|
-- Test rescan.
|
||||||
begin;
|
begin;
|
||||||
-- We force the planner to choose a plan with incremental sort on the right side
|
-- We force the planner to choose a plan with incremental sort on the right side
|
||||||
|
Loading…
Reference in New Issue
Block a user