mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Show sort ordering options in EXPLAIN output.
Up to now, EXPLAIN has contented itself with printing the sort expressions in a Sort or Merge Append plan node. This patch improves that by annotating the sort keys with COLLATE, DESC, USING, and/or NULLS FIRST/LAST whenever nondefault sort ordering options are used. The output is now a reasonably close approximation of an ORDER BY clause equivalent to the plan's ordering. Marius Timmer, Lukas Kreft, and Arne Scheffer; reviewed by Mike Blackwell. Some additional hacking by me.
This commit is contained in:
@ -735,7 +735,7 @@ explain (costs off)
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------
|
||||
Sort
|
||||
Sort Key: (generate_series(1, 3))
|
||||
Sort Key: (generate_series(1, 3)) DESC
|
||||
InitPlan 1 (returns $0)
|
||||
-> Limit
|
||||
-> Index Only Scan Backward using tenk1_unique2 on tenk1
|
||||
@ -784,7 +784,7 @@ explain (costs off)
|
||||
InitPlan 2 (returns $1)
|
||||
-> Limit
|
||||
-> Merge Append
|
||||
Sort Key: minmaxtest_1.f1
|
||||
Sort Key: minmaxtest_1.f1 DESC
|
||||
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_1
|
||||
Index Cond: (f1 IS NOT NULL)
|
||||
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest1_1
|
||||
@ -823,7 +823,7 @@ explain (costs off)
|
||||
InitPlan 2 (returns $1)
|
||||
-> Limit
|
||||
-> Merge Append
|
||||
Sort Key: minmaxtest_1.f1
|
||||
Sort Key: minmaxtest_1.f1 DESC
|
||||
-> Index Only Scan Backward using minmaxtesti on minmaxtest minmaxtest_1
|
||||
Index Cond: (f1 IS NOT NULL)
|
||||
-> Index Only Scan Backward using minmaxtest1i on minmaxtest1 minmaxtest1_1
|
||||
|
@ -603,6 +603,25 @@ ALTER TABLE collate_test22 ADD FOREIGN KEY (f2) REFERENCES collate_test20;
|
||||
RESET enable_seqscan;
|
||||
RESET enable_hashjoin;
|
||||
RESET enable_nestloop;
|
||||
-- EXPLAIN
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM collate_test10 ORDER BY x, y;
|
||||
QUERY PLAN
|
||||
----------------------------------------------
|
||||
Sort
|
||||
Sort Key: x COLLATE "C", y COLLATE "POSIX"
|
||||
-> Seq Scan on collate_test10
|
||||
(3 rows)
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM collate_test10 ORDER BY x DESC, y COLLATE "C" ASC NULLS FIRST;
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------
|
||||
Sort
|
||||
Sort Key: x COLLATE "C" DESC, y COLLATE "C" NULLS FIRST
|
||||
-> Seq Scan on collate_test10
|
||||
(3 rows)
|
||||
|
||||
-- 9.1 bug with useless COLLATE in an expression subject to length coercion
|
||||
CREATE TEMP TABLE vctable (f1 varchar(25));
|
||||
INSERT INTO vctable VALUES ('foo' COLLATE "C");
|
||||
|
@ -319,7 +319,7 @@ explain (costs off)
|
||||
-> Index Scan using ec1_expr4 on ec1 ec1_3
|
||||
-> Materialize
|
||||
-> Sort
|
||||
Sort Key: ec1.f1
|
||||
Sort Key: ec1.f1 USING <
|
||||
-> Index Scan using ec1_pkey on ec1
|
||||
Index Cond: (ff = 42::bigint)
|
||||
(20 rows)
|
||||
@ -376,7 +376,7 @@ explain (costs off)
|
||||
-> Index Scan using ec1_expr4 on ec1 ec1_3
|
||||
-> Materialize
|
||||
-> Sort
|
||||
Sort Key: ec1.f1
|
||||
Sort Key: ec1.f1 USING <
|
||||
-> Index Scan using ec1_pkey on ec1
|
||||
Index Cond: (ff = 42::bigint)
|
||||
(14 rows)
|
||||
|
@ -220,6 +220,15 @@ RESET enable_seqscan;
|
||||
RESET enable_hashjoin;
|
||||
RESET enable_nestloop;
|
||||
|
||||
|
||||
-- EXPLAIN
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM collate_test10 ORDER BY x, y;
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM collate_test10 ORDER BY x DESC, y COLLATE "C" ASC NULLS FIRST;
|
||||
|
||||
|
||||
-- 9.1 bug with useless COLLATE in an expression subject to length coercion
|
||||
|
||||
CREATE TEMP TABLE vctable (f1 varchar(25));
|
||||
|
Reference in New Issue
Block a user