-- Regular index with included columns CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); -- size is chosen to exceed page size and trigger actual truncation INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,8000) AS x; CREATEINDEX tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c2,c3); SELECT pg_get_indexdef(i.indexrelid) FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid WHERE i.indrelid = 'tbl_gist'::regclass ORDERBY c.relname; SELECT * FROM tbl_gist where c4 <@ box(point(1,1),point(10,10)); SET enable_bitmapscan TO off; EXPLAIN (costs off) SELECT * FROM tbl_gist where c4 <@ box(point(1,1),point(10,10)); SET enable_bitmapscan TOdefault; DROPTABLE tbl_gist;
/* *1.2.testCREATEINDEXwithinserts
*/
-- Regular index with included columns CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); -- size is chosen to exceed page size and trigger actual truncation CREATEINDEX tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c2,c3); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,8000) AS x; SELECT pg_get_indexdef(i.indexrelid) FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid WHERE i.indrelid = 'tbl_gist'::regclass ORDERBY c.relname; SELECT * FROM tbl_gist where c4 <@ box(point(1,1),point(10,10)); SET enable_bitmapscan TO off; EXPLAIN (costs off) SELECT * FROM tbl_gist where c4 <@ box(point(1,1),point(10,10)); SET enable_bitmapscan TOdefault; DROPTABLE tbl_gist;
/* *2.CREATEINDEXCONCURRENTLY
*/ CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,10) AS x; CREATEINDEX CONCURRENTLY tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c2,c3); SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl_gist'ORDERBY indexname; DROPTABLE tbl_gist;
/* *3.REINDEX
*/ CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,10) AS x; CREATEINDEX tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c3); SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl_gist'ORDERBY indexname;
REINDEX INDEX tbl_gist_idx; SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl_gist'ORDERBY indexname; ALTERTABLE tbl_gist DROPCOLUMN c1; SELECT indexdef FROM pg_indexes WHERE tablename = 'tbl_gist'ORDERBY indexname; DROPTABLE tbl_gist;
/* *4.Update,deletevaluesinindexedtable.
*/ CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,10) AS x; CREATEINDEX tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c3); UPDATE tbl_gist SET c1 = 100WHERE c1 = 2; UPDATE tbl_gist SET c1 = 1WHERE c1 = 3; DELETEFROM tbl_gist WHERE c1 = 5OR c3 = 12; DROPTABLE tbl_gist;
/* *5.Altercolumntype.
*/ CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,10) AS x; CREATEINDEX tbl_gist_idx ON tbl_gist using gist (c4) INCLUDE (c1,c3); ALTERTABLE tbl_gist ALTER c1 TYPE bigint; ALTERTABLE tbl_gist ALTER c3 TYPE bigint;
\d tbl_gist DROPTABLE tbl_gist;
/* *6.EXCLUDEconstraint.
*/ CREATETABLE tbl_gist (c1 int, c2 int, c3 int, c4 box, EXCLUDE USING gist (c4 WITH &&) INCLUDE (c1, c2, c3)); INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(x,x+1),point(2*x,2*x+1)) FROM generate_series(1,10) AS x; INSERTINTO tbl_gist SELECT x, 2*x, 3*x, box(point(3*x,2*x),point(3*x+1,2*x+1)) FROM generate_series(1,10) AS x; EXPLAIN (costs off) SELECT * FROM tbl_gist where c4 <@ box(point(1,1),point(10,10));
\d tbl_gist DROPTABLE tbl_gist;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 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.