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