Skip to content

Commit 1647cae

Browse files
Peter SmithCommitfest Bot
authored andcommitted
VCI - changes to postgres core
1 parent 5173bfd commit 1647cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+664
-100
lines changed

src/backend/access/heap/heapam.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "utils/spccache.h"
5555
#include "utils/syscache.h"
5656

57+
void (*add_index_delete_hook) (Relation indexRelation, ItemPointer heap_tid, TransactionId xmin) = NULL;
5758

5859
static HeapTuple heap_prepare_insert(Relation relation, HeapTuple tup,
5960
TransactionId xid, CommandId cid, int options);
@@ -364,6 +365,9 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
364365
* results for a non-MVCC snapshot, the caller must hold some higher-level
365366
* lock that ensures the interesting tuple(s) won't change.)
366367
*/
368+
if (keep_startblock)
369+
goto skip_get_number_of_blocks;
370+
367371
if (scan->rs_base.rs_parallel != NULL)
368372
{
369373
bpscan = (ParallelBlockTableScanDesc) scan->rs_base.rs_parallel;
@@ -372,6 +376,8 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
372376
else
373377
scan->rs_nblocks = RelationGetNumberOfBlocks(scan->rs_base.rs_rd);
374378

379+
skip_get_number_of_blocks:
380+
375381
/*
376382
* If the table is large relative to NBuffers, use a bulk-read access
377383
* strategy and enable synchronized scanning (see syncscan.c). Although
@@ -2806,6 +2812,7 @@ heap_delete(Relation relation, ItemPointer tid,
28062812
bool all_visible_cleared = false;
28072813
HeapTuple old_key_tuple = NULL; /* replica identity of the tuple */
28082814
bool old_key_copied = false;
2815+
TransactionId old_xmin;
28092816

28102817
Assert(ItemPointerIsValid(tid));
28112818

@@ -3052,6 +3059,8 @@ heap_delete(Relation relation, ItemPointer tid,
30523059
xid, LockTupleExclusive, true,
30533060
&new_xmax, &new_infomask, &new_infomask2);
30543061

3062+
old_xmin = HeapTupleHeaderGetXmin(tp.t_data);
3063+
30553064
START_CRIT_SECTION();
30563065

30573066
/*
@@ -3197,6 +3206,9 @@ heap_delete(Relation relation, ItemPointer tid,
31973206
if (old_key_tuple != NULL && old_key_copied)
31983207
heap_freetuple(old_key_tuple);
31993208

3209+
if (add_index_delete_hook)
3210+
add_index_delete_hook(relation, tid, old_xmin);
3211+
32003212
return TM_Ok;
32013213
}
32023214

@@ -3299,6 +3311,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
32993311
infomask2_old_tuple,
33003312
infomask_new_tuple,
33013313
infomask2_new_tuple;
3314+
TransactionId old_xmin;
33023315

33033316
Assert(ItemPointerIsValid(otid));
33043317

@@ -3745,6 +3758,8 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
37453758
&xmax_old_tuple, &infomask_old_tuple,
37463759
&infomask2_old_tuple);
37473760

3761+
old_xmin = HeapTupleHeaderGetRawXmin(oldtup.t_data);
3762+
37483763
/*
37493764
* And also prepare an Xmax value for the new copy of the tuple. If there
37503765
* was no xmax previously, or there was one but all lockers are now gone,
@@ -4228,6 +4243,9 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
42284243
bms_free(modified_attrs);
42294244
bms_free(interesting_attrs);
42304245

4246+
if (add_index_delete_hook)
4247+
add_index_delete_hook(relation, otid, old_xmin);
4248+
42314249
return TM_Ok;
42324250
}
42334251

src/backend/access/heap/heapam_handler.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include "utils/builtins.h"
4747
#include "utils/rel.h"
4848

49+
/* Preserve the original heap tuple that is passed to callback in heapam_index_build_range_scan() */
50+
HeapTuple IndexHeapTuple;
51+
4952
static void reform_and_rewrite_tuple(HeapTuple tuple,
5053
Relation OldHeap, Relation NewHeap,
5154
Datum *values, bool *isnull, RewriteState rwstate);
@@ -1658,6 +1661,7 @@ heapam_index_build_range_scan(Relation heapRelation,
16581661
* some index AMs want to do further processing on the data first. So
16591662
* pass the values[] and isnull[] arrays, instead.
16601663
*/
1664+
IndexHeapTuple = heapTuple;
16611665

16621666
if (HeapTupleIsHeapOnly(heapTuple))
16631667
{

src/backend/access/heap/heapam_visibility.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
#include "utils/builtins.h"
7979
#include "utils/snapmgr.h"
8080

81+
bool (*add_snapshot_satisfies_hook) (HeapTuple tup, Snapshot snapshot, Buffer buffer);
82+
8183

8284
/*
8385
* SetHintBits()
@@ -1791,6 +1793,10 @@ HeapTupleSatisfiesVisibility(HeapTuple htup, Snapshot snapshot, Buffer buffer)
17911793
return HeapTupleSatisfiesHistoricMVCC(htup, snapshot, buffer);
17921794
case SNAPSHOT_NON_VACUUMABLE:
17931795
return HeapTupleSatisfiesNonVacuumable(htup, snapshot, buffer);
1796+
case SNAPSHOT_VCI_WOS2ROS:
1797+
case SNAPSHOT_VCI_LOCALROS:
1798+
if (add_snapshot_satisfies_hook)
1799+
return add_snapshot_satisfies_hook(htup, snapshot, buffer);
17941800
}
17951801

17961802
return false; /* keep compiler quiet */

src/backend/access/transam/xlogfuncs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ pg_get_wal_replay_pause_state(PG_FUNCTION_ARGS)
607607
statestr = "not paused";
608608
break;
609609
case RECOVERY_PAUSE_REQUESTED:
610+
case RECOVERY_VCI_PAUSE_REQUESTED:
610611
statestr = "pause requested";
611612
break;
612613
case RECOVERY_PAUSED:

src/backend/access/transam/xlogrecovery.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,7 +2949,8 @@ recoveryPausesHere(bool endOfRecovery)
29492949
ereport(LOG,
29502950
(errmsg("pausing at the end of recovery"),
29512951
errhint("Execute pg_wal_replay_resume() to promote.")));
2952-
else
2952+
/* If pause requested by VCI, the log is not output. */
2953+
else if (GetRecoveryPauseState() != RECOVERY_VCI_PAUSE_REQUESTED)
29532954
ereport(LOG,
29542955
(errmsg("recovery has paused"),
29552956
errhint("Execute pg_wal_replay_resume() to continue.")));
@@ -3115,6 +3116,18 @@ SetRecoveryPause(bool recoveryPause)
31153116
ConditionVariableBroadcast(&XLogRecoveryCtl->recoveryNotPausedCV);
31163117
}
31173118

3119+
/* Set the recovery pause requested for VCI. */
3120+
void
3121+
SetVciRecoveryPause(void)
3122+
{
3123+
SpinLockAcquire(&XLogRecoveryCtl->info_lck);
3124+
3125+
if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_NOT_PAUSED)
3126+
XLogRecoveryCtl->recoveryPauseState = RECOVERY_VCI_PAUSE_REQUESTED;
3127+
3128+
SpinLockRelease(&XLogRecoveryCtl->info_lck);
3129+
}
3130+
31183131
/*
31193132
* Confirm the recovery pause by setting the recovery pause state to
31203133
* RECOVERY_PAUSED.
@@ -3124,7 +3137,8 @@ ConfirmRecoveryPaused(void)
31243137
{
31253138
/* If recovery pause is requested then set it paused */
31263139
SpinLockAcquire(&XLogRecoveryCtl->info_lck);
3127-
if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_PAUSE_REQUESTED)
3140+
if (XLogRecoveryCtl->recoveryPauseState == RECOVERY_PAUSE_REQUESTED ||
3141+
XLogRecoveryCtl->recoveryPauseState == RECOVERY_VCI_PAUSE_REQUESTED)
31283142
XLogRecoveryCtl->recoveryPauseState = RECOVERY_PAUSED;
31293143
SpinLockRelease(&XLogRecoveryCtl->info_lck);
31303144
}

src/backend/catalog/dependency.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "utils/lsyscache.h"
8686
#include "utils/syscache.h"
8787

88+
bool (*add_drop_relation_hook) (const ObjectAddress *object, int flags) = NULL;
8889

8990
/*
9091
* Deletion processing requires additional state for each ObjectAddress that
@@ -1357,6 +1358,12 @@ doDeletion(const ObjectAddress *object, int flags)
13571358
{
13581359
char relKind = get_rel_relkind(object->objectId);
13591360

1361+
if (add_drop_relation_hook)
1362+
{
1363+
if (add_drop_relation_hook(object, flags))
1364+
break;
1365+
}
1366+
13601367
if (relKind == RELKIND_INDEX ||
13611368
relKind == RELKIND_PARTITIONED_INDEX)
13621369
{

src/backend/catalog/index.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static void ResetReindexProcessing(void);
133133
static void SetReindexPending(List *indexes);
134134
static void RemoveReindexPending(Oid indexOid);
135135

136+
bool (*add_reindex_index_hook) (Relation) = NULL;
136137

137138
/*
138139
* relationHasPrimaryKey
@@ -342,12 +343,17 @@ ConstructTupleDescriptor(Relation heapRelation,
342343
/* Simple index column */
343344
const FormData_pg_attribute *from;
344345

345-
Assert(atnum > 0); /* should've been caught above */
346-
347346
if (atnum > natts) /* safety check */
348347
elog(ERROR, "invalid column number %d", atnum);
349-
from = TupleDescAttr(heapTupDesc,
350-
AttrNumberGetAttrOffset(atnum));
348+
if (atnum > 0)
349+
{
350+
from = TupleDescAttr(heapTupDesc,
351+
AttrNumberGetAttrOffset(atnum));
352+
}
353+
else
354+
{
355+
from = SystemAttributeDefinition(atnum);
356+
}
351357

352358
to->atttypid = from->atttypid;
353359
to->attlen = from->attlen;
@@ -3692,6 +3698,25 @@ reindex_index(const ReindexStmt *stmt, Oid indexId,
36923698
return;
36933699
}
36943700

3701+
if (add_reindex_index_hook)
3702+
{
3703+
if (!add_reindex_index_hook(iRel))
3704+
{
3705+
RemoveReindexPending(RelationGetRelid(iRel));
3706+
3707+
/* Roll back any GUC changes */
3708+
AtEOXact_GUC(false, save_nestlevel);
3709+
3710+
/* Restore userid and security context */
3711+
SetUserIdAndSecContext(save_userid, save_sec_context);
3712+
3713+
/* Close rels, but keep locks */
3714+
index_close(iRel, NoLock);
3715+
table_close(heapRelation, NoLock);
3716+
return;
3717+
}
3718+
}
3719+
36953720
if (progress)
36963721
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
36973722
iRel->rd_rel->relam);

src/backend/commands/explain.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ ExplainPreScanNode(PlanState *planstate, Bitmapset **rels_used)
12081208
((ForeignScan *) plan)->fs_base_relids);
12091209
break;
12101210
case T_CustomScan:
1211+
case T_CustomPlanMarkPos:
12111212
*rels_used = bms_add_members(*rels_used,
12121213
((CustomScan *) plan)->custom_relids);
12131214
break;
@@ -1511,6 +1512,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
15111512
}
15121513
break;
15131514
case T_CustomScan:
1515+
case T_CustomPlanMarkPos:
15141516
sname = "Custom Scan";
15151517
custom_name = ((CustomScan *) plan)->methods->CustomName;
15161518
if (custom_name)
@@ -1674,10 +1676,18 @@ ExplainNode(PlanState *planstate, List *ancestors,
16741676
ExplainScanTarget((Scan *) plan, es);
16751677
break;
16761678
case T_ForeignScan:
1677-
case T_CustomScan:
16781679
if (((Scan *) plan)->scanrelid > 0)
16791680
ExplainScanTarget((Scan *) plan, es);
16801681
break;
1682+
case T_CustomScan:
1683+
case T_CustomPlanMarkPos:
1684+
{
1685+
CustomScanState *css = (CustomScanState *) planstate;
1686+
1687+
if (css->methods->ExplainCustomPlanTargetRel)
1688+
css->methods->ExplainCustomPlanTargetRel(css, es);
1689+
}
1690+
break;
16811691
case T_IndexScan:
16821692
{
16831693
IndexScan *indexscan = (IndexScan *) plan;
@@ -2149,6 +2159,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
21492159
show_foreignscan_info((ForeignScanState *) planstate, es);
21502160
break;
21512161
case T_CustomScan:
2162+
case T_CustomPlanMarkPos:
21522163
{
21532164
CustomScanState *css = (CustomScanState *) planstate;
21542165

@@ -2410,6 +2421,7 @@ ExplainNode(PlanState *planstate, List *ancestors,
24102421
"Subquery", NULL, es);
24112422
break;
24122423
case T_CustomScan:
2424+
case T_CustomPlanMarkPos:
24132425
ExplainCustomChildren((CustomScanState *) planstate,
24142426
ancestors, es);
24152427
break;
@@ -4428,6 +4440,7 @@ ExplainTargetRel(Plan *plan, Index rti, ExplainState *es)
44284440
case T_TidRangeScan:
44294441
case T_ForeignScan:
44304442
case T_CustomScan:
4443+
case T_CustomPlanMarkPos:
44314444
case T_ModifyTable:
44324445
/* Assert it's on a real relation */
44334446
Assert(rte->rtekind == RTE_RELATION);
@@ -5109,3 +5122,12 @@ ExplainFlushWorkersState(ExplainState *es)
51095122
pfree(wstate->worker_state_save);
51105123
pfree(wstate);
51115124
}
5125+
5126+
void
5127+
ExplainPropertySortGroupKeys(PlanState *planstate, const char *qlabel,
5128+
int nkeys, AttrNumber *keycols,
5129+
List *ancestors, ExplainState *es)
5130+
{
5131+
show_sort_group_keys(planstate, qlabel, nkeys, 0, keycols,
5132+
NULL, NULL, NULL, ancestors, es);
5133+
}

0 commit comments

Comments
 (0)