diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-05-15 14:26:51 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-05-15 14:26:51 +0300 |
commit | 35fcb1b3d038a501f3f4c87c05630095abaaadab (patch) | |
tree | d67f36684fb18b8523e78f13c0a358b376f50d4b /src/include/nodes | |
parent | ecd222e770d352121590363ffdf981147a43e976 (diff) | |
download | postgresql-35fcb1b3d038a501f3f4c87c05630095abaaadab.tar.gz postgresql-35fcb1b3d038a501f3f4c87c05630095abaaadab.zip |
Allow GiST distance function to return merely a lower-bound.
The distance function can now set *recheck = false, like index quals. The
executor will then re-check the ORDER BY expressions, and use a queue to
reorder the results on the fly.
This makes it possible to do kNN-searches on polygons and circles, which
don't store the exact value in the index, but just a bounding box.
Alexander Korotkov and me
Diffstat (limited to 'src/include/nodes')
-rw-r--r-- | src/include/nodes/execnodes.h | 20 | ||||
-rw-r--r-- | src/include/nodes/plannodes.h | 10 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 5ad2cc23588..fcfe1107f92 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -17,6 +17,7 @@ #include "access/genam.h" #include "access/heapam.h" #include "executor/instrument.h" +#include "lib/pairingheap.h" #include "nodes/params.h" #include "nodes/plannodes.h" #include "utils/reltrigger.h" @@ -1262,6 +1263,7 @@ typedef struct * IndexScanState information * * indexqualorig execution state for indexqualorig expressions + * indexorderbyorig execution state for indexorderbyorig expressions * ScanKeys Skey structures for index quals * NumScanKeys number of ScanKeys * OrderByKeys Skey structures for index ordering operators @@ -1272,12 +1274,21 @@ typedef struct * RuntimeContext expr context for evaling runtime Skeys * RelationDesc index relation descriptor * ScanDesc index scan descriptor + * + * ReorderQueue tuples that need reordering due to re-check + * ReachedEnd have we fetched all tuples from index already? + * OrderByValues values of ORDER BY exprs of last fetched tuple + * OrderByNulls null flags for OrderByValues + * SortSupport for reordering ORDER BY exprs + * OrderByTypByVals is the datatype of order by expression pass-by-value? + * OrderByTypLens typlens of the datatypes of order by expressions * ---------------- */ typedef struct IndexScanState { ScanState ss; /* its first field is NodeTag */ List *indexqualorig; + List *indexorderbyorig; ScanKey iss_ScanKeys; int iss_NumScanKeys; ScanKey iss_OrderByKeys; @@ -1288,6 +1299,15 @@ typedef struct IndexScanState ExprContext *iss_RuntimeContext; Relation iss_RelationDesc; IndexScanDesc iss_ScanDesc; + + /* These are needed for re-checking ORDER BY expr ordering */ + pairingheap *iss_ReorderQueue; + bool iss_ReachedEnd; + Datum *iss_OrderByValues; + bool *iss_OrderByNulls; + SortSupport iss_SortSupport; + bool *iss_OrderByTypByVals; + int16 *iss_OrderByTypLens; } IndexScanState; /* ---------------- diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 1494b336c22..65f71d81705 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -311,8 +311,13 @@ typedef Scan SeqScan; * index column order. Only the expressions are provided, not the auxiliary * sort-order information from the ORDER BY SortGroupClauses; it's assumed * that the sort ordering is fully determinable from the top-level operators. - * indexorderbyorig is unused at run time, but is needed for EXPLAIN. - * (Note these fields are used for amcanorderbyop cases, not amcanorder cases.) + * indexorderbyorig is used at runtime to recheck the ordering, if the index + * cannot calculate an accurate ordering. It is also needed for EXPLAIN. + * + * indexorderbyops is an array of operators used to sort the ORDER BY + * expressions, used together with indexorderbyorig to recheck ordering at run + * time. (Note these fields are used for amcanorderbyop cases, not amcanorder + * cases.) * * indexorderdir specifies the scan ordering, for indexscans on amcanorder * indexes (for other indexes it should be "don't care"). @@ -326,6 +331,7 @@ typedef struct IndexScan List *indexqualorig; /* the same in original form */ List *indexorderby; /* list of index ORDER BY exprs */ List *indexorderbyorig; /* the same in original form */ + Oid *indexorderbyops; /* operators to sort ORDER BY exprs */ ScanDirection indexorderdir; /* forward or backward or don't care */ } IndexScan; |