]> granicus.if.org Git - postgresql/commitdiff
Fix slot type issue for fuzzy distance index scan over out-of-core table AM.
authorAndres Freund <andres@anarazel.de>
Fri, 19 Apr 2019 18:25:48 +0000 (11:25 -0700)
committerAndres Freund <andres@anarazel.de>
Fri, 19 Apr 2019 18:42:37 +0000 (11:42 -0700)
For amcanreorderby scans the nodeIndexscan.c's reorder queue holds
heap tuples, but the underlying table likely does not. Before this fix
we'd return different types of slots, depending on whether the tuple
came from the reorder queue, or from the index + table.

While that could be fixed by signalling that the node doesn't return a
fixed type of slot, it seems better to instead remove the separate
slot for the reorder queue, and use ExecForceStoreHeapTuple() to store
tuples from the queue. It's not particularly common to need
reordering, after all.

This reverts most of the iss_ReorderQueueSlot related changes to
nodeIndexscan.c made in 1a0586de3657cd3, except that now
ExecForceStoreHeapTuple() is used instead of ExecStoreHeapTuple().

Noticed when testing zheap against the in-core version of tableam.

Author: Andres Freund

src/backend/executor/nodeIndexscan.c
src/include/nodes/execnodes.h

index 399ac0109c39e84462982513782e8b63b2b13668..c97eb60f779c17f2d4bae89cc2744605c873893c 100644 (file)
@@ -196,6 +196,8 @@ IndexNextWithReorder(IndexScanState *node)
 
        scandesc = node->iss_ScanDesc;
        econtext = node->ss.ps.ps_ExprContext;
+       slot = node->ss.ss_ScanTupleSlot;
+
        if (scandesc == NULL)
        {
                /*
@@ -231,7 +233,6 @@ IndexNextWithReorder(IndexScanState *node)
                 */
                if (!pairingheap_is_empty(node->iss_ReorderQueue))
                {
-                       slot = node->iss_ReorderQueueSlot;
                        topmost = (ReorderTuple *) pairingheap_first(node->iss_ReorderQueue);
 
                        if (node->iss_ReachedEnd ||
@@ -246,22 +247,20 @@ IndexNextWithReorder(IndexScanState *node)
                                tuple = reorderqueue_pop(node);
 
                                /* Pass 'true', as the tuple in the queue is a palloc'd copy */
-                               ExecStoreHeapTuple(tuple, slot, true);
+                               ExecForceStoreHeapTuple(tuple, slot, true);
                                return slot;
                        }
                }
                else if (node->iss_ReachedEnd)
                {
                        /* Queue is empty, and no more tuples from index.  We're done. */
-                       ExecClearTuple(node->iss_ReorderQueueSlot);
-                       return ExecClearTuple(node->ss.ss_ScanTupleSlot);
+                       return ExecClearTuple(slot);
                }
 
                /*
                 * Fetch next tuple from the index.
                 */
 next_indextuple:
-               slot = node->ss.ss_ScanTupleSlot;
                if (!index_getnext_slot(scandesc, ForwardScanDirection, slot))
                {
                        /*
@@ -354,8 +353,7 @@ next_indextuple:
         * if we get here it means the index scan failed so we are at the end of
         * the scan..
         */
-       ExecClearTuple(node->iss_ReorderQueueSlot);
-       return ExecClearTuple(node->ss.ss_ScanTupleSlot);
+       return ExecClearTuple(slot);
 }
 
 /*
@@ -807,8 +805,6 @@ ExecEndIndexScan(IndexScanState *node)
         */
        if (node->ss.ps.ps_ResultTupleSlot)
                ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
-       if (node->iss_ReorderQueueSlot)
-               ExecClearTuple(node->iss_ReorderQueueSlot);
        ExecClearTuple(node->ss.ss_ScanTupleSlot);
 
        /*
@@ -1055,13 +1051,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
                indexstate->iss_OrderByNulls = (bool *)
                        palloc(numOrderByKeys * sizeof(bool));
 
-               /* and initialize the reorder queue and the corresponding slot */
+               /* and initialize the reorder queue */
                indexstate->iss_ReorderQueue = pairingheap_allocate(reorderqueue_cmp,
                                                                                                                        indexstate);
-               indexstate->iss_ReorderQueueSlot =
-                       ExecAllocTableSlot(&estate->es_tupleTable,
-                                                          RelationGetDescr(currentRelation),
-                                                          &TTSOpsHeapTuple);
        }
 
        /*
index a5e4b7ef2e03e90300157133198899012ad5fc23..ff3328752e725035942e6631f3c6893f835b7334 100644 (file)
@@ -1387,7 +1387,6 @@ typedef struct IndexScanState
        bool       *iss_OrderByTypByVals;
        int16      *iss_OrderByTypLens;
        Size            iss_PscanLen;
-       TupleTableSlot *iss_ReorderQueueSlot;
 } IndexScanState;
 
 /* ----------------