-- ----------------------------------------------------------------------
|
-- GiST index through the CFS storage manager.
|
--
|
-- A GiST index on a CFS heap inherits the heap's compression policy, so the
|
-- GiST tree pages (internal + leaf) live in sidecar-compressed storage. This
|
-- covers fillfactor + buffering build options combined with CFS, VACUUM entry
|
-- deletion, containment search and KNN ordering through compressed pages. A
|
-- plain (uncompressed) mirror table is the oracle: CFS and plain must return
|
-- identical results.
|
--
|
-- Based on regress/sql/gist.sql, reduced to the build/vacuum/scan paths.
|
-- ----------------------------------------------------------------------
|
CREATE EXTENSION pg_buffercache;
|
|
-- CFS heap + plain mirror. fillfactor + buffering must coexist with the
|
-- inherited CFS policy in one reloptions list.
|
CREATE TABLE cfsgist_cfs (id int, p point) WITH (algorithm = 'lz4');
|
CREATE TABLE cfsgist_plain (id int, p point);
|
CREATE INDEX cfsgist_cfs_idx ON cfsgist_cfs USING gist (p)
|
WITH (buffering = on, fillfactor = 50);
|
CREATE INDEX cfsgist_plain_idx ON cfsgist_plain USING gist (p)
|
WITH (buffering = on, fillfactor = 50);
|
|
INSERT INTO cfsgist_cfs SELECT g, point(g * 0.1, g * 0.1) FROM generate_series(1, 5000) g;
|
INSERT INTO cfsgist_plain SELECT * FROM cfsgist_cfs;
|
|
SELECT cfs_relation_policy('cfsgist_cfs_idx'::regclass) AS policy,
|
cfs_relation_has_sidecars('cfsgist_cfs_idx'::regclass) AS has_sidecars;
|
|
-- VACUUM churn: delete scattered entries, then vacuum (GiST page recycling).
|
DELETE FROM cfsgist_cfs WHERE id % 3 = 0;
|
DELETE FROM cfsgist_plain WHERE id % 3 = 0;
|
VACUUM cfsgist_cfs;
|
VACUUM cfsgist_plain;
|
|
-- Evict the compressed GiST pages so scans read through CFS decompression.
|
CHECKPOINT;
|
SELECT buffers_evicted > 0 AS evicted_idx
|
FROM pg_buffercache_evict_relation('cfsgist_cfs_idx'::regclass);
|
SELECT buffers_evicted > 0 AS evicted_tbl
|
FROM pg_buffercache_evict_relation('cfsgist_cfs');
|
|
-- Containment search: CFS and plain must match.
|
SET enable_seqscan TO off;
|
SELECT count(*) AS cfs_cnt FROM cfsgist_cfs WHERE p <@ box(point(0,0), point(100,100));
|
RESET enable_seqscan;
|
SELECT count(*) AS plain_cnt FROM cfsgist_plain WHERE p <@ box(point(0,0), point(100,100));
|
|
-- KNN search: the ordered result set through compressed GiST pages must
|
-- match the plain result set (compare as sorted text to be order-insensitive
|
-- in the diff while still verifying the actual points).
|
SET enable_seqscan TO off;
|
SELECT (SELECT string_agg(p::text, ',' ORDER BY p <-> point(1,1))
|
FROM cfsgist_cfs WHERE p <@ box(point(0,0), point(50,50)))
|
= (SELECT string_agg(p::text, ',' ORDER BY p <-> point(1,1))
|
FROM cfsgist_plain WHERE p <@ box(point(0,0), point(50,50)))
|
AS knn_matches;
|
RESET enable_seqscan;
|
|
DROP TABLE cfsgist_cfs, cfsgist_plain;
|
DROP EXTENSION pg_buffercache;
|