From d314f406891a138b115c51e6fb0dfa221203774a Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 10 Feb 2026 18:28:04 +1100 Subject: [PATCH v20260210] VCI - changes to postgres core --- src/backend/access/heap/heapam.c | 13 ++ src/backend/access/heap/heapam_handler.c | 4 + src/backend/access/heap/heapam_visibility.c | 6 + src/backend/access/transam/xlogfuncs.c | 1 + src/backend/access/transam/xlogrecovery.c | 18 ++- src/backend/catalog/dependency.c | 7 ++ src/backend/catalog/index.c | 33 +++++- src/backend/commands/explain.c | 24 +++- src/backend/commands/tablecmds.c | 125 ++++++++++++++++++++ src/backend/commands/vacuum.c | 16 +++ src/backend/executor/execAmi.c | 2 + src/backend/executor/execExpr.c | 6 +- src/backend/executor/execExprInterp.c | 36 ++++++ src/backend/executor/execProcnode.c | 1 + src/backend/executor/execScan.c | 2 +- src/backend/executor/nodeCustom.c | 16 +++ src/backend/executor/nodeModifyTable.c | 10 ++ src/backend/jit/llvm/llvmjit_expr.c | 12 ++ src/backend/jit/llvm/llvmjit_types.c | 2 + src/backend/nodes/gen_node_support.pl | 56 +++++++-- src/backend/optimizer/path/allpaths.c | 17 +++ src/backend/optimizer/plan/createplan.c | 4 +- src/backend/storage/ipc/procarray.c | 3 +- src/backend/utils/adt/timestamp.c | 18 +-- src/backend/utils/cache/relcache.c | 66 +++++++++++ src/bin/pg_dump/common.c | 1 + src/bin/pg_dump/pg_dump.c | 33 +++++- src/bin/pg_dump/pg_dump.h | 1 + src/include/access/heapam.h | 4 + src/include/access/xlogrecovery.h | 3 + src/include/catalog/dependency.h | 3 + src/include/catalog/index.h | 2 + src/include/commands/explain.h | 4 + src/include/commands/tablecmds.h | 6 + src/include/datatype/timestamp.h | 22 ++++ src/include/executor/execExpr.h | 16 +++ src/include/executor/nodeModifyTable.h | 2 + src/include/nodes/extensible.h | 4 + src/include/nodes/params.h | 2 + src/include/nodes/plannodes.h | 3 + src/include/optimizer/planner.h | 2 + src/include/utils/relcache.h | 5 + src/include/utils/snapshot.h | 10 ++ 43 files changed, 577 insertions(+), 44 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 3004964ab7f..caedeea0e03 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -54,6 +54,7 @@ #include "utils/spccache.h" #include "utils/syscache.h" +void (*add_index_delete_hook) (Relation indexRelation, const ItemPointerData *heap_tid, TransactionId xmin) = NULL; static HeapTuple heap_prepare_insert(Relation relation, HeapTuple tup, TransactionId xid, CommandId cid, int options); @@ -2859,6 +2860,7 @@ heap_delete(Relation relation, const ItemPointerData *tid, bool all_visible_cleared = false; HeapTuple old_key_tuple = NULL; /* replica identity of the tuple */ bool old_key_copied = false; + TransactionId old_xmin; Assert(ItemPointerIsValid(tid)); @@ -3105,6 +3107,8 @@ l1: xid, LockTupleExclusive, true, &new_xmax, &new_infomask, &new_infomask2); + old_xmin = HeapTupleHeaderGetXmin(tp.t_data); + START_CRIT_SECTION(); /* @@ -3250,6 +3254,9 @@ l1: if (old_key_tuple != NULL && old_key_copied) heap_freetuple(old_key_tuple); + if (add_index_delete_hook) + add_index_delete_hook(relation, tid, old_xmin); + return TM_Ok; } @@ -3352,6 +3359,7 @@ heap_update(Relation relation, const ItemPointerData *otid, HeapTuple newtup, infomask2_old_tuple, infomask_new_tuple, infomask2_new_tuple; + TransactionId old_xmin; Assert(ItemPointerIsValid(otid)); @@ -3798,6 +3806,8 @@ l2: &xmax_old_tuple, &infomask_old_tuple, &infomask2_old_tuple); + old_xmin = HeapTupleHeaderGetRawXmin(oldtup.t_data); + /* * And also prepare an Xmax value for the new copy of the tuple. If there * was no xmax previously, or there was one but all lockers are now gone, @@ -4281,6 +4291,9 @@ l2: bms_free(modified_attrs); bms_free(interesting_attrs); + if (add_index_delete_hook) + add_index_delete_hook(relation, otid, old_xmin); + return TM_Ok; } diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index cbef73e5d4b..b9d5cfb4c3e 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -46,6 +46,9 @@ #include "utils/builtins.h" #include "utils/rel.h" +/* Preserve the original heap tuple that is passed to callback in heapam_index_build_range_scan() */ +HeapTuple IndexHeapTuple; + static void reform_and_rewrite_tuple(HeapTuple tuple, Relation OldHeap, Relation NewHeap, Datum *values, bool *isnull, RewriteState rwstate); @@ -1672,6 +1675,7 @@ heapam_index_build_range_scan(Relation heapRelation, * some index AMs want to do further processing on the data first. So * pass the values[] and isnull[] arrays, instead. */ + IndexHeapTuple = heapTuple; if (HeapTupleIsHeapOnly(heapTuple)) { diff --git a/src/backend/access/heap/heapam_visibility.c b/src/backend/access/heap/heapam_visibility.c index 75ae268d753..de645474988 100644 --- a/src/backend/access/heap/heapam_visibility.c +++ b/src/backend/access/heap/heapam_visibility.c @@ -78,6 +78,8 @@ #include "utils/builtins.h" #include "utils/snapmgr.h" +bool (*add_snapshot_satisfies_hook) (HeapTuple tup, Snapshot snapshot, Buffer buffer) = NULL; + /* * SetHintBits() @@ -1670,6 +1672,10 @@ HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer) return HeapTupleSatisfiesHistoricMVCC(htup, snapshot, buffer); case SNAPSHOT_NON_VACUUMABLE: return HeapTupleSatisfiesNonVacuumable(htup, snapshot, buffer); + case SNAPSHOT_VCI_WOS2ROS: + case SNAPSHOT_VCI_LOCALROS: + if (add_snapshot_satisfies_hook) + return add_snapshot_satisfies_hook(htup, snapshot, buffer); } return false; /* keep compiler quiet */ diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index 2efe4105efb..783156ad2c5 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -607,6 +607,7 @@ pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS) statestr = "not paused"; break; case RECOVERY_PAUSE_REQUESTED: + case RECOVERY_VCI_PAUSE_REQUESTED: statestr = "pause requested"; break; case RECOVERY_PAUSED: diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 4fc37a031d9..712e697d6bf 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -2969,7 +2969,8 @@ recoveryPausesHere(bool endOfRecovery) ereport(LOG, (errmsg("pausing at the end of recovery"), errhint("Execute pg_wal_replay_resume() to promote."))); - else + /* If pause requested by VCI, the log is not output. */ + else if (GetRecoveryPauseState() != RECOVERY_VCI_PAUSE_REQUESTED) ereport(LOG, (errmsg("recovery has paused"), errhint("Execute pg_wal_replay_resume() to continue."))); @@ -3135,6 +3136,18 @@ SetRecoveryPause(bool recoveryPause) ConditionVariableBroadcast(&XLogRecoveryCtl->recoveryNotPausedCV); } +/* Set the recovery pause requested for VCI. */ +void +SetVciRecoveryPause(void) +{ + SpinLockAcquire(&XLogRecoveryCtl->info_lck); + + if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_NOT_PAUSED) + XLogRecoveryCtl->recoveryPauseState = RECOVERY_VCI_PAUSE_REQUESTED; + + SpinLockRelease(&XLogRecoveryCtl->info_lck); +} + /* * Confirm the recovery pause by setting the recovery pause state to * RECOVERY_PAUSED. @@ -3144,7 +3157,8 @@ ConfirmRecoveryPaused(void) { /* If recovery pause is requested then set it paused */ SpinLockAcquire(&XLogRecoveryCtl->info_lck); - if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_PAUSE_REQUESTED) + if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_PAUSE_REQUESTED || + XLogRecoveryCtl->recoveryPauseState == RECOVERY_VCI_PAUSE_REQUESTED) XLogRecoveryCtl->recoveryPauseState = RECOVERY_PAUSED; SpinLockRelease(&XLogRecoveryCtl->info_lck); } diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index f89267f0342..2102bfe2d7f 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -86,6 +86,7 @@ #include "utils/lsyscache.h" #include "utils/syscache.h" +bool (*add_drop_relation_hook) (const ObjectAddress *object, int flags) = NULL; /* * Deletion processing requires additional state for each ObjectAddress that @@ -1407,6 +1408,12 @@ doDeletion(const ObjectAddress *object, int flags) { char relKind = get_rel_relkind(object->objectId); + if (add_drop_relation_hook) + { + if (add_drop_relation_hook(object, flags)) + break; + } + if (relKind == RELKIND_INDEX || relKind == RELKIND_PARTITIONED_INDEX) { diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 43de42ce39e..e822ab626e5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -133,6 +133,7 @@ static void ResetReindexProcessing(void); static void SetReindexPending(List *indexes); static void RemoveReindexPending(Oid indexOid); +bool (*add_reindex_index_hook) (Relation) = NULL; /* * relationHasPrimaryKey @@ -342,12 +343,17 @@ ConstructTupleDescriptor(Relation heapRelation, /* Simple index column */ const FormData_pg_attribute *from; - Assert(atnum > 0); /* should've been caught above */ - if (atnum > natts) /* safety check */ elog(ERROR, "invalid column number %d", atnum); - from = TupleDescAttr(heapTupDesc, - AttrNumberGetAttrOffset(atnum)); + if (atnum > 0) + { + from = TupleDescAttr(heapTupDesc, + AttrNumberGetAttrOffset(atnum)); + } + else + { + from = SystemAttributeDefinition(atnum); + } to->atttypid = from->atttypid; to->attlen = from->attlen; @@ -3690,6 +3696,25 @@ reindex_index(const ReindexStmt *stmt, Oid indexId, return; } + if (add_reindex_index_hook) + { + if (!add_reindex_index_hook(iRel)) + { + RemoveReindexPending(RelationGetRelid(iRel)); + + /* Roll back any GUC changes */ + AtEOXact_GUC(false, save_nestlevel); + + /* Restore userid and security context */ + SetUserIdAndSecContext(save_userid, save_sec_context); + + /* Close rels, but keep locks */ + index_close(iRel, NoLock); + table_close(heapRelation, NoLock); + return; + } + } + if (progress) pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID, iRel->rd_rel->relam); diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index b7bb111688c..9a6360ecc48 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -1210,6 +1210,7 @@ ExplainPreScanNode(PlanState *planstate, Bitmapset **rels_used) ((ForeignScan *) plan)->fs_base_relids); break; case T_CustomScan: + case T_CustomPlanMarkPos: *rels_used = bms_add_members(*rels_used, ((CustomScan *) plan)->custom_relids); break; @@ -1513,6 +1514,7 @@ ExplainNode(PlanState *planstate, List *ancestors, } break; case T_CustomScan: + case T_CustomPlanMarkPos: sname = "Custom Scan"; custom_name = ((CustomScan *) plan)->methods->CustomName; if (custom_name) @@ -1676,10 +1678,18 @@ ExplainNode(PlanState *planstate, List *ancestors, ExplainScanTarget((Scan *) plan, es); break; case T_ForeignScan: - case T_CustomScan: if (((Scan *) plan)->scanrelid > 0) ExplainScanTarget((Scan *) plan, es); break; + case T_CustomScan: + case T_CustomPlanMarkPos: + { + CustomScanState *css = (CustomScanState *) planstate; + + if (css->methods->ExplainCustomPlanTargetRel) + css->methods->ExplainCustomPlanTargetRel(css, es); + } + break; case T_IndexScan: { IndexScan *indexscan = (IndexScan *) plan; @@ -2151,6 +2161,7 @@ ExplainNode(PlanState *planstate, List *ancestors, show_foreignscan_info((ForeignScanState *) planstate, es); break; case T_CustomScan: + case T_CustomPlanMarkPos: { CustomScanState *css = (CustomScanState *) planstate; @@ -2412,6 +2423,7 @@ ExplainNode(PlanState *planstate, List *ancestors, "Subquery", NULL, es); break; case T_CustomScan: + case T_CustomPlanMarkPos: ExplainCustomChildren((CustomScanState *) planstate, ancestors, es); break; @@ -4436,6 +4448,7 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es) case T_TidRangeScan: case T_ForeignScan: case T_CustomScan: + case T_CustomPlanMarkPos: case T_ModifyTable: /* Assert it's on a real relation */ Assert(rte->rtekind == RTE_RELATION); @@ -5117,3 +5130,12 @@ ExplainFlushWorkersState(ExplainState *es) pfree(wstate->worker_state_save); pfree(wstate); } + +void +ExplainPropertySortGroupKeys(PlanState *planstate, const char *qlabel, + int nkeys, AttrNumber *keycols, + List *ancestors, ExplainState *es) +{ + show_sort_group_keys(planstate, qlabel, nkeys, 0, keycols, + NULL, NULL, NULL, ancestors, es); +} diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f976c0e5c7e..a26b087afb8 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -110,6 +110,10 @@ #include "utils/typcache.h" #include "utils/usercontext.h" +bool (*add_alter_tablespace_hook) (Relation rel) = NULL; +void (*add_alter_table_change_owner_hook) (Oid relOid, char relKind, Oid newOwnerId) = NULL; +void (*add_alter_table_change_schema_hook) (Oid relOid, char relKind, Oid newNspOid) = NULL; + /* * ON COMMIT action list */ @@ -16324,6 +16328,9 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lock /* If it has dependent sequences, recurse to change them too */ change_owner_recurse_to_sequences(relationOid, newOwnerId, lockmode); + + if (add_alter_table_change_owner_hook) + add_alter_table_change_owner_hook(relationOid, tuple_class->relkind, newOwnerId); } InvokeObjectPostAlterHook(RelationRelationId, relationOid, 0); @@ -16873,6 +16880,112 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, } table_close(pgclass, RowExclusiveLock); + + /* + * Look up the index's access method, save the OID of its handler function + */ + if (rel->rd_rel->relam) + { + Form_pg_am aform; + HeapTuple amtuple; + + amtuple = SearchSysCache1(AMOID, ObjectIdGetDatum(rel->rd_rel->relam)); + if (!HeapTupleIsValid(amtuple)) + elog(ERROR, "cache lookup failed for access method %u", + rel->rd_rel->relam); + aform = (Form_pg_am) GETSTRUCT(amtuple); + + if (strcmp(NameStr(aform->amname), "vci") == 0) + + /* + * if((rel->rd_am) && (strcmp(NameStr(rel->rd_am->amname), "vci") + * == 0)) + */ + { + Relation depRel, + viewRel; + Oid vci_relid, + viewrelid; + ScanKeyData key; + SysScanDesc scan; + HeapTuple tup; + + depRel = table_open(DependRelationId, AccessShareLock); + vci_relid = RelationGetRelid(rel); + ScanKeyInit(&key, + Anum_pg_depend_refobjid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(vci_relid)); + scan = systable_beginscan(depRel, DependReferenceIndexId, true, + NULL, 1, &key); + while (HeapTupleIsValid((tup = systable_getnext(scan)))) + { + Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup); + + /* Retrieve objid of the internal function */ + if (depform->classid == RelationRelationId) + { + viewrelid = depform->objid; + viewRel = table_open(viewrelid, AccessExclusiveLock); + pgclass = table_open(RelationRelationId, RowExclusiveLock); + tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(viewrelid)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for relation %u", viewrelid); + + datum = (Datum) 0; + + /* Generate new proposed reloptions (text array) */ + newOptions = transformRelOptions(datum, defList, NULL, validnsps, false, + operation == AT_ResetRelOptions); + + (void) view_reloptions(newOptions, true); + + /* + * All we need do here is update the pg_class row; the new + * options will be propagated into relcaches during + * post-commit cache inval. + */ + memset(repl_val, 0, sizeof(repl_val)); + memset(repl_null, false, sizeof(repl_null)); + memset(repl_repl, false, sizeof(repl_repl)); + + if (newOptions != (Datum) 0) + repl_val[Anum_pg_class_reloptions - 1] = newOptions; + else + repl_null[Anum_pg_class_reloptions - 1] = true; + + repl_repl[Anum_pg_class_reloptions - 1] = true; + + newtuple = heap_modify_tuple(tuple, RelationGetDescr(pgclass), + repl_val, repl_null, repl_repl); + + /* + * simple_heap_update(pgclass, &newtuple->t_self, + * newtuple); + * + * CatalogUpdateIndexes(pgclass, newtuple); + */ + /* Perform actual update */ + CatalogTupleUpdate(pgclass, &newtuple->t_self, newtuple); + InvokeObjectPostAlterHook(RelationRelationId, viewrelid, 0); + + heap_freetuple(newtuple); + + ReleaseSysCache(tuple); + + table_close(pgclass, RowExclusiveLock); + table_close(viewRel, AccessExclusiveLock); + + } + } + + systable_endscan(scan); + + table_close(depRel, AccessShareLock); + } + + ReleaseSysCache(amtuple); + } } /* @@ -16894,6 +17007,15 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode) */ rel = relation_open(tableOid, lockmode); + if (add_alter_tablespace_hook) + { + if (add_alter_tablespace_hook(rel)) + { + relation_close(rel, NoLock); + return; + } + } + /* Check first if relation can be moved to new tablespace */ if (!CheckRelationTableSpaceMove(rel, newTableSpace)) { @@ -19143,6 +19265,9 @@ AlterRelationNamespaceInternal(Relation classRel, Oid relOid, { add_exact_object_address(&thisobj, objsMoved); + if (add_alter_table_change_schema_hook) + add_alter_table_change_schema_hook(relOid, classForm->relkind, newNspOid); + InvokeObjectPostAlterHook(RelationRelationId, relOid, 0); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 03932f45c8a..b0c3910239d 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -131,6 +131,8 @@ static double compute_parallel_delay(void); static VacOptValue get_vacoptval_from_boolean(DefElem *def); static bool vac_tid_reaped(ItemPointer itemptr, void *state); +bool (*add_skip_vacuum_hook) (Relation rel) = NULL; + /* * GUC check function to ensure GUC value specified is within the allowable * range. @@ -2130,6 +2132,20 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams params, return false; } + /* + * Silently ignore if it's a VCI internal table. + */ + if (add_skip_vacuum_hook) + { + if (add_skip_vacuum_hook(rel)) + { + relation_close(rel, lmode); + PopActiveSnapshot(); + CommitTransactionCommand(); + return false; + } + } + /* * Silently ignore tables that are temp tables of other backends --- * trying to vacuum these will lead to great unhappiness, since their diff --git a/src/backend/executor/execAmi.c b/src/backend/executor/execAmi.c index 90a68c0d156..0c05e92c795 100644 --- a/src/backend/executor/execAmi.c +++ b/src/backend/executor/execAmi.c @@ -437,6 +437,7 @@ ExecSupportsMarkRestore(Path *pathnode) return true; case T_CustomScan: + case T_CustomPlanMarkPos: if (castNode(CustomPath, pathnode)->flags & CUSTOMPATH_SUPPORT_MARK_RESTORE) return true; return false; @@ -563,6 +564,7 @@ ExecSupportsBackwardScan(Plan *node) return ExecSupportsBackwardScan(((SubqueryScan *) node)->subplan); case T_CustomScan: + case T_CustomPlanMarkPos: if (((CustomScan *) node)->flags & CUSTOMPATH_SUPPORT_BACKWARD_SCAN) return true; return false; diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index 088eca24021..db8c24dd221 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -68,7 +68,6 @@ typedef struct ExprSetupInfo List *multiexpr_subplans; } ExprSetupInfo; -static void ExecReadyExpr(ExprState *state); static void ExecInitExprRec(Expr *node, ExprState *state, Datum *resv, bool *resnull); static void ExecInitFunc(ExprEvalStep *scratch, Expr *node, List *args, @@ -77,7 +76,6 @@ static void ExecInitFunc(ExprEvalStep *scratch, Expr *node, List *args, static void ExecInitSubPlanExpr(SubPlan *subplan, ExprState *state, Datum *resv, bool *resnull); -static void ExecCreateExprSetupSteps(ExprState *state, Node *node); static void ExecPushExprSetupSteps(ExprState *state, ExprSetupInfo *info); static bool expr_setup_walker(Node *node, ExprSetupInfo *info); static bool ExecComputeSlotInfo(ExprState *state, ExprEvalStep *op); @@ -898,7 +896,7 @@ ExecCheck(ExprState *state, ExprContext *econtext) * Therefore this should be used instead of directly calling * ExecReadyInterpretedExpr(). */ -static void +void ExecReadyExpr(ExprState *state) { if (jit_compile_expr(state)) @@ -2872,7 +2870,7 @@ ExecInitSubPlanExpr(SubPlan *subplan, * Add expression steps performing setup that's needed before any of the * main execution of the expression. */ -static void +void ExecCreateExprSetupSteps(ExprState *state, Node *node) { ExprSetupInfo info = {0, 0, 0, 0, 0, NIL}; diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 61ff5ddc74c..08799df50ea 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -188,6 +188,21 @@ static pg_attribute_always_inline void ExecAggPlainTransByRef(AggState *aggstate int setno); static char *ExecGetJsonValueItemString(JsonbValue *item, bool *resnull); +ExprEvalVar_hook_type ExprEvalVar_hook = NULL; +ExprEvalParam_hook_type ExprEvalParam_hook = NULL; +void +VciExprEvalVarHook(ExprState *state, ExprEvalStep *op, ExprContext *econtext) +{ + Assert(ExprEvalVar_hook != NULL); + (*ExprEvalVar_hook) (state, op, econtext); +} +void +VciExprEvalParamHook(ExprState *state, ExprEvalStep *op, ExprContext *econtext) +{ + Assert(ExprEvalParam_hook != NULL); + (*ExprEvalParam_hook) (state, op, econtext); +} + /* * ScalarArrayOpExprHashEntry * Hash table entry type used during EEOP_HASHED_SCALARARRAYOP @@ -592,6 +607,8 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) &&CASE_EEOP_AGG_PRESORTED_DISTINCT_MULTI, &&CASE_EEOP_AGG_ORDERED_TRANS_DATUM, &&CASE_EEOP_AGG_ORDERED_TRANS_TUPLE, + &&CASE_EEOP_VCI_VAR, + &&CASE_EEOP_VCI_PARAM_EXEC, &&CASE_EEOP_LAST }; @@ -2265,6 +2282,25 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) EEO_NEXT(); } + EEO_CASE(EEOP_VCI_VAR) + { + /* TO-do */ + Assert(ExprEvalVar_hook != NULL); + (*ExprEvalVar_hook) (state, op, econtext); + + EEO_NEXT(); + } + + EEO_CASE(EEOP_VCI_PARAM_EXEC) + { + /* To-do */ + Assert(ExprEvalParam_hook != NULL); + (*ExprEvalParam_hook) (state, op, econtext); + + EEO_NEXT(); + } + + EEO_CASE(EEOP_LAST) { /* unreachable */ diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c index 7e40b852517..443fb9de501 100644 --- a/src/backend/executor/execProcnode.c +++ b/src/backend/executor/execProcnode.c @@ -287,6 +287,7 @@ ExecInitNode(Plan *node, EState *estate, int eflags) break; case T_CustomScan: + case T_CustomPlanMarkPos: result = (PlanState *) ExecInitCustomScan((CustomScan *) node, estate, eflags); break; diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index 9f68be17b99..fd7c3284833 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -139,7 +139,7 @@ ExecScanReScan(ScanState *node) */ if (IsA(node->ps.plan, ForeignScan)) relids = ((ForeignScan *) node->ps.plan)->fs_base_relids; - else if (IsA(node->ps.plan, CustomScan)) + else if (IsA(node->ps.plan, CustomScan) || IsA(node->ps.plan, CustomPlanMarkPos)) relids = ((CustomScan *) node->ps.plan)->custom_relids; else elog(ERROR, "unexpected scan node: %d", diff --git a/src/backend/executor/nodeCustom.c b/src/backend/executor/nodeCustom.c index a9ad5af6a98..4170d3874f4 100644 --- a/src/backend/executor/nodeCustom.c +++ b/src/backend/executor/nodeCustom.c @@ -49,6 +49,22 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags) css->ss.ps.state = estate; css->ss.ps.ExecProcNode = ExecCustomScan; + if (strcmp(cscan->methods->CustomName, "VCI Scan") == 0 || + strcmp(cscan->methods->CustomName, "VCI Sort") == 0 || + strcmp(cscan->methods->CustomName, "VCI Aggregate") == 0 || + strcmp(cscan->methods->CustomName, "VCI HashAggregate") == 0 || + strcmp(cscan->methods->CustomName, "VCI GroupAggregate") == 0 || + strcmp(cscan->methods->CustomName, "VCI Gather") == 0) + { + /* + * The callback of custom-scan provider applies the final + * initialization of the custom-scan-state node according to its + * logic. + */ + css->methods->BeginCustomScan(css, estate, eflags); + return css; + } + /* create expression context for node */ ExecAssignExprContext(estate, &css->ss.ps); diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index f5e9d369940..a8e54665df1 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -72,6 +72,7 @@ #include "utils/rel.h" #include "utils/snapmgr.h" +List *(*add_should_index_insert_hook) (ResultRelInfo *, TupleTableSlot *, ItemPointer, EState *) = NULL; typedef struct MTTargetRelLookup { @@ -2333,6 +2334,15 @@ ExecUpdateEpilogue(ModifyTableContext *context, UpdateContext *updateCxt, NULL, NIL, (updateCxt->updateIndexes == TU_Summarizing)); + /* + * VCI update hook + */ + else if (resultRelInfo->ri_NumIndices > 0 && !updateCxt->updateIndexes) + { + if (add_should_index_insert_hook) + recheckIndexes = add_should_index_insert_hook(resultRelInfo, slot, &slot->tts_tid, context->estate); + } + /* AFTER ROW UPDATE Triggers */ ExecARUpdateTriggers(context->estate, resultRelInfo, NULL, NULL, diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c index 650f1d42a93..0f53d084fd3 100644 --- a/src/backend/jit/llvm/llvmjit_expr.c +++ b/src/backend/jit/llvm/llvmjit_expr.c @@ -2940,6 +2940,18 @@ llvm_compile_expr(ExprState *state) LLVMBuildBr(b, opblocks[opno + 1]); break; + case EEOP_VCI_VAR: + build_EvalXFunc(b, mod, "VciExprEvalVarHook", + v_state, op, v_econtext); + LLVMBuildBr(b, opblocks[opno + 1]); + break; + + case EEOP_VCI_PARAM_EXEC: + build_EvalXFunc(b, mod, "VciExprEvalParamHook", + v_state, op, v_econtext); + LLVMBuildBr(b, opblocks[opno + 1]); + break; + case EEOP_LAST: Assert(false); break; diff --git a/src/backend/jit/llvm/llvmjit_types.c b/src/backend/jit/llvm/llvmjit_types.c index c8a1f841293..6562712b79e 100644 --- a/src/backend/jit/llvm/llvmjit_types.c +++ b/src/backend/jit/llvm/llvmjit_types.c @@ -182,4 +182,6 @@ void *referenced_functions[] = strlen, varsize_any, ExecInterpExprStillValid, + VciExprEvalParamHook, + VciExprEvalVarHook, }; diff --git a/src/backend/nodes/gen_node_support.pl b/src/backend/nodes/gen_node_support.pl index 4308751f787..d499258259b 100644 --- a/src/backend/nodes/gen_node_support.pl +++ b/src/backend/nodes/gen_node_support.pl @@ -153,6 +153,7 @@ my @extra_tags = qw( AllocSetContext GenerationContext SlabContext BumpContext TIDBitmap WindowObjectData + CustomPlanMarkPos ); # This is a regular node, but we skip parsing it from its header file @@ -679,10 +680,21 @@ foreach my $n (@node_types) my $struct_no_equal = (elem $n, @no_equal); next if $struct_no_copy && $struct_no_equal; - print $cfs "\t\tcase T_${n}:\n" - . "\t\t\tretval = _copy${n}(from);\n" - . "\t\t\tbreak;\n" - unless $struct_no_copy; + if($n eq 'CustomScan') + { + print $cfs "\t\tcase T_${n}:\n" + . "\t\tcase T_CustomPlanMarkPos:\n" + . "\t\t\tretval = _copy${n}(from);\n" + . "\t\t\tbreak;\n" + unless $struct_no_copy; + } + else + { + print $cfs "\t\tcase T_${n}:\n" + . "\t\t\tretval = _copy${n}(from);\n" + . "\t\t\tbreak;\n" + unless $struct_no_copy; + } print $efs "\t\tcase T_${n}:\n" . "\t\t\tretval = _equal${n}(a, b);\n" @@ -691,13 +703,35 @@ foreach my $n (@node_types) next if elem $n, @custom_copy_equal; - print $cff " -static $n * -_copy${n}(const $n *from) -{ -\t${n} *newnode = makeNode($n); - -" unless $struct_no_copy; + if ($n eq 'CustomScan') + { + print $cff "static $n *\n" + . "_copy${n}(const $n *from)\n" + . "{\n" + . "\tCustomScan *newnode;\n\n" + . "\tif (strcmp(from->methods->CustomName, \"VCI Scan\") == 0 || + strcmp(from->methods->CustomName, \"VCI Sort\") == 0 || + strcmp(from->methods->CustomName, \"VCI Aggregate\") == 0 || + strcmp(from->methods->CustomName, \"VCI HashAggregate\") == 0 || + strcmp(from->methods->CustomName, \"VCI GroupAggregate\") == 0 || + strcmp(from->methods->CustomName, \"VCI Gather\") == 0)\n" + . "\t{\n" + . "\t\tnewnode = from->methods->CopyCustomPlan(from);\n" + . "\t}\n" + . "\telse\n" + . "\t\tnewnode = makeNode(CustomScan);\n\n" + . "\t((Node *) newnode)->type = nodeTag(from);\n\n" unless $struct_no_copy; + } + else + { + print $cff + "static $n *\n" + . "_copy${n}(const $n *from)\n" + . "{\n" + ."\t${n} *newnode = makeNode($n);\n\n" + + unless $struct_no_copy; + } print $eff " static bool diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index b4581e54d93..b34264ecf7e 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -47,6 +47,7 @@ #include "partitioning/partbounds.h" #include "port/pg_bitutils.h" #include "rewrite/rewriteManip.h" +#include "utils/guc.h" #include "utils/lsyscache.h" #include "utils/selfuncs.h" @@ -822,6 +823,8 @@ static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) { Relids required_outer; + char *isVCIEnabled; + bool is_partition = false; /* * We don't support pushing join clauses into the quals of a seqscan, but @@ -847,6 +850,20 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) /* If appropriate, consider parallel sequential scan */ if (rel->consider_parallel && required_outer == NULL) create_plain_partial_paths(root, rel); + /**** + * Putting the isRelHasVCIIndex after the create_plain_partial_paths because + * want to enable oss parallelscan working on VCI tables but disable other + * gather plan like parallel_loop,parallel_agg working on VCI tables. + * Don't do this for partitioned tables or partitions as parallelscans on partitioned + * tables require gather plans + */ + if (isRelHasVCIIndex(rte->relid, &is_partition) && (bms_membership(root->all_baserels) == BMS_SINGLETON) && + !is_partition) + { + isVCIEnabled = GetConfigOptionByName("vci.enable", NULL, false); + if (strcmp(isVCIEnabled, "on") == 0) + rel->consider_parallel = false; + } /* Consider index scans */ create_index_paths(root, rel); diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index e5200f4b3ce..3d4f6cf4bd4 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -32,6 +32,7 @@ #include "optimizer/placeholder.h" #include "optimizer/plancat.h" #include "optimizer/planmain.h" +#include "optimizer/planner.h" #include "optimizer/prep.h" #include "optimizer/restrictinfo.h" #include "optimizer/subselect.h" @@ -172,7 +173,6 @@ static Node *fix_indexqual_operand(Node *node, IndexOptInfo *index, int indexcol static List *get_switched_clauses(List *clauses, Relids outerrelids); static List *order_qual_clauses(PlannerInfo *root, List *clauses); static void copy_generic_path_info(Plan *dest, Path *src); -static void copy_plan_costsize(Plan *dest, Plan *src); static void label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples); static void label_incrementalsort_with_costsize(PlannerInfo *root, IncrementalSort *plan, @@ -5368,7 +5368,7 @@ copy_generic_path_info(Plan *dest, Path *src) * Copy cost and size info from a lower plan node to an inserted node. * (Most callers alter the info after copying it.) */ -static void +void copy_plan_costsize(Plan *dest, Plan *src) { dest->disabled_nodes = src->disabled_nodes; diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 301f54fb5a8..322dbce9ce7 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -1922,7 +1922,8 @@ GlobalVisHorizonKindForRel(Relation rel) Assert(!rel || rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_MATVIEW || - rel->rd_rel->relkind == RELKIND_TOASTVALUE); + rel->rd_rel->relkind == RELKIND_TOASTVALUE || + rel->rd_rel->relkind == RELKIND_INDEX); if (rel == NULL || rel->rd_rel->relisshared || RecoveryInProgress()) return VISHORIZON_SHARED; diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 8deb2369471..c7e9715ca8e 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -24,6 +24,7 @@ #include "catalog/pg_type.h" #include "common/int.h" #include "common/int128.h" +#include "datatype/timestamp.h" #include "funcapi.h" #include "libpq/pqformat.h" #include "miscadmin.h" @@ -73,19 +74,6 @@ typedef struct pg_tz *attimezone; } generate_series_timestamptz_fctx; -/* - * The transition datatype for interval aggregates is declared as internal. - * It's a pointer to an IntervalAggState allocated in the aggregate context. - */ -typedef struct IntervalAggState -{ - int64 N; /* count of finite intervals processed */ - Interval sumX; /* sum of finite intervals processed */ - /* These counts are *not* included in N! Use IA_TOTAL_COUNT() as needed */ - int64 pInfcount; /* count of +infinity intervals */ - int64 nInfcount; /* count of -infinity intervals */ -} IntervalAggState; - #define IA_TOTAL_COUNT(ia) \ ((ia)->N + (ia)->pInfcount + (ia)->nInfcount) @@ -3484,7 +3472,7 @@ interval_larger(PG_FUNCTION_ARGS) PG_RETURN_INTERVAL_P(result); } -static void +void finite_interval_pl(const Interval *span1, const Interval *span2, Interval *result) { Assert(!INTERVAL_NOT_FINITE(span1)); @@ -3963,7 +3951,7 @@ in_range_interval_interval(PG_FUNCTION_ARGS) * context. When the state data needs to be allocated in the current memory * context, we use palloc0 directly e.g. interval_avg_deserialize(). */ -static IntervalAggState * +IntervalAggState * makeIntervalAggState(FunctionCallInfo fcinfo) { IntervalAggState *state; diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 6b634c9fff1..e6e9f67d3a4 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -92,6 +92,8 @@ #define RELCACHE_INIT_FILEMAGIC 0x573266 /* version ID value */ +bool (*add_skip_vci_index_hook) (Relation rel) = NULL; + /* * Whether to bother checking if relation cache memory needs to be freed * eagerly. See also RelationBuildDesc() and pg_config_manual.h. @@ -5384,6 +5386,16 @@ restart: indexDesc = index_open(indexOid, AccessShareLock); + if (add_skip_vci_index_hook) + { + if (add_skip_vci_index_hook(indexDesc)) + { + /* Skip if Index is VCI index */ + index_close(indexDesc, AccessShareLock); + continue; + } + } + /* * Extract index expressions and index predicate. Note: Don't use * RelationGetIndexExpressions()/RelationGetIndexPredicate(), because @@ -6962,6 +6974,60 @@ unlink_initfile(const char *initfilename, int elevel) } } +bool +isRelHasVCIIndex(Oid relid, bool *is_partition) +{ + ListCell *l; + Relation relation; + + bool hasVCI = false; + + *is_partition = false; + relation = table_open(relid, NoLock); + + if ((relation->rd_rel->relispartition == true) || relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + *is_partition = true; + + if (relation->rd_rel->relhasindex) + { + List *indexoidlist; + + indexoidlist = RelationGetIndexList(relation); + + foreach(l, indexoidlist) + { + Oid relam; + Oid indexoid = lfirst_oid(l); + Relation indexRelation; + Form_pg_am aform; + HeapTuple amtuple; + + indexRelation = index_open(indexoid, AccessShareLock); + relam = indexRelation->rd_rel->relam; + + amtuple = SearchSysCache1(AMOID, ObjectIdGetDatum(relam)); + if (!HeapTupleIsValid(amtuple)) + elog(ERROR, "cache lookup failed for access method %u", + relam); + aform = (Form_pg_am) GETSTRUCT(amtuple); + + if (strcmp(NameStr(aform->amname), "vci") == 0) + { + hasVCI = true; + } + + ReleaseSysCache(amtuple); + index_close(indexRelation, AccessShareLock); + + if (hasVCI) + break; + } + } + + table_close(relation, NoLock); + return hasVCI; +} + /* * ResourceOwner callbacks */ diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 349b47c8e29..8969eadc61d 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -668,6 +668,7 @@ AssignDumpId(DumpableObject *dobj) dobj->dependencies = NULL; dobj->nDeps = 0; dobj->allocDeps = 0; + dobj->isvciview = false; /* default assumption */ /* Add object to dumpIdMap[], enlarging that array if need be */ while (dobj->dumpId >= allocedDumpIds) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2c3754d020f..ddc86387f91 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -8643,6 +8643,17 @@ getRules(Archive *fout) ruleinfo[i].ev_enabled = *(PQgetvalue(res, i, i_ev_enabled)); if (ruleinfo[i].ruletable) { + /* + * isvciview is set to true when the table is a VCI internal relation. The + * judgement is done by the logic in vci_isVciRelation function + */ + if ((ruleinfo[i].ruletable->relkind == RELKIND_MATVIEW || + ruleinfo[i].ruletable->relkind == RELKIND_VIEW) && + !strcmp(ruleinfo[i].ruletable->dobj.name, ruleinfo[i].dobj.name)) + { + ruleinfo[i].ruletable->dobj.isvciview = true; + } + /* * If the table is a view or materialized view, force its ON * SELECT rule to be sorted before the view itself --- this @@ -17110,8 +17121,9 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo) int j, k; - /* We had better have loaded per-column details about this table */ - Assert(tbinfo->interesting); + /* Do not dump VCI internal relations */ + if (tbinfo->dobj.isvciview) + return; qrelname = pg_strdup(fmtId(tbinfo->dobj.name)); qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo)); @@ -20422,12 +20434,27 @@ addBoundaryDependencies(DumpableObject **dobjs, int numObjs, case DO_FDW: case DO_FOREIGN_SERVER: case DO_TRANSFORM: + + /* + * Do not add dependency for VCI internal relations to suppress dependency + * loop message + */ + if (dobj->isvciview) + break; /* Pre-data objects: must come before the pre-data boundary */ addObjectDependency(preDataBound, dobj->dumpId); break; + case DO_LARGE_OBJECT: + + /* + * Do not add dependency for VCI internal relations to suppress dependency + * loop message + */ + if (dobj->isvciview) + break; + /* fallthrough */ case DO_TABLE_DATA: case DO_SEQUENCE_SET: - case DO_LARGE_OBJECT: case DO_LARGE_OBJECT_DATA: /* Data objects: must come between the boundaries */ addObjectDependency(dobj, preDataBound->dumpId); diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index 4c4b14e5fc7..bc31c66aa03 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -159,6 +159,7 @@ typedef struct _dumpableObject DumpId *dependencies; /* dumpIds of objects this one depends on */ int nDeps; /* number of valid dependencies */ int allocDeps; /* allocated size of dependencies[] */ + bool isvciview; /* this table is a vci internal relation */ } DumpableObject; /* diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 3c0961ab36b..6fb77b44083 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -430,6 +430,10 @@ extern void log_heap_prune_and_freeze(Relation relation, Buffer buffer, OffsetNumber *dead, int ndead, OffsetNumber *unused, int nunused); +extern PGDLLIMPORT void (*add_index_delete_hook) (Relation indexRelation, const ItemPointerData *heap_tid, TransactionId xmin); +extern PGDLLIMPORT bool (*add_snapshot_satisfies_hook) (HeapTuple htup, Snapshot snapshot, Buffer buffer); +extern PGDLLIMPORT bool (*add_skip_vacuum_hook) (Relation rel); + /* in heap/vacuumlazy.c */ extern void heap_vacuum_rel(Relation rel, const VacuumParams params, BufferAccessStrategy bstrategy); diff --git a/src/include/access/xlogrecovery.h b/src/include/access/xlogrecovery.h index f926d89cb2f..3276ea2732e 100644 --- a/src/include/access/xlogrecovery.h +++ b/src/include/access/xlogrecovery.h @@ -56,6 +56,7 @@ typedef enum RecoveryPauseState RECOVERY_NOT_PAUSED, /* pause not requested */ RECOVERY_PAUSE_REQUESTED, /* pause requested, but not yet paused */ RECOVERY_PAUSED, /* recovery is paused */ + RECOVERY_VCI_PAUSE_REQUESTED, /* pause requested for VCI query */ } RecoveryPauseState; /* User-settable GUC parameters */ @@ -161,6 +162,8 @@ extern void WakeupRecovery(void); extern void StartupRequestWalReceiverRestart(void); extern void XLogRequestWalReceiverReply(void); +extern void SetVciRecoveryPause(void); + extern void RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue); extern void xlog_outdesc(StringInfo buf, XLogReaderState *record); diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h index 2f3c1eae3c7..96232cc9cb0 100644 --- a/src/include/catalog/dependency.h +++ b/src/include/catalog/dependency.h @@ -238,4 +238,7 @@ extern void shdepDropOwned(List *roleids, DropBehavior behavior); extern void shdepReassignOwned(List *roleids, Oid newrole); +/* vci index original hook*/ +extern PGDLLIMPORT bool (*add_drop_relation_hook) (const ObjectAddress *object, int flags); + #endif /* DEPENDENCY_H */ diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index b259c4141ed..3eb0193d88d 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -175,6 +175,8 @@ extern void RestoreReindexState(const void *reindexstate); extern void IndexSetParentIndex(Relation partitionIdx, Oid parentOid); +extern PGDLLIMPORT bool (*add_reindex_index_hook) (Relation); +extern PGDLLIMPORT HeapTuple IndexHeapTuple; /* * itemptr_encode - Encode ItemPointer as int64/int8 diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h index 86226f8db70..07347a882e9 100644 --- a/src/include/commands/explain.h +++ b/src/include/commands/explain.h @@ -81,4 +81,8 @@ extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc); extern void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen); +extern void ExplainPropertySortGroupKeys(PlanState *planstate, const char *qlabel, + int nkeys, AttrNumber *keycols, + List *ancestors, ExplainState *es); + #endif /* EXPLAIN_H */ diff --git a/src/include/commands/tablecmds.h b/src/include/commands/tablecmds.h index ed38b311ddf..cbcbd62a133 100644 --- a/src/include/commands/tablecmds.h +++ b/src/include/commands/tablecmds.h @@ -108,4 +108,10 @@ extern void RangeVarCallbackOwnsRelation(const RangeVar *relation, extern bool PartConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint); +extern PGDLLIMPORT bool (*add_alter_tablespace_hook) (Relation rel); +extern PGDLLIMPORT void (*add_alter_table_change_owner_hook) (Oid relOid, + char relKind, Oid newOwnerId); +extern PGDLLIMPORT void (*add_alter_table_change_schema_hook) (Oid relOid, + char relKind, Oid newNspOid); + #endif /* TABLECMDS_H */ diff --git a/src/include/datatype/timestamp.h b/src/include/datatype/timestamp.h index 45683678a47..9ac05186180 100644 --- a/src/include/datatype/timestamp.h +++ b/src/include/datatype/timestamp.h @@ -15,6 +15,11 @@ #ifndef DATATYPE_TIMESTAMP_H #define DATATYPE_TIMESTAMP_H +#ifndef FRONTEND +#include "postgres.h" +#include "fmgr.h" +#endif + /* * Timestamp represents absolute time. * @@ -87,6 +92,23 @@ struct pg_itm_in int tm_year; }; +#ifndef FRONTEND +/* + * The transition datatype for interval aggregates is declared as internal. + * It's a pointer to an IntervalAggState allocated in the aggregate context. + */ +typedef struct IntervalAggState +{ + int64 N; /* count of finite intervals processed */ + Interval sumX; /* sum of finite intervals processed */ + /* These counts are *not* included in N! Use IA_TOTAL_COUNT() as needed */ + int64 pInfcount; /* count of +infinity intervals */ + int64 nInfcount; /* count of -infinity intervals */ +} IntervalAggState; + +extern IntervalAggState *makeIntervalAggState(FunctionCallInfo fcinfo); +extern void finite_interval_pl(const Interval *span1, const Interval *span2, Interval *result); +#endif /* Limits on the "precision" option (typmod) for these data types */ #define MAX_TIMESTAMP_PRECISION 6 diff --git a/src/include/executor/execExpr.h b/src/include/executor/execExpr.h index aa9b361fa31..d8abcdb1eb1 100644 --- a/src/include/executor/execExpr.h +++ b/src/include/executor/execExpr.h @@ -292,6 +292,8 @@ typedef enum ExprEvalOp EEOP_AGG_ORDERED_TRANS_DATUM, EEOP_AGG_ORDERED_TRANS_TUPLE, + EEOP_VCI_VAR, + EEOP_VCI_PARAM_EXEC, /* non-existent operation, used e.g. to check array lengths */ EEOP_LAST } ExprEvalOp; @@ -338,6 +340,7 @@ typedef struct ExprEvalStep /* but it's just the normal (negative) attr number for SYSVAR */ int attnum; Oid vartype; /* type OID of variable */ + PlanState *vci_parent_planstate; VarReturningType varreturningtype; /* return old/new/default */ } var; @@ -424,6 +427,7 @@ typedef struct ExprEvalStep { int paramid; /* numeric ID for parameter */ Oid paramtype; /* OID of parameter's datatype */ + Plan *vci_parent_plan; } param; /* for EEOP_PARAM_CALLBACK */ @@ -902,6 +906,18 @@ extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext); extern void ExecEvalSysVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot); +extern void ExecCreateExprSetupSteps(ExprState *state, Node *node); +extern void ExecReadyExpr(ExprState *state); + +typedef void (*ExprEvalVar_hook_type) (ExprState *state, ExprEvalStep *op, + ExprContext *econtext); +extern PGDLLIMPORT ExprEvalVar_hook_type ExprEvalVar_hook; + +typedef void (*ExprEvalParam_hook_type) (ExprState *state, ExprEvalStep *op, + ExprContext *econtext); +extern PGDLLIMPORT ExprEvalParam_hook_type ExprEvalParam_hook; +extern void VciExprEvalVarHook(ExprState *state, ExprEvalStep *op, ExprContext *econtext); +extern void VciExprEvalParamHook(ExprState *state, ExprEvalStep *op, ExprContext *econtext); extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext); diff --git a/src/include/executor/nodeModifyTable.h b/src/include/executor/nodeModifyTable.h index f6070e1cdf3..85c542dd1ca 100644 --- a/src/include/executor/nodeModifyTable.h +++ b/src/include/executor/nodeModifyTable.h @@ -27,6 +27,8 @@ extern ModifyTableState *ExecInitModifyTable(ModifyTable *node, EState *estate, extern void ExecEndModifyTable(ModifyTableState *node); extern void ExecReScanModifyTable(ModifyTableState *node); +extern PGDLLIMPORT List *(*add_should_index_insert_hook) (ResultRelInfo *, TupleTableSlot *, ItemPointer, EState *); + extern void ExecInitMergeTupleSlots(ModifyTableState *mtstate, ResultRelInfo *resultRelInfo); diff --git a/src/include/nodes/extensible.h b/src/include/nodes/extensible.h index 517db95c4a3..772096c3822 100644 --- a/src/include/nodes/extensible.h +++ b/src/include/nodes/extensible.h @@ -115,6 +115,7 @@ typedef struct CustomScanMethods /* Create execution state (CustomScanState) from a CustomScan plan node */ Node *(*CreateCustomScanState) (CustomScan *cscan); + struct CustomScan *(*CopyCustomPlan) (const struct CustomScan *from); } CustomScanMethods; /* @@ -155,6 +156,9 @@ typedef struct CustomExecMethods void (*ExplainCustomScan) (CustomScanState *node, List *ancestors, ExplainState *es); + void (*SetBoundCustomScan) (const LimitState *limit, + CustomScanState *cps); + void (*ExplainCustomPlanTargetRel) (CustomScanState *node, ExplainState *es); } CustomExecMethods; extern void RegisterCustomScanMethods(const CustomScanMethods *methods); diff --git a/src/include/nodes/params.h b/src/include/nodes/params.h index 2a2f00c76de..0af396466a8 100644 --- a/src/include/nodes/params.h +++ b/src/include/nodes/params.h @@ -19,6 +19,7 @@ typedef struct ExprState ExprState; typedef struct Param Param; typedef struct ParseState ParseState; +struct PlanState; /* * ParamListInfo @@ -165,5 +166,6 @@ extern ParamListInfo RestoreParamList(char **start_address); extern char *BuildParamLogString(ParamListInfo params, char **knownTextValues, int maxlen); extern void ParamsErrorCallback(void *arg); +typedef struct ExprState *(*ExecInitParam_hook_type) (Param *param, struct PlanState *parent); #endif /* PARAMS_H */ diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 4bc6fb5670e..a1d2a76cf93 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -214,6 +214,9 @@ typedef struct Plan /* OK to use as part of parallel plan? */ bool parallel_safe; + /* plan number (1-origin) in the Query */ + AttrNumber plan_no; + /* * information needed for asynchronous execution */ diff --git a/src/include/optimizer/planner.h b/src/include/optimizer/planner.h index ae3f7f2edb6..895981ccd0a 100644 --- a/src/include/optimizer/planner.h +++ b/src/include/optimizer/planner.h @@ -53,6 +53,8 @@ typedef void (*create_upper_paths_hook_type) (PlannerInfo *root, void *extra); extern PGDLLIMPORT create_upper_paths_hook_type create_upper_paths_hook; +extern void copy_plan_costsize(Plan *dest, Plan *src); + extern PlannedStmt *standard_planner(Query *parse, const char *query_string, int cursorOptions, diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 2700224939a..b823442982b 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -61,6 +61,8 @@ extern List *RelationGetDummyIndexExpressions(Relation relation); extern List *RelationGetIndexPredicate(Relation relation); extern bytea **RelationGetIndexAttOptions(Relation relation, bool copy); +extern bool isRelHasVCIIndex(Oid relid, bool *is_partition); + /* * Which set of columns to return by RelationGetIndexAttrBitmap. */ @@ -160,4 +162,7 @@ extern PGDLLIMPORT bool criticalRelcachesBuilt; /* should be used only by relcache.c and postinit.c */ extern PGDLLIMPORT bool criticalSharedRelcachesBuilt; +/* vci index original hook*/ +extern PGDLLIMPORT bool (*add_skip_vci_index_hook) (Relation rel); + #endif /* RELCACHE_H */ diff --git a/src/include/utils/snapshot.h b/src/include/utils/snapshot.h index 9766aabcad4..a0f69e0980f 100644 --- a/src/include/utils/snapshot.h +++ b/src/include/utils/snapshot.h @@ -112,6 +112,16 @@ typedef enum SnapshotType * horizon to use. */ SNAPSHOT_NON_VACUUMABLE, + + /* + * VCI WOS2ROS visible + */ + SNAPSHOT_VCI_WOS2ROS, + + /* + * VCI Local ROS visible + */ + SNAPSHOT_VCI_LOCALROS } SnapshotType; typedef struct SnapshotData *Snapshot; -- 2.47.3