MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecMemoize

Function ExecMemoize

src/backend/executor/nodeMemoize.c:667–907  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

665}
666
667static TupleTableSlot *
668ExecMemoize(PlanState *pstate)
669{
670 MemoizeState *node = castNode(MemoizeState, pstate);
671 PlanState *outerNode;
672 TupleTableSlot *slot;
673
674 switch (node->mstatus)
675 {
676 case MEMO_CACHE_LOOKUP:
677 {
678 MemoizeEntry *entry;
679 TupleTableSlot *outerslot;
680 bool found;
681
682 Assert(node->entry == NULL);
683
684 /*
685 * We're only ever in this state for the first call of the
686 * scan. Here we have a look to see if we've already seen the
687 * current parameters before and if we have already cached a
688 * complete set of records that the outer plan will return for
689 * these parameters.
690 *
691 * When we find a valid cache entry, we'll return the first
692 * tuple from it. If not found, we'll create a cache entry and
693 * then try to fetch a tuple from the outer scan. If we find
694 * one there, we'll try to cache it.
695 */
696
697 /* see if we've got anything cached for the current parameters */
698 entry = cache_lookup(node, &found);
699
700 if (found && entry->complete)
701 {
702 node->stats.cache_hits += 1; /* stats update */
703
704 /*
705 * Set last_tuple and entry so that the state
706 * MEMO_CACHE_FETCH_NEXT_TUPLE can easily find the next
707 * tuple for these parameters.
708 */
709 node->last_tuple = entry->tuplehead;
710 node->entry = entry;
711
712 /* Fetch the first cached tuple, if there is one */
713 if (entry->tuplehead)
714 {
715 node->mstatus = MEMO_CACHE_FETCH_NEXT_TUPLE;
716
717 slot = node->ss.ps.ps_ResultTupleSlot;
718 ExecStoreMinimalTuple(entry->tuplehead->mintuple,
719 slot, false);
720
721 return slot;
722 }
723
724 /* The cache entry is void of any tuples. */

Callers

nothing calls this directly

Calls 6

cache_lookupFunction · 0.85
ExecStoreMinimalTupleFunction · 0.85
entry_purge_tuplesFunction · 0.85
ExecProcNodeFunction · 0.85
cache_store_tupleFunction · 0.85
ExecCopySlotFunction · 0.85

Tested by

no test coverage detected