@@ -141,7 +141,8 @@ begin
141141end;
142142$$;
143143-- A single large group tested around each mode transition point.
144- insert into t(a, b) select 1, i from generate_series(1, 100) n(i);
144+ insert into t(a, b) select i/100 + 1, i + 1 from generate_series(0, 999) n(i);
145+ analyze t;
145146explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
146147 QUERY PLAN
147148---------------------------------
@@ -456,7 +457,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
456457
457458delete from t;
458459-- An initial large group followed by a small group.
459- insert into t(a, b) select (case when i < 50 then 1 else 2 end), i from generate_series(1, 100) n(i);
460+ insert into t(a, b) select i/50 + 1, i + 1 from generate_series(0, 999) n(i);
461+ analyze t;
460462explain (costs off) select * from (select * from t order by a) s order by a, b limit 55;
461463 QUERY PLAN
462464---------------------------------
@@ -521,7 +523,7 @@ select * from (select * from t order by a) s order by a, b limit 55;
521523 1 | 47
522524 1 | 48
523525 1 | 49
524- 2 | 50
526+ 1 | 50
525527 2 | 51
526528 2 | 52
527529 2 | 53
@@ -538,10 +540,10 @@ select explain_analyze_without_memory('select * from (select * from t order by a
538540 Sort Key: t.a, t.b
539541 Presorted Key: t.a
540542 Full-sort Groups: 2 Sort Methods: top-N heapsort, quicksort Memory: avg=NNkB peak=NNkB
541- -> Sort (actual rows=100 loops=1)
543+ -> Sort (actual rows=101 loops=1)
542544 Sort Key: t.a
543545 Sort Method: quicksort Memory: NNkB
544- -> Seq Scan on t (actual rows=100 loops=1)
546+ -> Seq Scan on t (actual rows=1000 loops=1)
545547(9 rows)
546548
547549select jsonb_pretty(explain_analyze_inc_sort_nodes_without_memory('select * from (select * from t order by a) s order by a, b limit 55'));
@@ -584,7 +586,8 @@ select explain_analyze_inc_sort_nodes_verify_invariants('select * from (select *
584586
585587delete from t;
586588-- An initial small group followed by a large group.
587- insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_series(1, 100) n(i);
589+ insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_series(1, 1000) n(i);
590+ analyze t;
588591explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
589592 QUERY PLAN
590593---------------------------------
@@ -705,17 +708,17 @@ select * from t left join (select * from (select * from t order by a) v order by
705708rollback;
706709-- Test EXPLAIN ANALYZE with both fullsort and presorted groups.
707710select explain_analyze_without_memory('select * from (select * from t order by a) s order by a, b limit 70');
708- explain_analyze_without_memory
709- -----------------------------------------------------------------------------------------------------------------------------------------------------
711+ explain_analyze_without_memory
712+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
710713 Limit (actual rows=70 loops=1)
711714 -> Incremental Sort (actual rows=70 loops=1)
712715 Sort Key: t.a, t.b
713716 Presorted Key: t.a
714- Full-sort Groups: 1 Sort Method: quicksort Memory: avg=NNkB peak=NNkB Presorted Groups: 5 Sort Method: quicksort Memory: avg=NNkB peak=NNkB
715- -> Sort (actual rows=100 loops=1)
717+ Full-sort Groups: 1 Sort Method: quicksort Memory: avg=NNkB peak=NNkB Presorted Groups: 5 Sort Methods: top-N heapsort, quicksort Memory: avg=NNkB peak=NNkB
718+ -> Sort (actual rows=1000 loops=1)
716719 Sort Key: t.a
717720 Sort Method: quicksort Memory: NNkB
718- -> Seq Scan on t (actual rows=100 loops=1)
721+ -> Seq Scan on t (actual rows=1000 loops=1)
719722(9 rows)
720723
721724select jsonb_pretty(explain_analyze_inc_sort_nodes_without_memory('select * from (select * from t order by a) s order by a, b limit 70'));
@@ -747,6 +750,7 @@ select jsonb_pretty(explain_analyze_inc_sort_nodes_without_memory('select * from
747750 "Presorted Groups": { +
748751 "Group Count": 5, +
749752 "Sort Methods Used": [ +
753+ "top-N heapsort", +
750754 "quicksort" +
751755 ], +
752756 "Sort Space Memory": { +
@@ -767,7 +771,8 @@ select explain_analyze_inc_sort_nodes_verify_invariants('select * from (select *
767771
768772delete from t;
769773-- Small groups of 10 tuples each tested around each mode transition point.
770- insert into t(a, b) select i / 10, i from generate_series(1, 70) n(i);
774+ insert into t(a, b) select i / 10, i from generate_series(1, 1000) n(i);
775+ analyze t;
771776explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
772777 QUERY PLAN
773778---------------------------------
@@ -1082,7 +1087,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
10821087
10831088delete from t;
10841089-- Small groups of only 1 tuple each tested around each mode transition point.
1085- insert into t(a, b) select i, i from generate_series(1, 70) n(i);
1090+ insert into t(a, b) select i, i from generate_series(1, 1000) n(i);
1091+ analyze t;
10861092explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
10871093 QUERY PLAN
10881094---------------------------------
0 commit comments