75 #include "utils/fmgroids.h" 107 Oid accessMethodObjectId,
108 Oid *collationObjectId,
111 int numatts,
Oid indexoid);
162 foreach(indexoidscan, indexoidlist)
169 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
216 if ((is_alter_table || heapRel->
rd_rel->relispartition) &&
220 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
221 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
238 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
239 errmsg(
"primary keys cannot be expressions")));
249 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
253 if (!attform->attnotnull)
255 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
256 errmsg(
"primary key column \"%s\" is not marked NOT NULL",
272 Oid accessMethodObjectId,
273 Oid *collationObjectId,
301 for (i = 0; i < numatts; i++)
312 to->attstattarget = -1;
313 to->attcacheoff = -1;
314 to->attislocal =
true;
315 to->attcollation = (i < numkeyatts) ?
321 if (colnames_item == NULL)
322 elog(
ERROR,
"too few entries in colnames list");
324 colnames_item =
lnext(indexColNames, colnames_item);
339 elog(
ERROR,
"invalid column number %d", atnum);
343 to->atttypid = from->atttypid;
344 to->attlen = from->attlen;
345 to->attndims = from->attndims;
346 to->atttypmod = from->atttypmod;
347 to->attbyval = from->attbyval;
348 to->attstorage = from->attstorage;
349 to->attalign = from->attalign;
356 if (indexpr_item == NULL)
357 elog(
ERROR,
"too few entries in indexprs list");
367 elog(
ERROR,
"cache lookup failed for type %u", keyType);
373 to->atttypid = keyType;
374 to->attlen = typeTup->typlen;
375 to->attbyval = typeTup->typbyval;
376 to->attstorage = typeTup->typstorage;
377 to->attalign = typeTup->typalign;
392 to->atttypid, to->attcollation,
410 if (i < indexInfo->ii_NumIndexKeyAttrs)
414 elog(
ERROR,
"cache lookup failed for opclass %u",
418 keyType = opclassTup->opckeytype;
429 if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
433 elog(
ERROR,
"could not get element type of array type %u",
444 if (
OidIsValid(keyType) && keyType != to->atttypid)
448 elog(
ERROR,
"cache lookup failed for type %u", keyType);
451 to->atttypid = keyType;
453 to->attlen = typeTup->typlen;
454 to->attbyval = typeTup->typbyval;
455 to->attalign = typeTup->typalign;
456 to->attstorage = typeTup->typstorage;
481 for (i = 0; i < numatts; i += 1)
542 bool nulls[Natts_pg_index];
570 exprsDatum = (
Datum) 0;
585 predDatum = (
Datum) 0;
596 MemSet(nulls,
false,
sizeof(nulls));
603 values[Anum_pg_index_indisprimary - 1] =
BoolGetDatum(primary);
604 values[Anum_pg_index_indisexclusion - 1] =
BoolGetDatum(isexclusion);
605 values[Anum_pg_index_indimmediate - 1] =
BoolGetDatum(immediate);
606 values[Anum_pg_index_indisclustered - 1] =
BoolGetDatum(
false);
607 values[Anum_pg_index_indisvalid - 1] =
BoolGetDatum(isvalid);
608 values[Anum_pg_index_indcheckxmin - 1] =
BoolGetDatum(
false);
609 values[Anum_pg_index_indisready - 1] =
BoolGetDatum(isready);
610 values[Anum_pg_index_indislive - 1] =
BoolGetDatum(
true);
611 values[Anum_pg_index_indisreplident - 1] =
BoolGetDatum(
false);
613 values[Anum_pg_index_indcollation - 1] =
PointerGetDatum(indcollation);
616 values[Anum_pg_index_indexprs - 1] = exprsDatum;
617 if (exprsDatum == (
Datum) 0)
618 nulls[Anum_pg_index_indexprs - 1] =
true;
619 values[Anum_pg_index_indpred - 1] = predDatum;
620 if (predDatum == (
Datum) 0)
621 nulls[Anum_pg_index_indpred - 1] =
true;
687 const char *indexRelationName,
689 Oid parentIndexRelid,
690 Oid parentConstraintId,
694 Oid accessMethodObjectId,
696 Oid *collationObjectId,
702 bool allow_system_table_mods,
710 bool shared_relation;
711 bool mapped_relation;
725 Assert((constr_flags == 0) ||
730 relkind = partitioned ? RELKIND_PARTITIONED_INDEX : RELKIND_INDEX;
742 shared_relation = heapRelation->
rd_rel->relisshared;
744 relpersistence = heapRelation->
rd_rel->relpersistence;
750 elog(
ERROR,
"must index at least one column");
752 if (!allow_system_table_mods &&
756 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
757 errmsg(
"user-defined indexes on system catalog tables are not supported")));
780 Oid collation = collationObjectId[
i];
781 Oid opclass = classObjectId[
i];
785 if ((opclass == TEXT_BTREE_PATTERN_OPS_OID ||
786 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||
787 opclass == BPCHAR_BTREE_PATTERN_OPS_OID) &&
794 elog(
ERROR,
"cache lookup failed for operator class %u", opclass);
796 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
797 errmsg(
"nondeterministic collations are not supported for operator class \"%s\"",
811 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
812 errmsg(
"concurrent index creation on system catalog tables is not supported")));
818 if (concurrent && is_exclusion)
820 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
821 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
829 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
830 errmsg(
"shared indexes cannot be created after initdb")));
835 if (shared_relation && tableSpaceId != GLOBALTABLESPACE_OID)
836 elog(
ERROR,
"shared relations must be placed in pg_global tablespace");
849 (
errcode(ERRCODE_DUPLICATE_TABLE),
850 errmsg(
"relation \"%s\" already exists, skipping",
851 indexRelationName)));
857 (
errcode(ERRCODE_DUPLICATE_TABLE),
858 errmsg(
"relation \"%s\" already exists",
859 indexRelationName)));
862 if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0 &&
872 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
882 accessMethodObjectId,
899 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
900 errmsg(
"pg_class index OID value not set when in binary upgrade mode")));
922 accessMethodObjectId,
928 allow_system_table_mods,
949 indexRelation->
rd_rel->relowner = heapRelation->
rd_rel->relowner;
950 indexRelation->
rd_rel->relam = accessMethodObjectId;
987 collationObjectId, classObjectId, coloptions,
988 isprimary, is_exclusion,
990 !concurrent && !invalid,
1026 *colls_no_version =
NIL;
1030 if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0)
1032 char constraintType;
1036 constraintType = CONSTRAINT_PRIMARY;
1038 constraintType = CONSTRAINT_UNIQUE;
1039 else if (is_exclusion)
1040 constraintType = CONSTRAINT_EXCLUSION;
1043 elog(
ERROR,
"constraint must be PRIMARY, UNIQUE or EXCLUDE");
1054 allow_system_table_mods,
1057 *constraintId = localaddr.
objectId;
1061 bool have_simple_col =
false;
1074 have_simple_col =
true;
1084 if (!have_simple_col)
1113 Oid colloid = collationObjectId[
i];
1117 Oid opclass = classObjectId[
i];
1127 if (opclass == TEXT_BTREE_PATTERN_OPS_OID ||
1128 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||
1129 opclass == BPCHAR_BTREE_PATTERN_OPS_OID)
1130 colls_no_version =
lappend_oid(colls_no_version, colloid);
1138 Assert(i < indexTupDesc->natts);
1153 if (colls_no_version !=
NIL && colls !=
NIL)
1157 if (colls_no_version !=
NIL)
1195 Assert((flags & INDEX_CREATE_ADD_CONSTRAINT) == 0);
1200 indexRelationId, 0, is_internal);
1241 else if ((flags & INDEX_CREATE_SKIP_BUILD) != 0)
1256 index_build(heapRelation, indexRelation, indexInfo,
false,
true);
1265 return indexRelationId;
1280 const char *version,
1285 char *current_version;
1288 if (!version || otherObject->
classId != CollationRelationId)
1293 if (!current_version)
1304 if (strcmp(current_version, version) != 0)
1311 (
errmsg(
"index \"%s\" depends on collation \"%s\" version \"%s\", but the current version is \"%s\"",
1316 errdetail(
"The index may be corrupted due to changes in sort order."),
1317 errhint(
"REINDEX to avoid the risk of corruption.")));
1343 object.classId = RelationRelationId;
1344 object.objectId =
relid;
1345 object.objectSubId = 0;
1357 const char *version,
1364 if (!version || otherObject->
classId != CollationRelationId)
1385 object.
classId = RelationRelationId;
1386 object.objectId =
relid;
1387 object.objectSubId = 0;
1407 Datum indclassDatum,
1428 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1429 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
1434 elog(
ERROR,
"cache lookup failed for index %u", oldIndexId);
1436 Anum_pg_index_indclass, &isnull);
1441 Anum_pg_index_indoption, &isnull);
1448 elog(
ERROR,
"cache lookup failed for relation %u", oldIndexId);
1450 Anum_pg_class_reloptions, &isnull);
1463 Anum_pg_index_indexprs, &isnull);
1475 Anum_pg_index_indpred, &isnull);
1528 indexRelation->
rd_rel->relam,
1529 indexRelation->
rd_rel->reltablespace,
1559 Oid indexRelationId)
1585 index_build(heapRel, indexRelation, indexInfo,
false,
true);
1623 Oid indexConstraintOid;
1639 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1643 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1653 isPartition = newClassForm->relispartition;
1654 newClassForm->relispartition = oldClassForm->relispartition;
1655 oldClassForm->relispartition = isPartition;
1669 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1673 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1682 newIndexForm->indisprimary = oldIndexForm->indisprimary;
1683 oldIndexForm->indisprimary =
false;
1684 newIndexForm->indisexclusion = oldIndexForm->indisexclusion;
1685 oldIndexForm->indisexclusion =
false;
1686 newIndexForm->indimmediate = oldIndexForm->indimmediate;
1687 oldIndexForm->indimmediate =
true;
1690 newIndexForm->indisreplident = oldIndexForm->indisreplident;
1693 newIndexForm->indisclustered = oldIndexForm->indisclustered;
1699 newIndexForm->indisvalid =
true;
1700 oldIndexForm->indisvalid =
false;
1701 oldIndexForm->indisclustered =
false;
1702 oldIndexForm->indisreplident =
false;
1719 constraintOids =
lappend_oid(constraintOids, indexConstraintOid);
1724 foreach(lc, constraintOids)
1737 elog(
ERROR,
"could not find tuple for constraint %u", constraintOid);
1741 if (conForm->conindid == oldIndexId)
1743 conForm->conindid = newIndexId;
1752 Anum_pg_trigger_tgconstraint,
1763 if (tgForm->tgconstrindid != oldIndexId)
1770 tgForm->tgconstrindid = newIndexId;
1789 bool nulls[Natts_pg_description] = {0};
1790 bool replaces[Natts_pg_description] = {0};
1793 replaces[Anum_pg_description_objoid - 1] =
true;
1796 Anum_pg_description_objoid,
1800 Anum_pg_description_classoid,
1804 Anum_pg_description_objsubid,
1816 values, nulls, replaces);
1965 Oid indexRelationId,
1966 Oid parentConstraintId,
1968 const char *constraintName,
1969 char constraintType,
1971 bool allow_system_table_mods,
1980 bool mark_as_primary;
1993 if (!allow_system_table_mods &&
1997 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1998 errmsg(
"user-defined indexes on system catalog tables are not supported")));
2002 constraintType != CONSTRAINT_EXCLUSION)
2003 elog(
ERROR,
"constraints cannot have index expressions");
2100 trigger->
trigname = (constraintType == CONSTRAINT_PRIMARY) ?
2101 "PK_ConstraintTrigger" :
2102 "Unique_ConstraintTrigger";
2106 trigger->
row =
true;
2107 trigger->
timing = TRIGGER_TYPE_AFTER;
2108 trigger->
events = TRIGGER_TYPE_INSERT | TRIGGER_TYPE_UPDATE;
2130 (mark_as_primary || deferrable))
2142 elog(
ERROR,
"cache lookup failed for index %u", indexRelationId);
2145 if (mark_as_primary && !indexForm->indisprimary)
2147 indexForm->indisprimary =
true;
2151 if (deferrable && indexForm->indimmediate)
2153 indexForm->indimmediate =
false;
2204 (!concurrent && !concurrent_lock_mode));
2226 userHeapRelation =
table_open(heapId, lockmode);
2227 userIndexRelation =
index_open(indexId, lockmode);
2283 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2284 errmsg(
"DROP INDEX CONCURRENTLY must be first action in transaction")));
2379 if (userIndexRelation->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
2398 elog(
ERROR,
"cache lookup failed for index %u", indexId);
2479 numAtts = indexStruct->indnatts;
2481 elog(
ERROR,
"invalid indnatts %d for index %u",
2489 indexStruct->indnkeyatts,
2493 indexStruct->indisunique,
2494 indexStruct->indisready,
2498 for (i = 0; i < numAtts; i++)
2502 if (indexStruct->indisexclusion)
2538 numAtts = indexStruct->indnatts;
2540 elog(
ERROR,
"invalid indnatts %d for index %u",
2548 indexStruct->indnkeyatts,
2552 indexStruct->indisunique,
2553 indexStruct->indisready,
2557 for (i = 0; i < numAtts; i++)
2577 Oid *collations1,
Oid *collations2,
2578 Oid *opfamilies1,
Oid *opfamilies2,
2619 if (collations1[i] != collations2[i])
2621 if (opfamilies1[i] != opfamilies2[i])
2633 bool found_whole_row;
2639 if (found_whole_row)
2657 bool found_whole_row;
2663 if (found_whole_row)
2707 if (index->
rd_rel->relam != BTREE_AM_OID)
2708 elog(
ERROR,
"unexpected non-btree speculative unique index");
2719 for (i = 0; i < indnkeyatts; i++)
2728 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
2783 else if (keycol != 0)
2796 if (indexpr_item == NULL)
2797 elog(
ERROR,
"wrong number of index expressions");
2807 if (indexpr_item != NULL)
2808 elog(
ERROR,
"wrong number of index expressions");
2903 elog(
ERROR,
"could not find tuple for relation %u", relid);
2907 Assert(rd_rel->relkind != RELKIND_PARTITIONED_INDEX);
2915 if (reltuples == 0 && rd_rel->reltuples < 0)
2921 if (rd_rel->relhasindex != hasindex)
2923 rd_rel->relhasindex = hasindex;
2932 if (rd_rel->relkind != RELKIND_INDEX)
2937 if (rd_rel->relpages != (
int32) relpages)
2939 rd_rel->relpages = (
int32) relpages;
2942 if (rd_rel->reltuples != (
float4) reltuples)
2944 rd_rel->reltuples = (
float4) reltuples;
2947 if (rd_rel->relallvisible != (
int32) relallvisible)
2949 rd_rel->relallvisible = (
int32) relallvisible;
2999 int save_sec_context;
3017 indexRelation->
rd_rel->relam == BTREE_AM_OID)
3024 (
errmsg(
"building index \"%s\" on table \"%s\" serially",
3029 (
errmsg_plural(
"building index \"%s\" on table \"%s\" with request for %d parallel worker",
3030 "building index \"%s\" on table \"%s\" with request for %d parallel workers",
3048 const int index[] = {
3056 const int64
val[] = {
3079 if (indexRelation->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
3130 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3134 Assert(!indexForm->indcheckxmin);
3136 indexForm->indcheckxmin =
true;
3239 if (predicate != NULL)
3241 if (!
ExecQual(predicate, econtext))
3258 indexRelation, indexInfo,
3259 &(slot->
tts_tid), values, isnull,
3350 int save_sec_context;
3354 const int index[] = {
3361 const int64
val[] = {
3397 ivinfo.
index = indexRelation;
3423 const int index[] = {
3428 const int64
val[] = {
3452 "validate_index found %.0f heap tuples, %.0f index tuples; inserted %.0f missing tuples",
3502 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3510 Assert(indexForm->indislive);
3511 Assert(!indexForm->indisready);
3512 Assert(!indexForm->indisvalid);
3513 indexForm->indisready =
true;
3517 Assert(indexForm->indislive);
3518 Assert(indexForm->indisready);
3519 Assert(!indexForm->indisvalid);
3520 indexForm->indisvalid =
true;
3538 indexForm->indisvalid =
false;
3539 indexForm->indisclustered =
false;
3540 indexForm->indisreplident =
false;
3551 Assert(!indexForm->indisvalid);
3552 Assert(!indexForm->indisclustered);
3553 Assert(!indexForm->indisreplident);
3554 indexForm->indisready =
false;
3555 indexForm->indislive =
false;
3582 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3585 Assert(index->indexrelid == indexId);
3587 result = index->indrelid;
3603 volatile bool skipped_constraint =
false;
3652 if (iRel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
3653 elog(
ERROR,
"cannot reindex partitioned index \"%s.%s\"",
3663 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3664 errmsg(
"cannot reindex temporary tables of other sessions")));
3674 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3675 errmsg(
"cannot reindex invalid index on TOAST table")));
3693 if (skip_constraint_checks)
3696 skipped_constraint =
true;
3711 index_build(heapRelation, iRel, indexInfo,
true,
true);
3749 if (!skipped_constraint)
3762 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3765 index_bad = (!indexForm->indisvalid ||
3766 !indexForm->indisready ||
3767 !indexForm->indislive);
3770 early_pruning_enabled)
3773 indexForm->indcheckxmin =
false;
3774 else if (index_bad || early_pruning_enabled)
3775 indexForm->indcheckxmin =
true;
3776 indexForm->indisvalid =
true;
3777 indexForm->indisready =
true;
3778 indexForm->indislive =
true;
3797 (
errmsg(
"index \"%s\" was reindexed",
3877 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
3878 elog(
ERROR,
"cannot reindex partitioned table \"%s.%s\"",
3882 toast_relid = rel->
rd_rel->reltoastrelid;
3908 persistence = RELPERSISTENCE_UNLOGGED;
3910 persistence = RELPERSISTENCE_PERMANENT;
3912 persistence = rel->
rd_rel->relpersistence;
3916 foreach(indexId, indexIds)
3930 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3931 errmsg(
"cannot reindex invalid index \"%s.%s\" on TOAST table, skipping",
3938 persistence, params);
3956 result = (indexIds !=
NIL);
4036 elog(
ERROR,
"cannot reindex while reindexing");
4067 if (pendingReindexedIndexes)
4068 elog(
ERROR,
"cannot reindex while reindexing");
4070 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
4071 pendingReindexedIndexes =
list_copy(indexes);
4083 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
4111 pendingReindexedIndexes =
NIL;
4142 foreach(lc, pendingReindexedIndexes)
4163 pendingReindexedIndexes =
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
HeapTuple heap_copytuple(HeapTuple tuple)
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
struct IndexAmRoutine * rd_indam
Oid IndexGetRelation(Oid indexId, bool missing_ok)
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
void ResetReindexState(int nestLevel)
bool IsCatalogRelation(Relation relation)
List * SystemFuncName(char *name)
static Oid currentlyReindexedHeap
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_SORT
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrMap *attmap)
static void index_update_stats(Relation rel, bool hasindex, double reltuples)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
void tuplesort_performsort(Tuplesortstate *state)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
void table_close(Relation relation, LOCKMODE lockmode)
int errhint(const char *fmt,...)
#define DescriptionObjIndexId
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
void systable_endscan(SysScanDesc sysscan)
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
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)
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
#define TriggerConstraintIndexId
Oid currentlyReindexedIndex
Tuplesortstate * tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, SortCoordinate coordinate, bool randomAccess)
static bool ReindexIsCurrentlyProcessingIndex(Oid indexOid)
PgStat_Counter tuples_returned
bool IsSystemRelation(Relation relation)
#define INDEX_CREATE_IF_NOT_EXISTS
#define SECURITY_RESTRICTED_OPERATION
Snapshot RegisterSnapshot(Snapshot snapshot)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
static ListCell * lnext(const List *l, const ListCell *c)
TupleDesc CreateTemplateTupleDesc(int natts)
void SetUserIdAndSecContext(Oid userid, int sec_context)
bool equal(const void *a, const void *b)
#define RelationGetDescr(relation)
#define INDEX_CREATE_INVALID
PgStat_Counter t_tuples_fetched
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
void namestrcpy(Name name, const char *str)
int32 exprTypmod(const Node *expr)
static void SetReindexProcessing(Oid heapOid, Oid indexOid)
static void SetReindexPending(List *indexes)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
struct SMgrRelationData * rd_smgr
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, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int conInhCount, bool conNoInherit, bool is_internal)
void SerializeReindexState(Size maxsize, char *start_address)
void pgstat_progress_update_param(int index, int64 val)
char * get_collation_name(Oid colloid)
ExprState * ii_PredicateState
#define RelationGetForm(relation)
void CommitTransactionCommand(void)
MemoryContext ecxt_per_tuple_memory
void recordDependencyOnCollations(ObjectAddress *myself, List *collations, bool record_version)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
List * RelationGetDummyIndexExpressions(Relation relation)
int2vector * buildint2vector(const int16 *int2s, int n)
Oid get_rel_namespace(Oid relid)
BufferAccessStrategy strategy
static void InitializeAttributeOids(Relation indexRelation, int numatts, Oid indexoid)
Oid binary_upgrade_next_index_pg_class_oid
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent)
static List * pendingReindexedIndexes
List * list_copy(const List *oldlist)
#define FLEXIBLE_ARRAY_MEMBER
bool get_collation_isdeterministic(Oid colloid)
List * list_concat(List *list1, const List *list2)
int errcode(int sqlerrcode)
void * stringToNode(const char *str)
#define MemSet(start, val, len)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void MemoryContextReset(MemoryContext context)
#define PROGRESS_CREATEIDX_TUPLES_TOTAL
void RelationForgetRelation(Oid rid)
void PopActiveSnapshot(void)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
IndexInfo * BuildIndexInfo(Relation index)
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS
void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen)
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
PgStat_TableCounts t_counts
ObjectAddresses * new_object_addresses(void)
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
#define REINDEX_REL_SUPPRESS_INDEX_USE
static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)
void free_object_addresses(ObjectAddresses *addrs)
bool IsToastNamespace(Oid namespaceId)
void CopyStatistics(Oid fromrelid, Oid torelid)
void heap_freetuple(HeapTuple htup)
static bool ExecQual(ExprState *state, ExprContext *econtext)
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
Oid pendingReindexedIndexes[FLEXIBLE_ARRAY_MEMBER]
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, Oid relFileNode, 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)
List * lappend_oid(List *list, Oid datum)
#define OidIsValid(objectId)
#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)
PgStat_Counter t_tuples_returned
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)
int errdetail_internal(const char *fmt,...)
static void ResetReindexProcessing(void)
List * RelationGetIndexPredicate(Relation relation)
void pg_rusage_init(PGRUsage *ru0)
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
static void AppendAttributeTuples(Relation indexRelation, Datum *attopts)
void RelationSetNewRelfilenode(Relation relation, char persistence)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, Datum reloptions)
#define RelationOpenSmgr(relation)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
List * ii_ExpressionsState
HeapTuple systable_getnext(SysScanDesc sysscan)
void pfree(void *pointer)
bool IsInParallelMode(void)
#define EarlyPruningEnabled(rel)
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
#define ObjectIdGetDatum(X)
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
#define RelationIsValid(relation)
#define REINDEXOPT_VERBOSE
bool ReindexIsProcessingHeap(Oid heapOid)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self, bool record_version)
Oid get_relname_relid(const char *relname, Oid relnamespace)
Tuplesortstate * tuplesort
#define AttrNumberGetAttrOffset(attNum)
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry(Oid relid)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
char * get_namespace_name(Oid nspid)
#define IsNormalProcessingMode()
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
List * RelationGetIndexExpressions(Relation relation)
Oid values[FLEXIBLE_ARRAY_MEMBER]
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void AtEOXact_GUC(bool isCommit, int nestLevel)
#define PROGRESS_CREATEIDX_INDEX_OID
int errdetail(const char *fmt,...)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
const char * pg_rusage_show(const PGRUsage *ru0)
#define InvalidTransactionId
#define RelationGetRelationName(relation)
ExprState * ExecPrepareQual(List *qual, EState *estate)
static ListCell * list_head(const List *l)
List * list_delete_oid(List *list, Oid datum)
FormData_pg_attribute * Form_pg_attribute
PgStat_Counter tuples_fetched
bool ActiveSnapshotSet(void)
Oid get_index_constraint(Oid indexId)
#define REINDEXOPT_REPORT_PROGRESS
static int64 itemptr_encode(ItemPointer itemptr)
static TupleDesc ConstructTupleDescriptor(Relation heapRelation, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, Oid *collationObjectId, Oid *classObjectId)
#define IndexRelationGetNumberOfKeyAttributes(relation)
void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, Datum *attoptions, CatalogIndexState indstate)
TransactionId GetTopTransactionIdIfAny(void)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool isready, bool concurrent)
void visitDependenciesOf(const ObjectAddress *object, VisitDependenciesOfCB callback, void *userdata)
void CheckTableNotInUse(Relation rel, const char *stmt)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
Datum Int64GetDatum(int64 X)
static void IndexCheckExclusion(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)
#define ATTRIBUTE_FIXED_PART_SIZE
Size EstimateReindexStateSpace(void)
void index_register(Oid heap, Oid ind, IndexInfo *indexInfo)
PgStat_Counter t_blocks_hit
MemoryContext TopMemoryContext
int numPendingReindexedIndexes
static bool do_collation_version_check(const ObjectAddress *otherObject, const char *version, char **new_version, void *data)
bytea * index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, bool validate)
EState * CreateExecutorState(void)
void TransferPredicateLocksToHeapRelation(Relation relation)
bool get_rel_relispartition(Oid relid)
char * get_collation_version_for_oid(Oid oid)
List * ExecPrepareExprList(List *nodes, EState *estate)
void UnregisterSnapshot(Snapshot snapshot)
List * lappend(List *list, void *datum)
void reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, ReindexParams *params)
static Oid currentlyReindexedIndex
List * list_difference_oid(const List *list1, const List *list2)
#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE
Datum * RelationGetIndexRawAttOptions(Relation indexrel)
#define REINDEXOPT_MISSING_OK
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
#define RelationIsMapped(relation)
FormData_pg_index * Form_pg_index
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define PROGRESS_CREATEIDX_PHASE
Size mul_size(Size s1, Size s2)
#define TextDatumGetCString(d)
#define PROGRESS_SCAN_BLOCKS_DONE
void pgstat_progress_end_command(void)
void RelationDropStorage(Relation rel)
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
void CommandCounterIncrement(void)
void ReleaseSysCache(HeapTuple tuple)
Expr * make_ands_explicit(List *andclauses)
List * make_ands_implicit(Expr *clause)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
static bool relationHasPrimaryKey(Relation rel)
#define PROGRESS_CREATEIDX_COMMAND_REINDEX
PgStat_Counter blocks_hit
#define InvalidMultiXactId
#define RelationGetNumberOfBlocks(reln)
#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
PgStat_Counter t_numscans
#define INDEX_CREATE_IS_PRIMARY
static void RemoveReindexPending(Oid indexOid)
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
#define INDEX_CREATE_CONCURRENT
RegProcedure get_opcode(Oid opno)
#define ereport(elevel,...)
void DeleteRelationTuple(Oid relid)
int GetCurrentTransactionNestLevel(void)
TransactionId MultiXactId
#define ShareUpdateExclusiveLock
void index_check_collation_versions(Oid relid)
FormData_pg_constraint * Form_pg_constraint
bool list_member_oid(const List *list, Oid datum)
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
#define HeapTupleIsValid(tuple)
#define REINDEX_REL_FORCE_INDEXES_UNLOGGED
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
oidvector * buildoidvector(const Oid *oids, int n)
#define RELATION_IS_OTHER_TEMP(relation)
#define PROGRESS_CREATEIDX_PHASE_BUILD
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_TABLESCAN
void StartTransactionCommand(void)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid relfilenode, Oid accessmtd, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods, TransactionId *relfrozenxid, MultiXactId *relminmxid)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Oid exprType(const Node *expr)
struct PgStat_TableStatus * pgstat_info
int plan_create_index_workers(Oid tableOid, Oid indexOid)
bool get_index_isvalid(Oid index_oid)
FormData_pg_type * Form_pg_type
static int list_length(const List *l)
#define REINDEX_REL_CHECK_CONSTRAINTS
FormData_pg_trigger * Form_pg_trigger
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
TupleTableSlot * ecxt_scantuple
#define PROGRESS_SCAN_BLOCKS_TOTAL
List * get_index_ref_constraints(Oid indexId)
void DeleteAttributeTuples(Oid relid)
#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
int16 values[FLEXIBLE_ARRAY_MEMBER]
static int reindexingNestLevel
#define INDEX_CONSTR_CREATE_UPDATE_INDEX
List * RelationGetIndexList(Relation relation)
Snapshot GetLatestSnapshot(void)
static bool do_collation_version_update(const ObjectAddress *otherObject, const char *version, char **new_version, void *data)
#define InvalidAttrNumber
#define ObjectAddressSet(addr, class_id, object_id)
void index_close(Relation relation, LOCKMODE lockmode)
#define DatumGetPointer(X)
void CacheInvalidateRelcache(Relation relation)
void RemoveStatistics(Oid relid, AttrNumber attnum)
char get_rel_persistence(Oid relid)
bool reindex_relation(Oid relid, int flags, ReindexParams *params)
static void table_endscan(TableScanDesc scan)
static Datum values[MAXATTR]
void RelationInitIndexAccessInfo(Relation relation)
#define IsBootstrapProcessingMode()
FormData_pg_class * Form_pg_class
#define INDEX_CREATE_SKIP_BUILD
Oid get_base_element_type(Oid typid)
#define SearchSysCacheCopy1(cacheId, key1)
#define AccessExclusiveLock
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN
#define INDEX_CREATE_PARTITIONED
int NewGUCNestLevel(void)
List * GetTypeCollations(Oid typeoid)
void RestoreReindexState(void *reindexstate)
int errmsg(const char *fmt,...)
void heap_inplace_update(Relation relation, HeapTuple tuple)
IndexInfo * BuildDummyIndexInfo(Relation index)
static void table_index_validate_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)
#define PROGRESS_CREATEIDX_TUPLES_DONE
void list_free(List *list)
ambuildempty_function ambuildempty
MemoryContext rd_indexcxt
void LockRelation(Relation relation, LOCKMODE lockmode)
Oid currentlyReindexedHeap
#define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT
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)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define CStringGetTextDatum(s)
char * nodeToString(const void *obj)
#define REINDEX_REL_FORCE_INDEXES_PERMANENT
void CatalogCloseIndexes(CatalogIndexState indstate)
#define REINDEX_REL_PROCESS_TOAST
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
#define CHECK_FOR_INTERRUPTS()
#define PROGRESS_CREATEIDX_SUBPHASE
void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)
void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex)
void index_update_collation_versions(Oid relid, Oid coll)
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
uint16 * ii_ExclusionStrats
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)
void tuplesort_end(Tuplesortstate *state)
#define INDEX_CREATE_ADD_CONSTRAINT
Relation table_open(Oid relationId, LOCKMODE lockmode)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
void index_concurrently_set_dead(Oid heapId, Oid indexId)
bool ReindexIsProcessingIndex(Oid indexOid)
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
FormData_pg_opclass * Form_pg_opclass
#define ERRCODE_DUPLICATE_OBJECT
static bool validate_index_callback(ItemPointer itemptr, void *opaque)
PgStat_Counter blocks_fetched
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
char * get_rel_name(Oid relid)
#define PointerIsValid(pointer)
List * get_partition_ancestors(Oid relid)
#define RelationGetRelid(relation)
#define INDEX_CONSTR_CREATE_DEFERRABLE
#define PROGRESS_CREATEIDX_COMMAND
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Relation index_open(Oid relationId, LOCKMODE lockmode)
struct do_collation_version_check_context do_collation_version_check_context
Datum * ii_OpclassOptions
#define BTEqualStrategyNumber
#define offsetof(type, field)
PgStat_Counter t_blocks_fetched
#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY
#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID
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)
#define RelationGetNamespace(relation)