77 #include "utils/fmgroids.h"
110 Oid accessMethodObjectId,
111 Oid *collationObjectId,
114 int numatts,
Oid indexoid);
165 foreach(indexoidscan, indexoidlist)
172 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
219 if ((is_alter_table || heapRel->
rd_rel->relispartition) &&
223 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
224 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
237 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
238 errmsg(
"primary keys cannot use NULLS NOT DISTINCT indexes")));
254 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
255 errmsg(
"primary keys cannot be expressions")));
265 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
269 if (!attform->attnotnull)
271 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
272 errmsg(
"primary key column \"%s\" is not marked NOT NULL",
288 Oid accessMethodObjectId,
289 Oid *collationObjectId,
317 for (
i = 0;
i < numatts;
i++)
328 to->attstattarget = -1;
329 to->attcacheoff = -1;
330 to->attislocal =
true;
331 to->attcollation = (
i < numkeyatts) ?
337 if (colnames_item == NULL)
338 elog(
ERROR,
"too few entries in colnames list");
340 colnames_item =
lnext(indexColNames, colnames_item);
355 elog(
ERROR,
"invalid column number %d", atnum);
359 to->atttypid = from->atttypid;
360 to->attlen = from->attlen;
361 to->attndims = from->attndims;
362 to->atttypmod = from->atttypmod;
363 to->attbyval = from->attbyval;
364 to->attalign = from->attalign;
365 to->attstorage = from->attstorage;
366 to->attcompression = from->attcompression;
373 if (indexpr_item == NULL)
374 elog(
ERROR,
"too few entries in indexprs list");
384 elog(
ERROR,
"cache lookup failed for type %u", keyType);
390 to->atttypid = keyType;
391 to->attlen = typeTup->typlen;
393 to->attbyval = typeTup->typbyval;
394 to->attalign = typeTup->typalign;
395 to->attstorage = typeTup->typstorage;
418 to->atttypid, to->attcollation,
436 if (i < indexInfo->ii_NumIndexKeyAttrs)
440 elog(
ERROR,
"cache lookup failed for opclass %u",
444 keyType = opclassTup->opckeytype;
455 if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
459 elog(
ERROR,
"could not get element type of array type %u",
470 if (
OidIsValid(keyType) && keyType != to->atttypid)
474 elog(
ERROR,
"cache lookup failed for type %u", keyType);
477 to->atttypid = keyType;
479 to->attlen = typeTup->typlen;
480 to->attbyval = typeTup->typbyval;
481 to->attalign = typeTup->typalign;
482 to->attstorage = typeTup->typstorage;
509 for (
i = 0;
i < numatts;
i += 1)
570 bool nulls[Natts_pg_index] = {0};
598 exprsDatum = (
Datum) 0;
613 predDatum = (
Datum) 0;
643 values[Anum_pg_index_indexprs - 1] = exprsDatum;
644 if (exprsDatum == (
Datum) 0)
645 nulls[Anum_pg_index_indexprs - 1] =
true;
646 values[Anum_pg_index_indpred - 1] = predDatum;
647 if (predDatum == (
Datum) 0)
648 nulls[Anum_pg_index_indpred - 1] =
true;
714 const char *indexRelationName,
716 Oid parentIndexRelid,
717 Oid parentConstraintId,
721 Oid accessMethodObjectId,
723 Oid *collationObjectId,
729 bool allow_system_table_mods,
737 bool shared_relation;
738 bool mapped_relation;
753 Assert((constr_flags == 0) ||
758 relkind = partitioned ? RELKIND_PARTITIONED_INDEX : RELKIND_INDEX;
770 shared_relation = heapRelation->
rd_rel->relisshared;
772 relpersistence = heapRelation->
rd_rel->relpersistence;
778 elog(
ERROR,
"must index at least one column");
780 if (!allow_system_table_mods &&
784 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
785 errmsg(
"user-defined indexes on system catalog tables are not supported")));
808 Oid collation = collationObjectId[
i];
809 Oid opclass = classObjectId[
i];
813 if ((opclass == TEXT_BTREE_PATTERN_OPS_OID ||
814 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||
815 opclass == BPCHAR_BTREE_PATTERN_OPS_OID) &&
822 elog(
ERROR,
"cache lookup failed for operator class %u", opclass);
824 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
825 errmsg(
"nondeterministic collations are not supported for operator class \"%s\"",
839 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
840 errmsg(
"concurrent index creation on system catalog tables is not supported")));
846 if (concurrent && is_exclusion)
848 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
849 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
857 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
858 errmsg(
"shared indexes cannot be created after initdb")));
863 if (shared_relation && tableSpaceId != GLOBALTABLESPACE_OID)
864 elog(
ERROR,
"shared relations must be placed in pg_global tablespace");
877 (
errcode(ERRCODE_DUPLICATE_TABLE),
878 errmsg(
"relation \"%s\" already exists, skipping",
879 indexRelationName)));
885 (
errcode(ERRCODE_DUPLICATE_TABLE),
886 errmsg(
"relation \"%s\" already exists",
887 indexRelationName)));
900 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
910 accessMethodObjectId,
927 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
928 errmsg(
"pg_class index OID value not set when in binary upgrade mode")));
934 if ((relkind == RELKIND_INDEX) &&
937 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
938 errmsg(
"index relfilenumber value not set when in binary upgrade mode")));
966 accessMethodObjectId,
972 allow_system_table_mods,
994 indexRelation->
rd_rel->relowner = heapRelation->
rd_rel->relowner;
995 indexRelation->
rd_rel->relam = accessMethodObjectId;
1032 collationObjectId, classObjectId, coloptions,
1033 isprimary, is_exclusion,
1075 char constraintType;
1079 constraintType = CONSTRAINT_PRIMARY;
1081 constraintType = CONSTRAINT_UNIQUE;
1082 else if (is_exclusion)
1083 constraintType = CONSTRAINT_EXCLUSION;
1086 elog(
ERROR,
"constraint must be PRIMARY, UNIQUE or EXCLUDE");
1097 allow_system_table_mods,
1100 *constraintId = localaddr.
objectId;
1104 bool have_simple_col =
false;
1117 have_simple_col =
true;
1127 if (!have_simple_col)
1162 collationObjectId[
i] != DEFAULT_COLLATION_OID)
1165 collationObjectId[
i]);
1208 indexRelationId, 0, is_internal);
1264 index_build(heapRelation, indexRelation, indexInfo,
false,
true);
1273 return indexRelationId;
1287 Oid tablespaceOid,
const char *newName)
1295 Datum indclassDatum,
1316 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1317 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
1322 elog(
ERROR,
"cache lookup failed for index %u", oldIndexId);
1324 Anum_pg_index_indclass);
1328 Anum_pg_index_indoption);
1334 elog(
ERROR,
"cache lookup failed for relation %u", oldIndexId);
1336 Anum_pg_class_reloptions, &isnull);
1349 Anum_pg_index_indexprs);
1360 Anum_pg_index_indpred);
1423 indexRelation->
rd_rel->relam,
1454 Oid indexRelationId)
1458 int save_sec_context;
1492 index_build(heapRel, indexRelation, indexInfo,
false,
true);
1536 Oid indexConstraintOid;
1552 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1556 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1566 isPartition = newClassForm->relispartition;
1567 newClassForm->relispartition = oldClassForm->relispartition;
1568 oldClassForm->relispartition = isPartition;
1582 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1586 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1595 newIndexForm->indisprimary = oldIndexForm->indisprimary;
1596 oldIndexForm->indisprimary =
false;
1597 newIndexForm->indisexclusion = oldIndexForm->indisexclusion;
1598 oldIndexForm->indisexclusion =
false;
1599 newIndexForm->indimmediate = oldIndexForm->indimmediate;
1600 oldIndexForm->indimmediate =
true;
1603 newIndexForm->indisreplident = oldIndexForm->indisreplident;
1606 newIndexForm->indisclustered = oldIndexForm->indisclustered;
1612 newIndexForm->indisvalid =
true;
1613 oldIndexForm->indisvalid =
false;
1614 oldIndexForm->indisclustered =
false;
1615 oldIndexForm->indisreplident =
false;
1632 constraintOids =
lappend_oid(constraintOids, indexConstraintOid);
1637 foreach(lc, constraintOids)
1650 elog(
ERROR,
"could not find tuple for constraint %u", constraintOid);
1654 if (conForm->conindid == oldIndexId)
1656 conForm->conindid = newIndexId;
1665 Anum_pg_trigger_tgconstraint,
1676 if (tgForm->tgconstrindid != oldIndexId)
1683 tgForm->tgconstrindid = newIndexId;
1702 bool nulls[Natts_pg_description] = {0};
1703 bool replaces[Natts_pg_description] = {0};
1706 replaces[Anum_pg_description_objoid - 1] =
true;
1709 Anum_pg_description_objoid,
1713 Anum_pg_description_classoid,
1717 Anum_pg_description_objsubid,
1729 values, nulls, replaces);
1779 Anum_pg_attribute_attrelid,
1783 true, NULL, 1,
key);
1788 Datum repl_val[Natts_pg_attribute];
1789 bool repl_null[Natts_pg_attribute];
1790 bool repl_repl[Natts_pg_attribute];
1795 if (att->attisdropped)
1804 if (attstattarget == att->attstattarget)
1807 memset(repl_val, 0,
sizeof(repl_val));
1808 memset(repl_null,
false,
sizeof(repl_null));
1809 memset(repl_repl,
false,
sizeof(repl_repl));
1811 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
1812 repl_val[Anum_pg_attribute_attstattarget - 1] =
Int16GetDatum(attstattarget);
1816 repl_val, repl_null, repl_repl);
1908 Oid indexRelationId,
1909 Oid parentConstraintId,
1911 const char *constraintName,
1912 char constraintType,
1914 bool allow_system_table_mods,
1923 bool mark_as_primary;
1936 if (!allow_system_table_mods &&
1940 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1941 errmsg(
"user-defined indexes on system catalog tables are not supported")));
1945 constraintType != CONSTRAINT_EXCLUSION)
1946 elog(
ERROR,
"constraints cannot have index expressions");
2045 trigger->
trigname = (constraintType == CONSTRAINT_PRIMARY) ?
2046 "PK_ConstraintTrigger" :
2047 "Unique_ConstraintTrigger";
2051 trigger->
row =
true;
2052 trigger->
timing = TRIGGER_TYPE_AFTER;
2053 trigger->
events = TRIGGER_TYPE_INSERT | TRIGGER_TYPE_UPDATE;
2075 (mark_as_primary || deferrable))
2081 bool marked_as_primary =
false;
2088 elog(
ERROR,
"cache lookup failed for index %u", indexRelationId);
2091 if (mark_as_primary && !indexForm->indisprimary)
2093 indexForm->indisprimary =
true;
2095 marked_as_primary =
true;
2098 if (deferrable && indexForm->indimmediate)
2100 indexForm->indimmediate =
false;
2114 if (marked_as_primary)
2160 (!concurrent && !concurrent_lock_mode));
2182 userHeapRelation =
table_open(heapId, lockmode);
2183 userIndexRelation =
index_open(indexId, lockmode);
2239 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2240 errmsg(
"DROP INDEX CONCURRENTLY must be first action in transaction")));
2335 if (RELKIND_HAS_STORAGE(userIndexRelation->
rd_rel->relkind))
2357 elog(
ERROR,
"cache lookup failed for index %u", indexId);
2438 numAtts = indexStruct->indnatts;
2440 elog(
ERROR,
"invalid indnatts %d for index %u",
2448 indexStruct->indnkeyatts,
2449 index->rd_rel->relam,
2452 indexStruct->indisunique,
2453 indexStruct->indnullsnotdistinct,
2454 indexStruct->indisready,
2456 index->rd_indam->amsummarizing);
2459 for (
i = 0;
i < numAtts;
i++)
2463 if (indexStruct->indisexclusion)
2499 numAtts = indexStruct->indnatts;
2501 elog(
ERROR,
"invalid indnatts %d for index %u",
2509 indexStruct->indnkeyatts,
2510 index->rd_rel->relam,
2513 indexStruct->indisunique,
2514 indexStruct->indnullsnotdistinct,
2515 indexStruct->indisready,
2517 index->rd_indam->amsummarizing);
2520 for (
i = 0;
i < numAtts;
i++)
2540 Oid *collations1,
Oid *collations2,
2541 Oid *opfamilies1,
Oid *opfamilies2,
2585 if (collations1[
i] != collations2[
i])
2587 if (opfamilies1[
i] != opfamilies2[
i])
2599 bool found_whole_row;
2605 if (found_whole_row)
2623 bool found_whole_row;
2629 if (found_whole_row)
2673 if (
index->rd_rel->relam != BTREE_AM_OID)
2674 elog(
ERROR,
"unexpected non-btree speculative unique index");
2685 for (
i = 0;
i < indnkeyatts;
i++)
2694 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
2749 else if (keycol != 0)
2762 if (indexpr_item == NULL)
2763 elog(
ERROR,
"wrong number of index expressions");
2773 if (indexpr_item != NULL)
2774 elog(
ERROR,
"wrong number of index expressions");
2869 elog(
ERROR,
"could not find tuple for relation %u", relid);
2873 Assert(rd_rel->relkind != RELKIND_PARTITIONED_INDEX);
2881 if (reltuples == 0 && rd_rel->reltuples < 0)
2887 if (rd_rel->relhasindex != hasindex)
2889 rd_rel->relhasindex = hasindex;
2898 if (rd_rel->relkind != RELKIND_INDEX)
2903 if (rd_rel->relpages != (
int32) relpages)
2905 rd_rel->relpages = (
int32) relpages;
2908 if (rd_rel->reltuples != (
float4) reltuples)
2910 rd_rel->reltuples = (
float4) reltuples;
2913 if (rd_rel->relallvisible != (
int32) relallvisible)
2915 rd_rel->relallvisible = (
int32) relallvisible;
2965 int save_sec_context;
2983 indexRelation->
rd_rel->relam == BTREE_AM_OID)
2995 (
errmsg_internal(
"building index \"%s\" on table \"%s\" with request for %d parallel workers",
3012 const int progress_index[] = {
3020 const int64 progress_vals[] = {
3043 if (indexRelation->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
3093 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3097 Assert(!indexForm->indcheckxmin);
3099 indexForm->indcheckxmin =
true;
3202 if (predicate != NULL)
3204 if (!
ExecQual(predicate, econtext))
3221 indexRelation, indexInfo,
3313 int save_sec_context;
3317 const int progress_index[] = {
3324 const int64 progress_vals[] = {
3360 ivinfo.
index = indexRelation;
3361 ivinfo.
heaprel = heapRelation;
3387 const int progress_index[] = {
3392 const int64 progress_vals[] = {
3416 "validate_index found %.0f heap tuples, %.0f index tuples; inserted %.0f missing tuples",
3466 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3474 Assert(indexForm->indislive);
3475 Assert(!indexForm->indisready);
3476 Assert(!indexForm->indisvalid);
3477 indexForm->indisready =
true;
3481 Assert(indexForm->indislive);
3482 Assert(indexForm->indisready);
3483 Assert(!indexForm->indisvalid);
3484 indexForm->indisvalid =
true;
3501 indexForm->indisvalid =
false;
3502 indexForm->indisclustered =
false;
3503 indexForm->indisreplident =
false;
3514 Assert(!indexForm->indisvalid);
3515 Assert(!indexForm->indisclustered);
3516 Assert(!indexForm->indisreplident);
3517 indexForm->indisready =
false;
3518 indexForm->indislive =
false;
3545 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3550 result =
index->indrelid;
3566 int save_sec_context;
3569 volatile bool skipped_constraint =
false;
3572 bool set_tablespace =
false;
3607 const int progress_cols[] = {
3611 const int64 progress_vals[] = {
3635 if (iRel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
3636 elog(
ERROR,
"cannot reindex partitioned index \"%s.%s\"",
3646 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3647 errmsg(
"cannot reindex temporary tables of other sessions")));
3657 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3658 errmsg(
"cannot reindex invalid index on TOAST table")));
3673 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3674 errmsg(
"cannot move system relation \"%s\"",
3680 set_tablespace =
true;
3714 if (skip_constraint_checks)
3717 skipped_constraint =
true;
3732 index_build(heapRelation, iRel, indexInfo,
true,
true);
3770 if (!skipped_constraint)
3783 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3786 index_bad = (!indexForm->indisvalid ||
3787 !indexForm->indisready ||
3788 !indexForm->indislive);
3791 early_pruning_enabled)
3794 indexForm->indcheckxmin =
false;
3795 else if (index_bad || early_pruning_enabled)
3796 indexForm->indcheckxmin =
true;
3797 indexForm->indisvalid =
true;
3798 indexForm->indisready =
true;
3799 indexForm->indislive =
true;
3818 (
errmsg(
"index \"%s\" was reindexed",
3901 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
3902 elog(
ERROR,
"cannot reindex partitioned table \"%s.%s\"",
3906 toast_relid = rel->
rd_rel->reltoastrelid;
3932 persistence = RELPERSISTENCE_UNLOGGED;
3934 persistence = RELPERSISTENCE_PERMANENT;
3936 persistence = rel->
rd_rel->relpersistence;
3940 foreach(indexId, indexIds)
3954 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3955 errmsg(
"cannot reindex invalid index \"%s.%s\" on TOAST table, skipping",
3962 persistence, params);
3980 result = (indexIds !=
NIL);
4063 elog(
ERROR,
"cannot reindex while reindexing");
4095 elog(
ERROR,
"cannot reindex while reindexing");
4097 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
4110 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
#define AttrNumberGetAttrOffset(attNum)
#define InvalidAttrNumber
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
@ PROGRESS_COMMAND_CREATE_INDEX
static Datum values[MAXATTR]
void index_register(Oid heap, Oid ind, IndexInfo *indexInfo)
#define RelationGetNumberOfBlocks(reln)
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
TransactionId MultiXactId
#define PointerIsValid(pointer)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
#define OidIsValid(objectId)
bool IsToastNamespace(Oid namespaceId)
bool IsSystemRelation(Relation relation)
RelFileNumber GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
bool IsCatalogRelation(Relation relation)
elog(ERROR, "%s: %s", p2, msg)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
ExprState * ExecPrepareQual(List *qual, EState *estate)
List * ExecPrepareExprList(List *nodes, EState *estate)
void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
EState * CreateExecutorState(void)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
static bool ExecQual(ExprState *state, ExprContext *econtext)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
Datum Int64GetDatum(int64 X)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
int NewGUCNestLevel(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, Datum *attoptions, CatalogIndexState indstate)
void DeleteRelationTuple(Oid relid)
void DeleteAttributeTuples(Oid relid)
void RemoveStatistics(Oid relid, AttrNumber attnum)
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
void CopyStatistics(Oid fromrelid, Oid torelid)
void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, Datum reloptions)
Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, RelFileNumber relfilenumber, Oid accessmtd, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods, TransactionId *relfrozenxid, MultiXactId *relminmxid, bool create_storage)
void heap_inplace_update(Relation relation, HeapTuple tuple)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
bool ReindexIsProcessingIndex(Oid indexOid)
static bool validate_index_callback(ItemPointer itemptr, void *opaque)
ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
void ResetReindexState(int nestLevel)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
static int reindexingNestLevel
void index_concurrently_set_dead(Oid heapId, Oid indexId)
static Oid currentlyReindexedHeap
static void ResetReindexProcessing(void)
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
void RestoreReindexState(void *reindexstate)
static void RemoveReindexPending(Oid indexOid)
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrMap *attmap)
static List * pendingReindexedIndexes
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber
IndexInfo * BuildDummyIndexInfo(Relation index)
static void AppendAttributeTuples(Relation indexRelation, Datum *attopts)
static void UpdateIndexRelation(Oid indexoid, Oid heapoid, Oid parentIndexId, IndexInfo *indexInfo, Oid *collationOids, Oid *classOids, int16 *coloptions, bool primary, bool isexclusion, bool immediate, bool isvalid, bool isready)
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, Oid tableSpaceId, Oid *collationObjectId, Oid *classObjectId, int16 *coloptions, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)
void SerializeReindexState(Size maxsize, char *start_address)
static void index_update_stats(Relation rel, bool hasindex, double reltuples)
static bool relationHasPrimaryKey(Relation rel)
static void SetReindexProcessing(Oid heapOid, Oid indexOid)
static void IndexCheckExclusion(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)
static void InitializeAttributeOids(Relation indexRelation, int numatts, Oid indexoid)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
Oid binary_upgrade_next_index_pg_class_oid
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
void reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, ReindexParams *params)
bool ReindexIsProcessingHeap(Oid heapOid)
static bool ReindexIsCurrentlyProcessingIndex(Oid indexOid)
bool reindex_relation(Oid relid, int flags, ReindexParams *params)
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
static TupleDesc ConstructTupleDescriptor(Relation heapRelation, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, Oid *collationObjectId, Oid *classObjectId)
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
static void SetReindexPending(List *indexes)
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
static Oid currentlyReindexedIndex
Size EstimateReindexStateSpace(void)
IndexInfo * BuildIndexInfo(Relation index)
#define INDEX_CREATE_IS_PRIMARY
#define INDEX_CREATE_IF_NOT_EXISTS
#define REINDEX_REL_PROCESS_TOAST
#define INDEX_CREATE_PARTITIONED
#define REINDEXOPT_MISSING_OK
#define INDEX_CREATE_INVALID
static int64 itemptr_encode(ItemPointer itemptr)
#define INDEX_CREATE_ADD_CONSTRAINT
#define INDEX_CREATE_SKIP_BUILD
#define INDEX_CONSTR_CREATE_UPDATE_INDEX
#define REINDEX_REL_FORCE_INDEXES_UNLOGGED
#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS
#define INDEX_CONSTR_CREATE_DEFERRABLE
#define REINDEXOPT_REPORT_PROGRESS
#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY
#define REINDEX_REL_SUPPRESS_INDEX_USE
#define REINDEX_REL_FORCE_INDEXES_PERMANENT
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
#define INDEX_CREATE_CONCURRENT
#define REINDEXOPT_VERBOSE
#define REINDEX_REL_CHECK_CONSTRAINTS
void index_close(Relation relation, LOCKMODE lockmode)
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
Relation index_open(Oid relationId, LOCKMODE lockmode)
bytea * index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, bool validate)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogCloseIndexes(CatalogIndexState indstate)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
int2vector * buildint2vector(const int16 *int2s, int n)
void CacheInvalidateRelcache(Relation relation)
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
invalidindex index d is invalid
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
List * list_copy(const List *oldlist)
List * list_delete_oid(List *list, Oid datum)
void list_free(List *list)
bool list_member_oid(const List *list, Oid datum)
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
void LockRelation(Relation relation, LOCKMODE lockmode)
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define AccessExclusiveLock
#define ShareUpdateExclusiveLock
bool get_rel_relispartition(Oid relid)
char get_rel_persistence(Oid relid)
bool get_index_isvalid(Oid index_oid)
int get_attstattarget(Oid relid, AttrNumber attnum)
char * get_namespace_name(Oid nspid)
Datum get_attoptions(Oid relid, int16 attnum)
Oid get_rel_namespace(Oid relid)
RegProcedure get_opcode(Oid opno)
char * get_rel_name(Oid relid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
bool get_collation_isdeterministic(Oid colloid)
Oid get_base_element_type(Oid typid)
Oid get_relname_relid(const char *relname, Oid relnamespace)
List * make_ands_implicit(Expr *clause)
Expr * make_ands_explicit(List *andclauses)
IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool nulls_not_distinct, bool isready, bool concurrent, bool summarizing)
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
#define IsBootstrapProcessingMode()
#define SECURITY_RESTRICTED_OPERATION
#define CHECK_FOR_INTERRUPTS()
#define IsNormalProcessingMode()
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
#define InvalidMultiXactId
void namestrcpy(Name name, const char *str)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)
#define ObjectAddressSet(addr, class_id, object_id)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
oidvector * buildoidvector(const Oid *oids, int n)
char * nodeToString(const void *obj)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
List * SystemFuncName(char *name)
List * get_partition_ancestors(Oid relid)
#define ATTRIBUTE_FIXED_PART_SIZE
FormData_pg_attribute * Form_pg_attribute
FormData_pg_class * Form_pg_class
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int conInhCount, bool conNoInherit, bool is_internal)
FormData_pg_constraint * Form_pg_constraint
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Oid get_index_constraint(Oid indexId)
List * get_index_ref_constraints(Oid indexId)
FormData_pg_index * Form_pg_index
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
static int list_length(const List *l)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
FormData_pg_opclass * Form_pg_opclass
const char * pg_rusage_show(const PGRUsage *ru0)
void pg_rusage_init(PGRUsage *ru0)
FormData_pg_trigger * Form_pg_trigger
FormData_pg_type * Form_pg_type
void pgstat_copy_relation_stats(Relation dst, Relation src)
void pgstat_drop_relation(Relation rel)
int plan_create_index_workers(Oid tableOid, Oid indexOid)
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
void TransferPredicateLocksToHeapRelation(Relation relation)
#define PROGRESS_CREATEIDX_PHASE_BUILD
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_TABLESCAN
#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_SORT
#define PROGRESS_SCAN_BLOCKS_DONE
#define PROGRESS_CREATEIDX_TUPLES_DONE
#define PROGRESS_CREATEIDX_SUBPHASE
#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE
#define PROGRESS_CREATEIDX_PHASE
#define PROGRESS_CREATEIDX_COMMAND_REINDEX
#define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN
#define PROGRESS_SCAN_BLOCKS_TOTAL
#define PROGRESS_CREATEIDX_INDEX_OID
#define PROGRESS_CREATEIDX_COMMAND
void * stringToNode(const char *str)
#define RelationGetForm(relation)
#define RelationGetRelid(relation)
static SMgrRelation RelationGetSmgr(Relation rel)
#define RelationGetDescr(relation)
#define RelationIsMapped(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationIsValid(relation)
#define RelationGetNamespace(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
List * RelationGetIndexList(Relation relation)
void RelationInitIndexAccessInfo(Relation relation)
List * RelationGetIndexPredicate(Relation relation)
List * RelationGetDummyIndexExpressions(Relation relation)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
void RelationForgetRelation(Oid rid)
void RelationAssumeNewRelfilelocator(Relation relation)
Datum * RelationGetIndexRawAttOptions(Relation indexrel)
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
List * RelationGetIndexExpressions(Relation relation)
#define InvalidRelFileNumber
#define RelFileNumberIsValid(relnumber)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Size mul_size(Size s1, Size s2)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Snapshot GetLatestSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
bool ActiveSnapshotSet(void)
Snapshot RegisterSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
#define EarlyPruningEnabled(rel)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void RelationDropStorage(Relation rel)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
MemoryContext ecxt_per_tuple_memory
TupleTableSlot * ecxt_scantuple
ambuildempty_function ambuildempty
uint16 * ii_ExclusionStrats
Datum * ii_OpclassOptions
ExprState * ii_PredicateState
List * ii_ExpressionsState
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
BufferAccessStrategy strategy
struct IndexAmRoutine * rd_indam
MemoryContext rd_indexcxt
Oid currentlyReindexedHeap
Oid currentlyReindexedIndex
int numPendingReindexedIndexes
Oid pendingReindexedIndexes[FLEXIBLE_ARRAY_MEMBER]
int16 values[FLEXIBLE_ARRAY_MEMBER]
Oid values[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
static void table_endscan(TableScanDesc scan)
static void table_index_validate_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
void CheckTableNotInUse(Relation rel, const char *stmt)
bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)
#define InvalidCompressionMethod
#define InvalidTransactionId
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
TupleDesc CreateTemplateTupleDesc(int natts)
#define TupleDescAttr(tupdesc, i)
void tuplesort_performsort(Tuplesortstate *state)
void tuplesort_end(Tuplesortstate *state)
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Tuplesortstate * tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, SortCoordinate coordinate, int sortopt)
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen)
int GetCurrentTransactionNestLevel(void)
void CommandCounterIncrement(void)
TransactionId GetTopTransactionIdIfAny(void)
void StartTransactionCommand(void)
bool IsInParallelMode(void)
void CommitTransactionCommand(void)