PostgreSQL Source Code git master
|
#include "postgres.h"
#include "common/hashfn.h"
#include "executor/executor.h"
#include "executor/nodeMemoize.h"
#include "lib/ilist.h"
#include "miscadmin.h"
#include "utils/datum.h"
#include "utils/lsyscache.h"
#include "lib/simplehash.h"
Go to the source code of this file.
Data Structures | |
struct | MemoizeTuple |
struct | MemoizeKey |
struct | MemoizeEntry |
Macros | |
#define | MEMO_CACHE_LOOKUP 1 /* Attempt to perform a cache lookup */ |
#define | MEMO_CACHE_FETCH_NEXT_TUPLE 2 /* Get another tuple from the cache */ |
#define | MEMO_FILLING_CACHE 3 /* Read outer node to fill cache */ |
#define | MEMO_CACHE_BYPASS_MODE |
#define | MEMO_END_OF_SCAN 5 /* Ready for rescan */ |
#define | EMPTY_ENTRY_MEMORY_BYTES(e) |
#define | CACHE_TUPLE_BYTES(t) |
#define | SH_PREFIX memoize |
#define | SH_ELEMENT_TYPE MemoizeEntry |
#define | SH_KEY_TYPE MemoizeKey * |
#define | SH_SCOPE static inline |
#define | SH_DECLARE |
#define | SH_PREFIX memoize |
#define | SH_ELEMENT_TYPE MemoizeEntry |
#define | SH_KEY_TYPE MemoizeKey * |
#define | SH_KEY key |
#define | SH_HASH_KEY(tb, key) MemoizeHash_hash(tb, key) |
#define | SH_EQUAL(tb, a, b) MemoizeHash_equal(tb, a, b) |
#define | SH_SCOPE static inline |
#define | SH_STORE_HASH |
#define | SH_GET_HASH(tb, a) a->hash |
#define | SH_DEFINE |
Typedefs | |
typedef struct MemoizeTuple | MemoizeTuple |
typedef struct MemoizeKey | MemoizeKey |
typedef struct MemoizeEntry | MemoizeEntry |
#define CACHE_TUPLE_BYTES | ( | t | ) |
Definition at line 89 of file nodeMemoize.c.
#define EMPTY_ENTRY_MEMORY_BYTES | ( | e | ) |
Definition at line 86 of file nodeMemoize.c.
#define MEMO_CACHE_BYPASS_MODE |
Definition at line 81 of file nodeMemoize.c.
#define MEMO_CACHE_FETCH_NEXT_TUPLE 2 /* Get another tuple from the cache */ |
Definition at line 79 of file nodeMemoize.c.
Definition at line 78 of file nodeMemoize.c.
#define MEMO_END_OF_SCAN 5 /* Ready for rescan */ |
Definition at line 82 of file nodeMemoize.c.
#define MEMO_FILLING_CACHE 3 /* Read outer node to fill cache */ |
Definition at line 80 of file nodeMemoize.c.
#define SH_DECLARE |
Definition at line 129 of file nodeMemoize.c.
#define SH_DEFINE |
Definition at line 147 of file nodeMemoize.c.
#define SH_ELEMENT_TYPE MemoizeEntry |
Definition at line 139 of file nodeMemoize.c.
#define SH_ELEMENT_TYPE MemoizeEntry |
Definition at line 139 of file nodeMemoize.c.
#define SH_EQUAL | ( | tb, | |
a, | |||
b | |||
) | MemoizeHash_equal(tb, a, b) |
Definition at line 143 of file nodeMemoize.c.
Definition at line 146 of file nodeMemoize.c.
#define SH_HASH_KEY | ( | tb, | |
key | |||
) | MemoizeHash_hash(tb, key) |
Definition at line 142 of file nodeMemoize.c.
#define SH_KEY key |
Definition at line 141 of file nodeMemoize.c.
#define SH_KEY_TYPE MemoizeKey * |
Definition at line 140 of file nodeMemoize.c.
#define SH_KEY_TYPE MemoizeKey * |
Definition at line 140 of file nodeMemoize.c.
#define SH_PREFIX memoize |
Definition at line 138 of file nodeMemoize.c.
#define SH_PREFIX memoize |
Definition at line 138 of file nodeMemoize.c.
#define SH_SCOPE static inline |
Definition at line 144 of file nodeMemoize.c.
#define SH_SCOPE static inline |
Definition at line 144 of file nodeMemoize.c.
#define SH_STORE_HASH |
Definition at line 145 of file nodeMemoize.c.
typedef struct MemoizeEntry MemoizeEntry |
typedef struct MemoizeKey MemoizeKey |
typedef struct MemoizeTuple MemoizeTuple |
|
static |
Definition at line 282 of file nodeMemoize.c.
References Assert, MemoizeState::hashtable, size, and MemoizeState::tableContext.
Referenced by ExecMemoize().
|
static |
Definition at line 527 of file nodeMemoize.c.
References Assert, cache_reduce_memory(), MemoizeEntry::complete, dlist_move_tail(), dlist_push_tail(), EMPTY_ENTRY_MEMORY_BYTES, ExecCopySlotMinimalTuple(), MemoizeState::hashtable, MemoizeEntry::key, sort-test::key, MemoizeState::last_tuple, MemoizeState::lru_list, MemoizeKey::lru_node, MemoizeState::mem_limit, MemoizeState::mem_used, MemoryContextSwitchTo(), palloc(), prepare_probe_slot(), MemoizeState::probeslot, MemoizeEntry::status, MemoizeState::tableContext, MemoizeEntry::tuplehead, and unlikely.
Referenced by ExecMemoize().
|
static |
Definition at line 401 of file nodeMemoize.c.
References MemoizeInstrumentation::cache_evictions, dlist_init(), MemoizeState::entry, MemoizeState::hashtable, MemoizeState::last_tuple, MemoizeState::lru_list, MemoizeState::mem_used, MemoryContextReset(), MemoizeState::stats, and MemoizeState::tableContext.
Referenced by ExecReScanMemoize().
|
static |
Definition at line 439 of file nodeMemoize.c.
References Assert, MemoizeInstrumentation::cache_evictions, dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, elog, ERROR, MemoizeState::hashtable, MemoizeEntry::key, sort-test::key, MemoizeState::lru_list, MemoizeState::mem_limit, MemoizeInstrumentation::mem_peak, MemoizeState::mem_used, prepare_probe_slot(), remove_cache_entry(), MemoizeState::stats, and unlikely.
Referenced by cache_lookup(), and cache_store_tuple().
|
static |
Definition at line 624 of file nodeMemoize.c.
References Assert, cache_reduce_memory(), CACHE_TUPLE_BYTES, MemoizeState::entry, ExecCopySlotMinimalTuple(), MemoizeState::hashtable, MemoizeEntry::key, sort-test::key, MemoizeState::last_tuple, MemoizeState::mem_limit, MemoizeState::mem_used, MemoryContextSwitchTo(), MemoizeTuple::mintuple, MemoizeTuple::next, palloc(), prepare_probe_slot(), MemoizeEntry::status, MemoizeState::tableContext, and MemoizeEntry::tuplehead.
Referenced by ExecMemoize().
|
inlinestatic |
Definition at line 343 of file nodeMemoize.c.
References CACHE_TUPLE_BYTES, MemoizeEntry::complete, MemoizeState::mem_used, MemoizeTuple::mintuple, next, MemoizeTuple::next, pfree(), and MemoizeEntry::tuplehead.
Referenced by ExecMemoize(), and remove_cache_entry().
void ExecEndMemoize | ( | MemoizeState * | node | ) |
Definition at line 1079 of file nodeMemoize.c.
References Assert, CACHE_TUPLE_BYTES, EMPTY_ENTRY_MEMORY_BYTES, ExecEndNode(), MemoizeState::hashtable, i, IsParallelWorker, MemoizeInstrumentation::mem_peak, MemoizeState::mem_used, MemoryContextDelete(), MemoizeTuple::next, outerPlanState, ParallelWorkerNumber, MemoizeState::shared_info, SharedMemoizeInfo::sinstrument, MemoizeState::stats, MemoizeState::tableContext, and MemoizeEntry::tuplehead.
Referenced by ExecEndNode().
double ExecEstimateCacheEntryOverheadBytes | ( | double | ntuples | ) |
Definition at line 1171 of file nodeMemoize.c.
Referenced by cost_memoize_rescan().
MemoizeState * ExecInitMemoize | ( | Memoize * | node, |
EState * | estate, | ||
int | eflags | ||
) |
Definition at line 951 of file nodeMemoize.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, MemoizeState::binary_mode, Memoize::binary_mode, MemoizeState::cache_eq_expr, MemoizeState::collations, CurrentMemoryContext, dlist_init(), elog, MemoizeState::entry, ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecBuildParamSetEqual(), ExecCreateScanSlotFromOuterPlan(), ExecInitExpr(), ExecInitNode(), ExecInitResultTupleSlotTL(), ExecMemoize(), PlanState::ExecProcNode, ExecTypeFromExprList(), fmgr_info(), get_hash_memory_limit(), get_op_hash_functions(), get_opcode(), MemoizeState::hashfunctions, MemoizeState::hashkeydesc, MemoizeState::hashtable, i, MemoizeState::keyparamids, Memoize::keyparamids, MemoizeState::last_tuple, list_nth(), MemoizeState::lru_list, makeNode, MakeSingleTupleTableSlot(), MemoizeState::mem_limit, MemoizeState::mem_used, MEMO_CACHE_LOOKUP, MemoizeState::mstatus, MemoizeState::nkeys, Memoize::numKeys, outerPlan, outerPlanState, palloc(), MemoizeState::param_exprs, Memoize::param_exprs, pfree(), PlanState::plan, MemoizeState::probeslot, ScanState::ps, PlanState::ps_ProjInfo, MemoizeState::singlerow, Memoize::singlerow, MemoizeState::ss, PlanState::state, MemoizeState::stats, MemoizeState::tableContext, MemoizeState::tableslot, TTSOpsMinimalTuple, and TTSOpsVirtual.
Referenced by ExecInitNode().
|
static |
Definition at line 696 of file nodeMemoize.c.
References Assert, build_hash_table(), MemoizeInstrumentation::cache_hits, cache_lookup(), MemoizeInstrumentation::cache_misses, MemoizeInstrumentation::cache_overflows, cache_store_tuple(), castNode, CHECK_FOR_INTERRUPTS, MemoizeEntry::complete, elog, MemoizeState::entry, entry_purge_tuples(), ERROR, ExecCopySlot(), ExecProcNode(), ExecStoreMinimalTuple(), MemoizeState::hashtable, MemoizeState::last_tuple, likely, MEMO_CACHE_BYPASS_MODE, MEMO_CACHE_FETCH_NEXT_TUPLE, MEMO_CACHE_LOOKUP, MEMO_END_OF_SCAN, MEMO_FILLING_CACHE, MemoizeTuple::mintuple, MemoizeState::mstatus, MemoizeTuple::next, outerPlanState, PlanState::plan, ScanState::ps, PlanState::ps_ExprContext, PlanState::ps_ResultTupleSlot, ResetExprContext, MemoizeState::singlerow, MemoizeState::ss, MemoizeState::stats, TupIsNull, MemoizeEntry::tuplehead, and unlikely.
Referenced by ExecInitMemoize().
void ExecMemoizeEstimate | ( | MemoizeState * | node, |
ParallelContext * | pcxt | ||
) |
Definition at line 1189 of file nodeMemoize.c.
References add_size(), ParallelContext::estimator, PlanState::instrument, mul_size(), ParallelContext::nworkers, ScanState::ps, shm_toc_estimate_chunk, shm_toc_estimate_keys, size, and MemoizeState::ss.
Referenced by ExecParallelEstimate().
void ExecMemoizeInitializeDSM | ( | MemoizeState * | node, |
ParallelContext * | pcxt | ||
) |
Definition at line 1210 of file nodeMemoize.c.
References PlanState::instrument, SharedMemoizeInfo::num_workers, ParallelContext::nworkers, PlanState::plan, Plan::plan_node_id, ScanState::ps, MemoizeState::shared_info, shm_toc_allocate(), shm_toc_insert(), size, MemoizeState::ss, and ParallelContext::toc.
Referenced by ExecParallelInitializeDSM().
void ExecMemoizeInitializeWorker | ( | MemoizeState * | node, |
ParallelWorkerContext * | pwcxt | ||
) |
Definition at line 1235 of file nodeMemoize.c.
References PlanState::plan, Plan::plan_node_id, ScanState::ps, MemoizeState::shared_info, shm_toc_lookup(), MemoizeState::ss, and ParallelWorkerContext::toc.
Referenced by ExecParallelInitializeWorker().
void ExecMemoizeRetrieveInstrumentation | ( | MemoizeState * | node | ) |
Definition at line 1248 of file nodeMemoize.c.
References SharedMemoizeInfo::num_workers, palloc(), MemoizeState::shared_info, and size.
Referenced by ExecParallelRetrieveInstrumentation().
void ExecReScanMemoize | ( | MemoizeState * | node | ) |
Definition at line 1139 of file nodeMemoize.c.
References bms_nonempty_difference(), cache_purge_all(), MemoizeState::entry, ExecReScan(), MemoizeState::keyparamids, MemoizeState::last_tuple, MEMO_CACHE_LOOKUP, MemoizeState::mstatus, outerPlan, and outerPlanState.
Referenced by ExecReScan().
|
static |
Definition at line 220 of file nodeMemoize.c.
References CompactAttribute::attbyval, CompactAttribute::attlen, MemoizeState::binary_mode, MemoizeState::cache_eq_expr, datum_image_eq(), ExecQual(), ExecStoreMinimalTuple(), i, MemoryContextSwitchTo(), MemoizeState::nkeys, MemoizeKey::params, MemoizeState::probeslot, ScanState::ps, PlanState::ps_ExprContext, slot_getallattrs(), MemoizeState::ss, MemoizeState::tableslot, and TupleDescCompactAttr().
|
static |
Definition at line 157 of file nodeMemoize.c.
References CompactAttribute::attbyval, CompactAttribute::attlen, MemoizeState::binary_mode, MemoizeState::collations, datum_image_hash(), DatumGetUInt32(), FunctionCall1Coll(), MemoizeState::hashfunctions, i, MemoryContextSwitchTo(), murmurhash32(), MemoizeState::nkeys, pg_rotate_left32(), MemoizeState::probeslot, ScanState::ps, PlanState::ps_ExprContext, MemoizeState::ss, and TupleDescCompactAttr().
|
inlinestatic |
Definition at line 301 of file nodeMemoize.c.
References ExprContext::ecxt_per_tuple_memory, ExecClearTuple(), ExecEvalExpr(), ExecStoreMinimalTuple(), ExecStoreVirtualTuple(), i, sort-test::key, MemoryContextSwitchTo(), MemoizeState::nkeys, MemoizeState::param_exprs, MemoizeState::probeslot, ScanState::ps, PlanState::ps_ExprContext, slot_getallattrs(), MemoizeState::ss, MemoizeState::tableslot, TupleTableSlot::tts_isnull, and TupleTableSlot::tts_values.
Referenced by cache_lookup(), cache_reduce_memory(), and cache_store_tuple().
|
static |
Definition at line 373 of file nodeMemoize.c.
References dlist_delete(), EMPTY_ENTRY_MEMORY_BYTES, entry_purge_tuples(), MemoizeState::hashtable, MemoizeEntry::key, sort-test::key, MemoizeKey::lru_node, MemoizeState::mem_used, and pfree().
Referenced by cache_reduce_memory().