diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2019-09-19 21:30:19 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2019-09-19 21:48:39 +0300 |
commit | 6cae9d2c10e151f741e7bc64a8b70bb2615c367c (patch) | |
tree | 1d2530905cfabaef098a1e1378097a0bb9c4ed2c /src/include/access/spgist_private.h | |
parent | 0a97edb12ec44f8d2d8828cbca6dd7639408ac88 (diff) | |
download | postgresql-6cae9d2c10e151f741e7bc64a8b70bb2615c367c.tar.gz postgresql-6cae9d2c10e151f741e7bc64a8b70bb2615c367c.zip |
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
Diffstat (limited to 'src/include/access/spgist_private.h')
-rw-r--r-- | src/include/access/spgist_private.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/include/access/spgist_private.h b/src/include/access/spgist_private.h index e0d1178f245..428e54bfbd2 100644 --- a/src/include/access/spgist_private.h +++ b/src/include/access/spgist_private.h @@ -169,8 +169,12 @@ typedef struct SpGistScanOpaqueData int numberOfKeys; /* number of index qualifier conditions */ ScanKey keyData; /* array of index qualifier descriptors */ int numberOfOrderBys; /* number of ordering operators */ + int numberOfNonNullOrderBys; /* number of ordering operators + * with non-NULL arguments */ ScanKey orderByData; /* array of ordering op descriptors */ Oid *orderByTypes; /* array of ordering op return types */ + int *nonNullOrderByOffsets; /* array of offset of non-NULL + * ordering keys in the original array */ Oid indexCollation; /* collation of index column */ /* Opclass defined functions: */ @@ -195,7 +199,9 @@ typedef struct SpGistScanOpaqueData bool recheckDistances[MaxIndexTuplesPerPage]; /* distance recheck * flags */ HeapTuple reconTups[MaxIndexTuplesPerPage]; /* reconstructed tuples */ - double *distances[MaxIndexTuplesPerPage]; /* distances (for recheck) */ + + /* distances (for recheck) */ + IndexOrderByDistance *distances[MaxIndexTuplesPerPage]; /* * Note: using MaxIndexTuplesPerPage above is a bit hokey since |