@ -141,7 +141,8 @@ begin
end;
$$;
-- A single large group tested around each mode transition point.
insert into t(a, b) select 1, i from generate_series(1, 100) n(i);
insert into t(a, b) select i/100 + 1, i + 1 from generate_series(0, 999) n(i);
analyze t;
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
QUERY PLAN
---------------------------------
@ -456,7 +457,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
delete from t;
-- An initial large group followed by a small group.
insert into t(a, b) select (case when i < 50 then 1 else 2 end), i from generate_series(1, 100) n(i);
insert into t(a, b) select i/50 + 1, i + 1 from generate_series(0, 999) n(i);
analyze t;
explain (costs off) select * from (select * from t order by a) s order by a, b limit 55;
QUERY PLAN
---------------------------------
@ -521,7 +523,7 @@ select * from (select * from t order by a) s order by a, b limit 55;
1 | 47
1 | 48
1 | 49
2 | 50
1 | 50
2 | 51
2 | 52
2 | 53
@ -538,10 +540,10 @@ select explain_analyze_without_memory('select * from (select * from t order by a
Sort Key: t.a, t.b
Presorted Key: t.a
Full-sort Groups: 2 Sort Methods: top-N heapsort, quicksort Memory: avg=NNkB peak=NNkB
-> Sort (actual rows=100 loops=1)
-> Sort (actual rows=101 loops=1)
Sort Key: t.a
Sort Method: quicksort Memory: NNkB
-> Seq Scan on t (actual rows=100 loops=1)
-> Seq Scan on t (actual rows=1000 loops=1)
(9 rows)
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 *
delete from t;
-- An initial small group followed by a large group.
insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_series(1, 100) n(i);
insert into t(a, b) select (case when i < 5 then i else 9 end), i from generate_series(1, 1000) n(i);
analyze t;
explain (costs off) select * from (select * from t order by a) s order by a, b limit 70;
QUERY PLAN
---------------------------------
@ -705,17 +708,17 @@ select * from t left join (select * from (select * from t order by a) v order by
rollback;
-- Test EXPLAIN ANALYZE with both fullsort and presorted groups.
select explain_analyze_without_memory('select * from (select * from t order by a) s order by a, b limit 70');
explain_analyze_without_memory
-----------------------------------------------------------------------------------------------------------------------------------------------------
explain_analyze_without_memory
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (actual rows=70 loops=1)
-> Incremental Sort (actual rows=70 loops=1)
Sort Key: t.a, t.b
Presorted Key: t.a
Full-sort Groups: 1 Sort Method: quicksort Memory: avg=NNkB peak=NNkB Presorted Groups: 5 Sort Method: quicksort Memory: avg=NNkB peak=NNkB
-> Sort (actual rows=100 loops=1)
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
-> Sort (actual rows=1000 loops=1)
Sort Key: t.a
Sort Method: quicksort Memory: NNkB
-> Seq Scan on t (actual rows=100 loops=1)
-> Seq Scan on t (actual rows=1000 loops=1)
(9 rows)
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
"Presorted Groups": { +
"Group Count": 5, +
"Sort Methods Used": [ +
"top-N heapsort", +
"quicksort" +
], +
"Sort Space Memory": { +
@ -767,7 +771,8 @@ select explain_analyze_inc_sort_nodes_verify_invariants('select * from (select *
delete from t;
-- Small groups of 10 tuples each tested around each mode transition point.
insert into t(a, b) select i / 10, i from generate_series(1, 70) n(i);
insert into t(a, b) select i / 10, i from generate_series(1, 1000) n(i);
analyze t;
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
QUERY PLAN
---------------------------------
@ -1082,7 +1087,8 @@ select * from (select * from t order by a) s order by a, b limit 66;
delete from t;
-- Small groups of only 1 tuple each tested around each mode transition point.
insert into t(a, b) select i, i from generate_series(1, 70) n(i);
insert into t(a, b) select i, i from generate_series(1, 1000) n(i);
analyze t;
explain (costs off) select * from (select * from t order by a) s order by a, b limit 31;
QUERY PLAN
---------------------------------