PostgreSQL Source Code  git master
execReplication.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * execReplication.c
4  * miscellaneous executor routines for logical replication
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/backend/executor/execReplication.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres.h"
16 
17 #include "access/genam.h"
18 #include "access/relscan.h"
19 #include "access/tableam.h"
20 #include "access/transam.h"
21 #include "access/xact.h"
22 #include "catalog/pg_am_d.h"
23 #include "commands/trigger.h"
24 #include "executor/executor.h"
27 #include "storage/lmgr.h"
28 #include "utils/builtins.h"
29 #include "utils/lsyscache.h"
30 #include "utils/rel.h"
31 #include "utils/snapmgr.h"
32 #include "utils/syscache.h"
33 #include "utils/typcache.h"
34 
35 
36 static bool tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
37  TypeCacheEntry **eq);
38 
39 /*
40  * Returns the fixed strategy number, if any, of the equality operator for the
41  * given index access method, otherwise, InvalidStrategy.
42  *
43  * Currently, only Btree and Hash indexes are supported. The other index access
44  * methods don't have a fixed strategy for equality operation - instead, the
45  * support routines of each operator class interpret the strategy numbers
46  * according to the operator class's definition.
47  */
50 {
51  int ret;
52 
53  switch (am)
54  {
55  case BTREE_AM_OID:
57  break;
58  case HASH_AM_OID:
60  break;
61  default:
62  /* XXX: Only Btree and Hash indexes are supported */
63  ret = InvalidStrategy;
64  break;
65  }
66 
67  return ret;
68 }
69 
70 /*
71  * Return the appropriate strategy number which corresponds to the equality
72  * operator.
73  */
74 static StrategyNumber
76 {
77  Oid am = get_opclass_method(opclass);
78 
80 }
81 
82 /*
83  * Setup a ScanKey for a search in the relation 'rel' for a tuple 'key' that
84  * is setup to match 'rel' (*NOT* idxrel!).
85  *
86  * Returns how many columns to use for the index scan.
87  *
88  * This is not generic routine, idxrel must be PK, RI, or an index that can be
89  * used for REPLICA IDENTITY FULL table. See FindUsableIndexForReplicaIdentityFull()
90  * for details.
91  *
92  * By definition, replication identity of a rel meets all limitations associated
93  * with that. Note that any other index could also meet these limitations.
94  */
95 static int
97  TupleTableSlot *searchslot)
98 {
99  int index_attoff;
100  int skey_attoff = 0;
101  Datum indclassDatum;
102  oidvector *opclass;
103  int2vector *indkey = &idxrel->rd_index->indkey;
104 
105  indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, idxrel->rd_indextuple,
106  Anum_pg_index_indclass);
107  opclass = (oidvector *) DatumGetPointer(indclassDatum);
108 
109  /* Build scankey for every non-expression attribute in the index. */
110  for (index_attoff = 0; index_attoff < IndexRelationGetNumberOfKeyAttributes(idxrel);
111  index_attoff++)
112  {
113  Oid operator;
114  Oid optype;
115  Oid opfamily;
116  RegProcedure regop;
117  int table_attno = indkey->values[index_attoff];
118  StrategyNumber eq_strategy;
119 
120  if (!AttributeNumberIsValid(table_attno))
121  {
122  /*
123  * XXX: Currently, we don't support expressions in the scan key,
124  * see code below.
125  */
126  continue;
127  }
128 
129  /*
130  * Load the operator info. We need this to get the equality operator
131  * function for the scan key.
132  */
133  optype = get_opclass_input_type(opclass->values[index_attoff]);
134  opfamily = get_opclass_family(opclass->values[index_attoff]);
135  eq_strategy = get_equal_strategy_number(opclass->values[index_attoff]);
136 
137  operator = get_opfamily_member(opfamily, optype,
138  optype,
139  eq_strategy);
140 
141  if (!OidIsValid(operator))
142  elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
143  eq_strategy, optype, optype, opfamily);
144 
145  regop = get_opcode(operator);
146 
147  /* Initialize the scankey. */
148  ScanKeyInit(&skey[skey_attoff],
149  index_attoff + 1,
150  eq_strategy,
151  regop,
152  searchslot->tts_values[table_attno - 1]);
153 
154  skey[skey_attoff].sk_collation = idxrel->rd_indcollation[index_attoff];
155 
156  /* Check for null value. */
157  if (searchslot->tts_isnull[table_attno - 1])
158  skey[skey_attoff].sk_flags |= (SK_ISNULL | SK_SEARCHNULL);
159 
160  skey_attoff++;
161  }
162 
163  /* There must always be at least one attribute for the index scan. */
164  Assert(skey_attoff > 0);
165 
166  return skey_attoff;
167 }
168 
169 /*
170  * Search the relation 'rel' for tuple using the index.
171  *
172  * If a matching tuple is found, lock it with lockmode, fill the slot with its
173  * contents, and return true. Return false otherwise.
174  */
175 bool
177  LockTupleMode lockmode,
178  TupleTableSlot *searchslot,
179  TupleTableSlot *outslot)
180 {
182  int skey_attoff;
183  IndexScanDesc scan;
184  SnapshotData snap;
185  TransactionId xwait;
186  Relation idxrel;
187  bool found;
188  TypeCacheEntry **eq = NULL;
189  bool isIdxSafeToSkipDuplicates;
190 
191  /* Open the index. */
192  idxrel = index_open(idxoid, RowExclusiveLock);
193 
194  isIdxSafeToSkipDuplicates = (GetRelationIdentityOrPK(rel) == idxoid);
195 
196  InitDirtySnapshot(snap);
197 
198  /* Build scan key. */
199  skey_attoff = build_replindex_scan_key(skey, rel, idxrel, searchslot);
200 
201  /* Start an index scan. */
202  scan = index_beginscan(rel, idxrel, &snap, skey_attoff, 0);
203 
204 retry:
205  found = false;
206 
207  index_rescan(scan, skey, skey_attoff, NULL, 0);
208 
209  /* Try to find the tuple */
210  while (index_getnext_slot(scan, ForwardScanDirection, outslot))
211  {
212  /*
213  * Avoid expensive equality check if the index is primary key or
214  * replica identity index.
215  */
216  if (!isIdxSafeToSkipDuplicates)
217  {
218  if (eq == NULL)
219  eq = palloc0(sizeof(*eq) * outslot->tts_tupleDescriptor->natts);
220 
221  if (!tuples_equal(outslot, searchslot, eq))
222  continue;
223  }
224 
225  ExecMaterializeSlot(outslot);
226 
227  xwait = TransactionIdIsValid(snap.xmin) ?
228  snap.xmin : snap.xmax;
229 
230  /*
231  * If the tuple is locked, wait for locking transaction to finish and
232  * retry.
233  */
234  if (TransactionIdIsValid(xwait))
235  {
236  XactLockTableWait(xwait, NULL, NULL, XLTW_None);
237  goto retry;
238  }
239 
240  /* Found our tuple and it's not locked */
241  found = true;
242  break;
243  }
244 
245  /* Found tuple, try to lock it in the lockmode. */
246  if (found)
247  {
248  TM_FailureData tmfd;
249  TM_Result res;
250 
252 
253  res = table_tuple_lock(rel, &(outslot->tts_tid), GetLatestSnapshot(),
254  outslot,
255  GetCurrentCommandId(false),
256  lockmode,
258  0 /* don't follow updates */ ,
259  &tmfd);
260 
262 
263  switch (res)
264  {
265  case TM_Ok:
266  break;
267  case TM_Updated:
268  /* XXX: Improve handling here */
270  ereport(LOG,
272  errmsg("tuple to be locked was already moved to another partition due to concurrent update, retrying")));
273  else
274  ereport(LOG,
276  errmsg("concurrent update, retrying")));
277  goto retry;
278  case TM_Deleted:
279  /* XXX: Improve handling here */
280  ereport(LOG,
282  errmsg("concurrent delete, retrying")));
283  goto retry;
284  case TM_Invisible:
285  elog(ERROR, "attempted to lock invisible tuple");
286  break;
287  default:
288  elog(ERROR, "unexpected table_tuple_lock status: %u", res);
289  break;
290  }
291  }
292 
293  index_endscan(scan);
294 
295  /* Don't release lock until commit. */
296  index_close(idxrel, NoLock);
297 
298  return found;
299 }
300 
301 /*
302  * Compare the tuples in the slots by checking if they have equal values.
303  */
304 static bool
306  TypeCacheEntry **eq)
307 {
308  int attrnum;
309 
310  Assert(slot1->tts_tupleDescriptor->natts ==
311  slot2->tts_tupleDescriptor->natts);
312 
313  slot_getallattrs(slot1);
314  slot_getallattrs(slot2);
315 
316  /* Check equality of the attributes. */
317  for (attrnum = 0; attrnum < slot1->tts_tupleDescriptor->natts; attrnum++)
318  {
319  Form_pg_attribute att;
320  TypeCacheEntry *typentry;
321 
322  att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
323 
324  /*
325  * Ignore dropped and generated columns as the publisher doesn't send
326  * those
327  */
328  if (att->attisdropped || att->attgenerated)
329  continue;
330 
331  /*
332  * If one value is NULL and other is not, then they are certainly not
333  * equal
334  */
335  if (slot1->tts_isnull[attrnum] != slot2->tts_isnull[attrnum])
336  return false;
337 
338  /*
339  * If both are NULL, they can be considered equal.
340  */
341  if (slot1->tts_isnull[attrnum] || slot2->tts_isnull[attrnum])
342  continue;
343 
344  typentry = eq[attrnum];
345  if (typentry == NULL)
346  {
347  typentry = lookup_type_cache(att->atttypid,
349  if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
350  ereport(ERROR,
351  (errcode(ERRCODE_UNDEFINED_FUNCTION),
352  errmsg("could not identify an equality operator for type %s",
353  format_type_be(att->atttypid))));
354  eq[attrnum] = typentry;
355  }
356 
358  att->attcollation,
359  slot1->tts_values[attrnum],
360  slot2->tts_values[attrnum])))
361  return false;
362  }
363 
364  return true;
365 }
366 
367 /*
368  * Search the relation 'rel' for tuple using the sequential scan.
369  *
370  * If a matching tuple is found, lock it with lockmode, fill the slot with its
371  * contents, and return true. Return false otherwise.
372  *
373  * Note that this stops on the first matching tuple.
374  *
375  * This can obviously be quite slow on tables that have more than few rows.
376  */
377 bool
379  TupleTableSlot *searchslot, TupleTableSlot *outslot)
380 {
381  TupleTableSlot *scanslot;
382  TableScanDesc scan;
383  SnapshotData snap;
384  TypeCacheEntry **eq;
385  TransactionId xwait;
386  bool found;
388 
389  Assert(equalTupleDescs(desc, outslot->tts_tupleDescriptor));
390 
391  eq = palloc0(sizeof(*eq) * outslot->tts_tupleDescriptor->natts);
392 
393  /* Start a heap scan. */
394  InitDirtySnapshot(snap);
395  scan = table_beginscan(rel, &snap, 0, NULL);
396  scanslot = table_slot_create(rel, NULL);
397 
398 retry:
399  found = false;
400 
401  table_rescan(scan, NULL);
402 
403  /* Try to find the tuple */
404  while (table_scan_getnextslot(scan, ForwardScanDirection, scanslot))
405  {
406  if (!tuples_equal(scanslot, searchslot, eq))
407  continue;
408 
409  found = true;
410  ExecCopySlot(outslot, scanslot);
411 
412  xwait = TransactionIdIsValid(snap.xmin) ?
413  snap.xmin : snap.xmax;
414 
415  /*
416  * If the tuple is locked, wait for locking transaction to finish and
417  * retry.
418  */
419  if (TransactionIdIsValid(xwait))
420  {
421  XactLockTableWait(xwait, NULL, NULL, XLTW_None);
422  goto retry;
423  }
424 
425  /* Found our tuple and it's not locked */
426  break;
427  }
428 
429  /* Found tuple, try to lock it in the lockmode. */
430  if (found)
431  {
432  TM_FailureData tmfd;
433  TM_Result res;
434 
436 
437  res = table_tuple_lock(rel, &(outslot->tts_tid), GetLatestSnapshot(),
438  outslot,
439  GetCurrentCommandId(false),
440  lockmode,
442  0 /* don't follow updates */ ,
443  &tmfd);
444 
446 
447  switch (res)
448  {
449  case TM_Ok:
450  break;
451  case TM_Updated:
452  /* XXX: Improve handling here */
454  ereport(LOG,
456  errmsg("tuple to be locked was already moved to another partition due to concurrent update, retrying")));
457  else
458  ereport(LOG,
460  errmsg("concurrent update, retrying")));
461  goto retry;
462  case TM_Deleted:
463  /* XXX: Improve handling here */
464  ereport(LOG,
466  errmsg("concurrent delete, retrying")));
467  goto retry;
468  case TM_Invisible:
469  elog(ERROR, "attempted to lock invisible tuple");
470  break;
471  default:
472  elog(ERROR, "unexpected table_tuple_lock status: %u", res);
473  break;
474  }
475  }
476 
477  table_endscan(scan);
479 
480  return found;
481 }
482 
483 /*
484  * Insert tuple represented in the slot to the relation, update the indexes,
485  * and execute any constraints and per-row triggers.
486  *
487  * Caller is responsible for opening the indexes.
488  */
489 void
491  EState *estate, TupleTableSlot *slot)
492 {
493  bool skip_tuple = false;
494  Relation rel = resultRelInfo->ri_RelationDesc;
495 
496  /* For now we support only tables. */
497  Assert(rel->rd_rel->relkind == RELKIND_RELATION);
498 
500 
501  /* BEFORE ROW INSERT Triggers */
502  if (resultRelInfo->ri_TrigDesc &&
503  resultRelInfo->ri_TrigDesc->trig_insert_before_row)
504  {
505  if (!ExecBRInsertTriggers(estate, resultRelInfo, slot))
506  skip_tuple = true; /* "do nothing" */
507  }
508 
509  if (!skip_tuple)
510  {
511  List *recheckIndexes = NIL;
512 
513  /* Compute stored generated columns */
514  if (rel->rd_att->constr &&
516  ExecComputeStoredGenerated(resultRelInfo, estate, slot,
517  CMD_INSERT);
518 
519  /* Check the constraints of the tuple */
520  if (rel->rd_att->constr)
521  ExecConstraints(resultRelInfo, slot, estate);
522  if (rel->rd_rel->relispartition)
523  ExecPartitionCheck(resultRelInfo, slot, estate, true);
524 
525  /* OK, store the tuple and create index entries for it */
526  simple_table_tuple_insert(resultRelInfo->ri_RelationDesc, slot);
527 
528  if (resultRelInfo->ri_NumIndices > 0)
529  recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
530  slot, estate, false, false,
531  NULL, NIL, false);
532 
533  /* AFTER ROW INSERT Triggers */
534  ExecARInsertTriggers(estate, resultRelInfo, slot,
535  recheckIndexes, NULL);
536 
537  /*
538  * XXX we should in theory pass a TransitionCaptureState object to the
539  * above to capture transition tuples, but after statement triggers
540  * don't actually get fired by replication yet anyway
541  */
542 
543  list_free(recheckIndexes);
544  }
545 }
546 
547 /*
548  * Find the searchslot tuple and update it with data in the slot,
549  * update the indexes, and execute any constraints and per-row triggers.
550  *
551  * Caller is responsible for opening the indexes.
552  */
553 void
555  EState *estate, EPQState *epqstate,
556  TupleTableSlot *searchslot, TupleTableSlot *slot)
557 {
558  bool skip_tuple = false;
559  Relation rel = resultRelInfo->ri_RelationDesc;
560  ItemPointer tid = &(searchslot->tts_tid);
561 
562  /* For now we support only tables. */
563  Assert(rel->rd_rel->relkind == RELKIND_RELATION);
564 
566 
567  /* BEFORE ROW UPDATE Triggers */
568  if (resultRelInfo->ri_TrigDesc &&
569  resultRelInfo->ri_TrigDesc->trig_update_before_row)
570  {
571  if (!ExecBRUpdateTriggers(estate, epqstate, resultRelInfo,
572  tid, NULL, slot, NULL, NULL))
573  skip_tuple = true; /* "do nothing" */
574  }
575 
576  if (!skip_tuple)
577  {
578  List *recheckIndexes = NIL;
579  TU_UpdateIndexes update_indexes;
580 
581  /* Compute stored generated columns */
582  if (rel->rd_att->constr &&
584  ExecComputeStoredGenerated(resultRelInfo, estate, slot,
585  CMD_UPDATE);
586 
587  /* Check the constraints of the tuple */
588  if (rel->rd_att->constr)
589  ExecConstraints(resultRelInfo, slot, estate);
590  if (rel->rd_rel->relispartition)
591  ExecPartitionCheck(resultRelInfo, slot, estate, true);
592 
593  simple_table_tuple_update(rel, tid, slot, estate->es_snapshot,
594  &update_indexes);
595 
596  if (resultRelInfo->ri_NumIndices > 0 && (update_indexes != TU_None))
597  recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
598  slot, estate, true, false,
599  NULL, NIL,
600  (update_indexes == TU_Summarizing));
601 
602  /* AFTER ROW UPDATE Triggers */
603  ExecARUpdateTriggers(estate, resultRelInfo,
604  NULL, NULL,
605  tid, NULL, slot,
606  recheckIndexes, NULL, false);
607 
608  list_free(recheckIndexes);
609  }
610 }
611 
612 /*
613  * Find the searchslot tuple and delete it, and execute any constraints
614  * and per-row triggers.
615  *
616  * Caller is responsible for opening the indexes.
617  */
618 void
620  EState *estate, EPQState *epqstate,
621  TupleTableSlot *searchslot)
622 {
623  bool skip_tuple = false;
624  Relation rel = resultRelInfo->ri_RelationDesc;
625  ItemPointer tid = &searchslot->tts_tid;
626 
628 
629  /* BEFORE ROW DELETE Triggers */
630  if (resultRelInfo->ri_TrigDesc &&
631  resultRelInfo->ri_TrigDesc->trig_delete_before_row)
632  {
633  skip_tuple = !ExecBRDeleteTriggers(estate, epqstate, resultRelInfo,
634  tid, NULL, NULL, NULL, NULL);
635  }
636 
637  if (!skip_tuple)
638  {
639  /* OK, delete the tuple */
640  simple_table_tuple_delete(rel, tid, estate->es_snapshot);
641 
642  /* AFTER ROW DELETE Triggers */
643  ExecARDeleteTriggers(estate, resultRelInfo,
644  tid, NULL, NULL, false);
645  }
646 }
647 
648 /*
649  * Check if command can be executed with current replica identity.
650  */
651 void
653 {
654  PublicationDesc pubdesc;
655 
656  /*
657  * Skip checking the replica identity for partitioned tables, because the
658  * operations are actually performed on the leaf partitions.
659  */
660  if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
661  return;
662 
663  /* We only need to do checks for UPDATE and DELETE. */
664  if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
665  return;
666 
667  /*
668  * It is only safe to execute UPDATE/DELETE when all columns, referenced
669  * in the row filters from publications which the relation is in, are
670  * valid - i.e. when all referenced columns are part of REPLICA IDENTITY
671  * or the table does not publish UPDATEs or DELETEs.
672  *
673  * XXX We could optimize it by first checking whether any of the
674  * publications have a row filter for this relation. If not and relation
675  * has replica identity then we can avoid building the descriptor but as
676  * this happens only one time it doesn't seem worth the additional
677  * complexity.
678  */
679  RelationBuildPublicationDesc(rel, &pubdesc);
680  if (cmd == CMD_UPDATE && !pubdesc.rf_valid_for_update)
681  ereport(ERROR,
682  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
683  errmsg("cannot update table \"%s\"",
685  errdetail("Column used in the publication WHERE expression is not part of the replica identity.")));
686  else if (cmd == CMD_UPDATE && !pubdesc.cols_valid_for_update)
687  ereport(ERROR,
688  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
689  errmsg("cannot update table \"%s\"",
691  errdetail("Column list used by the publication does not cover the replica identity.")));
692  else if (cmd == CMD_DELETE && !pubdesc.rf_valid_for_delete)
693  ereport(ERROR,
694  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
695  errmsg("cannot delete from table \"%s\"",
697  errdetail("Column used in the publication WHERE expression is not part of the replica identity.")));
698  else if (cmd == CMD_DELETE && !pubdesc.cols_valid_for_delete)
699  ereport(ERROR,
700  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
701  errmsg("cannot delete from table \"%s\"",
703  errdetail("Column list used by the publication does not cover the replica identity.")));
704 
705  /* If relation has replica identity we are always good. */
707  return;
708 
709  /* REPLICA IDENTITY FULL is also good for UPDATE/DELETE. */
710  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL)
711  return;
712 
713  /*
714  * This is UPDATE/DELETE and there is no replica identity.
715  *
716  * Check if the table publishes UPDATES or DELETES.
717  */
718  if (cmd == CMD_UPDATE && pubdesc.pubactions.pubupdate)
719  ereport(ERROR,
720  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
721  errmsg("cannot update table \"%s\" because it does not have a replica identity and publishes updates",
723  errhint("To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.")));
724  else if (cmd == CMD_DELETE && pubdesc.pubactions.pubdelete)
725  ereport(ERROR,
726  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
727  errmsg("cannot delete from table \"%s\" because it does not have a replica identity and publishes deletes",
729  errhint("To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.")));
730 }
731 
732 
733 /*
734  * Check if we support writing into specific relkind.
735  *
736  * The nspname and relname are only needed for error reporting.
737  */
738 void
739 CheckSubscriptionRelkind(char relkind, const char *nspname,
740  const char *relname)
741 {
742  if (relkind != RELKIND_RELATION && relkind != RELKIND_PARTITIONED_TABLE)
743  ereport(ERROR,
744  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
745  errmsg("cannot use relation \"%s.%s\" as logical replication target",
746  nspname, relname),
748 }
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:182
#define Assert(condition)
Definition: c.h:858
regproc RegProcedure
Definition: c.h:650
uint32 TransactionId
Definition: c.h:652
#define OidIsValid(objectId)
Definition: c.h:775
int errdetail(const char *fmt,...)
Definition: elog.c:1205
int errhint(const char *fmt,...)
Definition: elog.c:1319
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define LOG
Definition: elog.h:31
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
List * ExecInsertIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool update, bool noDupErr, bool *specConflict, List *arbiterIndexes, bool onlySummarizing)
Definition: execIndexing.c:298
bool ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool emitError)
Definition: execMain.c:1792
void ExecConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate)
Definition: execMain.c:1916
bool RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode, TupleTableSlot *searchslot, TupleTableSlot *outslot)
bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid, LockTupleMode lockmode, TupleTableSlot *searchslot, TupleTableSlot *outslot)
void ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo, EState *estate, EPQState *epqstate, TupleTableSlot *searchslot)
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
StrategyNumber get_equal_strategy_number_for_am(Oid am)
static bool tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2, TypeCacheEntry **eq)
static StrategyNumber get_equal_strategy_number(Oid opclass)
void ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo, EState *estate, EPQState *epqstate, TupleTableSlot *searchslot, TupleTableSlot *slot)
void CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
void ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo, EState *estate, TupleTableSlot *slot)
static int build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel, TupleTableSlot *searchslot)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1341
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1149
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition: indexam.c:673
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, int norderbys)
Definition: indexam.c:256
void index_endscan(IndexScanDesc scan)
Definition: indexam.c:378
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition: indexam.c:352
static bool ItemPointerIndicatesMovedPartitions(const ItemPointerData *pointer)
Definition: itemptr.h:197
void list_free(List *list)
Definition: list.c:1546
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:667
@ XLTW_None
Definition: lmgr.h:26
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
@ LockWaitBlock
Definition: lockoptions.h:39
LockTupleMode
Definition: lockoptions.h:50
Oid get_opclass_method(Oid opclass)
Definition: lsyscache.c:1260
Oid get_opclass_input_type(Oid opclass)
Definition: lsyscache.c:1212
Oid get_opclass_family(Oid opclass)
Definition: lsyscache.c:1190
RegProcedure get_opcode(Oid opno)
Definition: lsyscache.c:1285
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition: lsyscache.c:166
void * palloc0(Size size)
Definition: mcxt.c:1346
void ExecComputeStoredGenerated(ResultRelInfo *resultRelInfo, EState *estate, TupleTableSlot *slot, CmdType cmdtype)
CmdType
Definition: nodes.h:263
@ CMD_INSERT
Definition: nodes.h:267
@ CMD_DELETE
Definition: nodes.h:268
@ CMD_UPDATE
Definition: nodes.h:266
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
int errdetail_relkind_not_supported(char relkind)
Definition: pg_class.c:24
NameData relname
Definition: pg_class.h:38
#define INDEX_MAX_KEYS
#define NIL
Definition: pg_list.h:68
#define ERRCODE_T_R_SERIALIZATION_FAILURE
Definition: pgbench.c:76
static bool DatumGetBool(Datum X)
Definition: postgres.h:90
uintptr_t Datum
Definition: postgres.h:64
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:531
#define RelationGetRelationName(relation)
Definition: rel.h:539
#define IndexRelationGetNumberOfKeyAttributes(relation)
Definition: rel.h:524
void RelationBuildPublicationDesc(Relation relation, PublicationDesc *pubdesc)
Definition: relcache.c:5716
Oid RelationGetReplicaIndex(Relation relation)
Definition: relcache.c:5000
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
@ ForwardScanDirection
Definition: sdir.h:28
#define SK_SEARCHNULL
Definition: skey.h:121
#define SK_ISNULL
Definition: skey.h:115
Snapshot GetLatestSnapshot(void)
Definition: snapmgr.c:291
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:648
void PopActiveSnapshot(void)
Definition: snapmgr.c:743
#define InitDirtySnapshot(snapshotdata)
Definition: snapmgr.h:40
Oid GetRelationIdentityOrPK(Relation rel)
Definition: relation.c:851
uint16 StrategyNumber
Definition: stratnum.h:22
#define InvalidStrategy
Definition: stratnum.h:24
#define HTEqualStrategyNumber
Definition: stratnum.h:41
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Snapshot es_snapshot
Definition: execnodes.h:624
Oid fn_oid
Definition: fmgr.h:59
Definition: pg_list.h:54
PublicationActions pubactions
bool cols_valid_for_delete
bool cols_valid_for_update
struct HeapTupleData * rd_indextuple
Definition: rel.h:194
TupleDesc rd_att
Definition: rel.h:112
Form_pg_index rd_index
Definition: rel.h:192
Oid * rd_indcollation
Definition: rel.h:217
Form_pg_class rd_rel
Definition: rel.h:111
int ri_NumIndices
Definition: execnodes.h:459
Relation ri_RelationDesc
Definition: execnodes.h:456
TriggerDesc * ri_TrigDesc
Definition: execnodes.h:486
int sk_flags
Definition: skey.h:66
Oid sk_collation
Definition: skey.h:70
TransactionId xmin
Definition: snapshot.h:157
TransactionId xmax
Definition: snapshot.h:158
ItemPointerData ctid
Definition: tableam.h:150
bool trig_delete_before_row
Definition: reltrigger.h:66
bool trig_update_before_row
Definition: reltrigger.h:61
bool trig_insert_before_row
Definition: reltrigger.h:56
bool has_generated_stored
Definition: tupdesc.h:45
TupleConstr * constr
Definition: tupdesc.h:85
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
bool * tts_isnull
Definition: tuptable.h:127
ItemPointerData tts_tid
Definition: tuptable.h:129
Datum * tts_values
Definition: tuptable.h:125
FmgrInfo eq_opr_finfo
Definition: typcache.h:75
Definition: c.h:715
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:722
Definition: c.h:726
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:733
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:510
void simple_table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot, Snapshot snapshot, TU_UpdateIndexes *update_indexes)
Definition: tableam.c:335
void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
Definition: tableam.c:276
void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot)
Definition: tableam.c:290
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
Definition: tableam.c:91
static TableScanDesc table_beginscan(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:918
TU_UpdateIndexes
Definition: tableam.h:118
@ TU_Summarizing
Definition: tableam.h:126
@ TU_None
Definition: tableam.h:120
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1029
TM_Result
Definition: tableam.h:80
@ TM_Ok
Definition: tableam.h:85
@ TM_Deleted
Definition: tableam.h:100
@ TM_Updated
Definition: tableam.h:97
@ TM_Invisible
Definition: tableam.h:88
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:1038
static TM_Result table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *slot, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, uint8 flags, TM_FailureData *tmfd)
Definition: tableam.h:1590
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
Definition: tableam.h:1065
#define TransactionIdIsValid(xid)
Definition: transam.h:41
bool ExecBRUpdateTriggers(EState *estate, EPQState *epqstate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, TupleTableSlot *newslot, TM_Result *tmresult, TM_FailureData *tmfd)
Definition: trigger.c:2934
void ExecARDeleteTriggers(EState *estate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, TransitionCaptureState *transition_capture, bool is_crosspart_update)
Definition: trigger.c:2774
bool ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo, TupleTableSlot *slot)
Definition: trigger.c:2458
void ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ResultRelInfo *src_partinfo, ResultRelInfo *dst_partinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, TupleTableSlot *newslot, List *recheckIndexes, TransitionCaptureState *transition_capture, bool is_crosspart_update)
Definition: trigger.c:3097
bool ExecBRDeleteTriggers(EState *estate, EPQState *epqstate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, TupleTableSlot **epqslot, TM_Result *tmresult, TM_FailureData *tmfd)
Definition: trigger.c:2683
void ExecARInsertTriggers(EState *estate, ResultRelInfo *relinfo, TupleTableSlot *slot, List *recheckIndexes, TransitionCaptureState *transition_capture)
Definition: trigger.c:2534
bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
Definition: tupdesc.c:419
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
Definition: tuptable.h:509
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:368
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:472
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition: typcache.c:346
#define TYPECACHE_EQ_OPR_FINFO
Definition: typcache.h:142
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:826