-- btree index -- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1 -- SELECT * FROM onek WHERE onek.unique1 < 10 ORDERBY onek.unique1;
-- -- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 -- SELECT onek.unique1, onek.stringu1 FROM onek WHERE onek.unique1 < 20 ORDERBY unique1 using >;
-- -- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 -- SELECT onek.unique1, onek.stringu1 FROM onek WHERE onek.unique1 > 980 ORDERBY stringu1 using <;
-- -- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | -- sort +1d -2 +0nr -1 -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 ORDERBY string4 using <, unique1 using >;
-- -- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | -- sort +1dr -2 +0n -1 -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 ORDERBY string4 using >, unique1 using <;
-- -- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | -- sort +0nr -1 +1d -2 -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 ORDERBY unique1 using >, string4 using <;
-- -- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | -- sort +0n -1 +1dr -2 -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 ORDERBY unique1 using <, string4 using >;
-- -- test partial btree indexes -- -- As of 7.2, planner probably won't pick an indexscan without stats, -- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan -- followed by sort, because that could hide index ordering problems. -- ANALYZE onek2;
SET enable_seqscan TO off; SET enable_bitmapscan TO off; SET enable_sort TO off;
-- -- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 -- SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10;
-- -- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 -- SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 < 20 ORDERBY unique1 using >;
-- -- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 -- SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 > 980;
-- -- Test some cases involving whole-row Var referencing a subquery -- select foo from (select1 offset 0) as foo; select foo from (selectnull offset 0) as foo; select foo from (select'xyzzy',1,null offset 0) as foo;
-- -- Test VALUES lists -- select * from onek, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) WHERE onek.unique1 = v.i and onek.stringu1 = v.j;
-- a more complex case -- looks like we're coding lisp :-) select * from onek,
(values ((select i from
(values(10000), (2), (389), (1000), (2000), ((select10029))) as foo(i) orderby i asclimit1))) bar (i) where onek.unique1 = bar.i;
-- try VALUES in a subquery select * from onek where (unique1,ten) in (values (1,1), (20,0), (99,9), (17,99)) orderby unique1;
-- VALUES is also legal as a standalone query or a set-operation member VALUES (1,2), (3,4+4), (7,77.7);
SELECT * FROM foo ORDERBY f1; SELECT * FROM foo ORDERBY f1 ASC; -- same thing SELECT * FROM foo ORDERBY f1 NULLS FIRST; SELECT * FROM foo ORDERBY f1 DESC; SELECT * FROM foo ORDERBY f1 DESC NULLS LAST;
-- check if indexscans do the right things CREATEINDEX fooi ON foo (f1); SET enable_sort = false;
SELECT * FROM foo ORDERBY f1; SELECT * FROM foo ORDERBY f1 NULLS FIRST; SELECT * FROM foo ORDERBY f1 DESC; SELECT * FROM foo ORDERBY f1 DESC NULLS LAST;
DROPINDEX fooi; CREATEINDEX fooi ON foo (f1 DESC);
SELECT * FROM foo ORDERBY f1; SELECT * FROM foo ORDERBY f1 NULLS FIRST; SELECT * FROM foo ORDERBY f1 DESC; SELECT * FROM foo ORDERBY f1 DESC NULLS LAST;
DROPINDEX fooi; CREATEINDEX fooi ON foo (f1 DESC NULLS LAST);
SELECT * FROM foo ORDERBY f1; SELECT * FROM foo ORDERBY f1 NULLS FIRST; SELECT * FROM foo ORDERBY f1 DESC; SELECT * FROM foo ORDERBY f1 DESC NULLS LAST;
-- -- Test planning of some cases with partial indexes --
-- partial index is usable explain (costs off) select * from onek2 where unique2 = 11and stringu1 = 'ATAAAA'; select * from onek2 where unique2 = 11and stringu1 = 'ATAAAA'; -- actually run the query with an analyze to use the partial index explain (costs off, analyzeon, timing off, summary off, buffers off) select * from onek2 where unique2 = 11and stringu1 = 'ATAAAA'; explain (costs off) select unique2 from onek2 where unique2 = 11and stringu1 = 'ATAAAA'; select unique2 from onek2 where unique2 = 11and stringu1 = 'ATAAAA'; -- partial index predicate implies clause, so no need for retest explain (costs off) select * from onek2 where unique2 = 11and stringu1 < 'B'; select * from onek2 where unique2 = 11and stringu1 < 'B'; explain (costs off) select unique2 from onek2 where unique2 = 11and stringu1 < 'B'; select unique2 from onek2 where unique2 = 11and stringu1 < 'B'; -- but if it's an update target, must retest anyway explain (costs off) select unique2 from onek2 where unique2 = 11and stringu1 < 'B'forupdate; select unique2 from onek2 where unique2 = 11and stringu1 < 'B'forupdate; -- partial index is not applicable explain (costs off) select unique2 from onek2 where unique2 = 11and stringu1 < 'C'; select unique2 from onek2 where unique2 = 11and stringu1 < 'C'; -- partial index implies clause, but bitmap scan must recheck predicate anyway SET enable_indexscan TO off; explain (costs off) select unique2 from onek2 where unique2 = 11and stringu1 < 'B'; select unique2 from onek2 where unique2 = 11and stringu1 < 'B';
RESET enable_indexscan; -- check multi-index cases too explain (costs off) select unique1, unique2 from onek2 where (unique2 = 11or unique1 = 0) and stringu1 < 'B'; select unique1, unique2 from onek2 where (unique2 = 11or unique1 = 0) and stringu1 < 'B'; explain (costs off) select unique1, unique2 from onek2 where (unique2 = 11and stringu1 < 'B') or unique1 = 0; select unique1, unique2 from onek2 where (unique2 = 11and stringu1 < 'B') or unique1 = 0;
-- -- Test some corner cases that have been known to confuse the planner --
-- ORDER BY on a constant doesn't really need any sorting SELECT1AS x ORDERBY x;
-- But ORDER BY on a set-valued expression does create function sillysrf(int) returns setof intas 'values (1),(10),(2),($1)' language sql immutable;
-- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict -- (see bug #5084) select * from (values (2),(null),(1)) v(k) where k = k orderby k; select * from (values (2),(null),(1)) v(k) where k = k;
-- Test partitioned tables with no partitions, which should be handled the -- same as the non-inheritance case when expanding its RTE. createtable list_parted_tbl (a int,b int) partition by list (a); createtable list_parted_tbl1 partition of list_parted_tbl forvaluesin (1) partition by list(b); explain (costs off) select * from list_parted_tbl; droptable list_parted_tbl;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.