mirror of
https://github.com/postgres/postgres.git
synced 2025-12-16 16:42:29 +03:00
Teach SPGiST to store nulls and do whole-index scans.
This patch fixes the other major compatibility-breaking limitation of SPGiST, that it didn't store anything for null values of the indexed column, and so could not support whole-index scans or "x IS NULL" tests. The approach is to create a wholly separate search tree for the null entries, and use fixed "allTheSame" insertion and search rules when processing this tree, instead of calling the index opclass methods. This way the opclass methods do not need to worry about dealing with nulls. Catversion bump is for pg_am updates as well as the change in on-disk format of SPGiST indexes; there are some tweaks in SPGiST WAL records as well. Heavily rewritten version of a patch by Oleg Bartunov and Teodor Sigaev. (The original also stored nulls separately, but it reused GIN code to do so; which required undesirable compromises in the on-disk format, and would likely lead to bugs due to the GIN code being required to work in two very different contexts.)
This commit is contained in:
@@ -102,6 +102,8 @@ CREATE TABLE quad_point_tbl AS
|
||||
INSERT INTO quad_point_tbl
|
||||
SELECT '(333.0,400.0)'::point FROM generate_series(1,1000);
|
||||
|
||||
INSERT INTO quad_point_tbl VALUES (NULL), (NULL), (NULL);
|
||||
|
||||
CREATE INDEX sp_quad_ind ON quad_point_tbl USING spgist (p);
|
||||
|
||||
CREATE TABLE kd_point_tbl AS SELECT * FROM quad_point_tbl;
|
||||
@@ -172,6 +174,12 @@ SELECT * FROM point_tbl WHERE f1 IS NOT NULL ORDER BY f1 <-> '0,1';
|
||||
|
||||
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
|
||||
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
|
||||
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NOT NULL;
|
||||
|
||||
SELECT count(*) FROM quad_point_tbl;
|
||||
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p <@ box '(200,200,1000,1000)';
|
||||
|
||||
SELECT count(*) FROM quad_point_tbl WHERE box '(200,200,1000,1000)' @> p;
|
||||
@@ -305,6 +313,18 @@ EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
|
||||
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NOT NULL;
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NOT NULL;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl;
|
||||
SELECT count(*) FROM quad_point_tbl;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p <@ box '(200,200,1000,1000)';
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p <@ box '(200,200,1000,1000)';
|
||||
@@ -422,6 +442,18 @@ EXPLAIN (COSTS OFF)
|
||||
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
|
||||
SELECT * FROM point_tbl WHERE f1 <@ '(-10,-10),(10,10)':: box ORDER BY f1 <-> '0,1';
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NULL;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NOT NULL;
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p IS NOT NULL;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl;
|
||||
SELECT count(*) FROM quad_point_tbl;
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p <@ box '(200,200,1000,1000)';
|
||||
SELECT count(*) FROM quad_point_tbl WHERE p <@ box '(200,200,1000,1000)';
|
||||
|
||||
Reference in New Issue
Block a user