@@ -141,7 +141,8 @@ begin
141
141
end;
142
142
$$;
143
143
-- 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;
145
146
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
146
147
QUERY PLAN
147
148
---------------------------------
@@ -456,7 +457,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
456
457
457
458
delete from t;
458
459
-- 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;
460
462
explain (costs off) select * from (select * from t order by a) s order by a, b limit 55;
461
463
QUERY PLAN
462
464
---------------------------------
@@ -521,7 +523,7 @@ select * from (select * from t order by a) s order by a, b limit 55;
521
523
1 | 47
522
524
1 | 48
523
525
1 | 49
524
- 2 | 50
526
+ 1 | 50
525
527
2 | 51
526
528
2 | 52
527
529
2 | 53
@@ -538,10 +540,10 @@ select explain_analyze_without_memory('select * from (select * from t order by a
538
540
Sort Key: t.a, t.b
539
541
Presorted Key: t.a
540
542
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)
542
544
Sort Key: t.a
543
545
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)
545
547
(9 rows)
546
548
547
549
select 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 *
584
586
585
587
delete from t;
586
588
-- 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;
588
591
explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
589
592
QUERY PLAN
590
593
---------------------------------
@@ -705,17 +708,17 @@ select * from t left join (select * from (select * from t order by a) v order by
705
708
rollback;
706
709
-- Test EXPLAIN ANALYZE with both fullsort and presorted groups.
707
710
select 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
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
710
713
Limit (actual rows=70 loops=1)
711
714
-> Incremental Sort (actual rows=70 loops=1)
712
715
Sort Key: t.a, t.b
713
716
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)
716
719
Sort Key: t.a
717
720
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)
719
722
(9 rows)
720
723
721
724
select 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
747
750
"Presorted Groups": { +
748
751
"Group Count": 5, +
749
752
"Sort Methods Used": [ +
753
+ "top-N heapsort", +
750
754
"quicksort" +
751
755
], +
752
756
"Sort Space Memory": { +
@@ -767,7 +771,8 @@ select explain_analyze_inc_sort_nodes_verify_invariants('select * from (select *
767
771
768
772
delete from t;
769
773
-- 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;
771
776
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
772
777
QUERY PLAN
773
778
---------------------------------
@@ -1082,7 +1087,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
1082
1087
1083
1088
delete from t;
1084
1089
-- 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;
1086
1092
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
1087
1093
QUERY PLAN
1088
1094
---------------------------------
0 commit comments