mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Improve handling of NULLs in KNN-GiST and KNN-SP-GiST
This commit improves subject in two ways:
* It removes ugliness of 02f90879e7
, which stores distance values and null
flags in two separate arrays after GISTSearchItem struct. Instead we pack
both distance value and null flag in IndexOrderByDistance struct. Alignment
overhead should be negligible, because we typically deal with at most few
"col op const" expressions in ORDER BY clause.
* It fixes handling of "col op NULL" expression in KNN-SP-GiST. Now, these
expression are not passed to support functions, which can't deal with them.
Instead, NULL result is implicitly assumed. It future we may decide to
teach support functions to deal with NULL arguments, but current solution is
bugfix suitable for backpatch.
Reported-by: Nikita Glukhov
Discussion: https://postgr.es/m/826f57ee-afc7-8977-c44c-6111d18b02ec%40postgrespro.ru
Author: Nikita Glukhov
Reviewed-by: Alexander Korotkov
Backpatch-through: 9.4
This commit is contained in:
@ -555,6 +555,16 @@ WHERE seq.dist IS DISTINCT FROM idx.dist;
|
||||
---+------+---+---+------+---
|
||||
(0 rows)
|
||||
|
||||
-- check ORDER BY distance to NULL
|
||||
SELECT (SELECT p FROM kd_point_tbl ORDER BY p <-> pt LIMIT 1)
|
||||
FROM (VALUES (point '1,2'), (NULL), ('1234,5678')) pts(pt);
|
||||
p
|
||||
-------------
|
||||
(59,21)
|
||||
(9853,112)
|
||||
(1239,5647)
|
||||
(3 rows)
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
|
||||
QUERY PLAN
|
||||
|
@ -225,6 +225,11 @@ SELECT * FROM quad_point_tbl_ord_seq3 seq FULL JOIN kd_point_tbl_ord_idx3 idx
|
||||
ON seq.n = idx.n
|
||||
WHERE seq.dist IS DISTINCT FROM idx.dist;
|
||||
|
||||
-- check ORDER BY distance to NULL
|
||||
SELECT (SELECT p FROM kd_point_tbl ORDER BY p <-> pt LIMIT 1)
|
||||
FROM (VALUES (point '1,2'), (NULL), ('1234,5678')) pts(pt);
|
||||
|
||||
|
||||
EXPLAIN (COSTS OFF)
|
||||
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
|
||||
SELECT count(*) FROM radix_text_tbl WHERE t = 'P0123456789abcdef';
|
||||
|
Reference in New Issue
Block a user