77 #include "utils/fmgroids.h" 109 Oid accessMethodObjectId,
110 Oid *collationObjectId,
113 int numatts,
Oid indexoid);
164 foreach(indexoidscan, indexoidlist)
171 elog(
ERROR,
"cache lookup failed for index %u", indexoid);
218 if ((is_alter_table || heapRel->
rd_rel->relispartition) &&
222 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
223 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
240 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
241 errmsg(
"primary keys cannot be expressions")));
251 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
255 if (!attform->attnotnull)
257 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
258 errmsg(
"primary key column \"%s\" is not marked NOT NULL",
274 Oid accessMethodObjectId,
275 Oid *collationObjectId,
303 for (i = 0; i < numatts; i++)
314 to->attstattarget = -1;
315 to->attcacheoff = -1;
316 to->attislocal =
true;
317 to->attcollation = (i < numkeyatts) ?
323 if (colnames_item == NULL)
324 elog(
ERROR,
"too few entries in colnames list");
326 colnames_item =
lnext(indexColNames, colnames_item);
341 elog(
ERROR,
"invalid column number %d", atnum);
345 to->atttypid = from->atttypid;
346 to->attlen = from->attlen;
347 to->attndims = from->attndims;
348 to->atttypmod = from->atttypmod;
349 to->attbyval = from->attbyval;
350 to->attstorage = from->attstorage;
351 to->attalign = from->attalign;
352 to->attcompression = from->attcompression;
359 if (indexpr_item == NULL)
360 elog(
ERROR,
"too few entries in indexprs list");
370 elog(
ERROR,
"cache lookup failed for type %u", keyType);
376 to->atttypid = keyType;
377 to->attlen = typeTup->typlen;
378 to->attbyval = typeTup->typbyval;
379 to->attstorage = typeTup->typstorage;
380 to->attalign = typeTup->typalign;
404 to->atttypid, to->attcollation,
422 if (i < indexInfo->ii_NumIndexKeyAttrs)
426 elog(
ERROR,
"cache lookup failed for opclass %u",
430 keyType = opclassTup->opckeytype;
441 if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
445 elog(
ERROR,
"could not get element type of array type %u",
456 if (
OidIsValid(keyType) && keyType != to->atttypid)
460 elog(
ERROR,
"cache lookup failed for type %u", keyType);
463 to->atttypid = keyType;
465 to->attlen = typeTup->typlen;
466 to->attbyval = typeTup->typbyval;
467 to->attalign = typeTup->typalign;
468 to->attstorage = typeTup->typstorage;
493 for (i = 0; i < numatts; i += 1)
554 bool nulls[Natts_pg_index];
582 exprsDatum = (
Datum) 0;
597 predDatum = (
Datum) 0;
608 MemSet(nulls,
false,
sizeof(nulls));
615 values[Anum_pg_index_indisprimary - 1] =
BoolGetDatum(primary);
616 values[Anum_pg_index_indisexclusion - 1] =
BoolGetDatum(isexclusion);
617 values[Anum_pg_index_indimmediate - 1] =
BoolGetDatum(immediate);
618 values[Anum_pg_index_indisclustered - 1] =
BoolGetDatum(
false);
619 values[Anum_pg_index_indisvalid - 1] =
BoolGetDatum(isvalid);
620 values[Anum_pg_index_indcheckxmin - 1] =
BoolGetDatum(
false);
621 values[Anum_pg_index_indisready - 1] =
BoolGetDatum(isready);
622 values[Anum_pg_index_indislive - 1] =
BoolGetDatum(
true);
623 values[Anum_pg_index_indisreplident - 1] =
BoolGetDatum(
false);
625 values[Anum_pg_index_indcollation - 1] =
PointerGetDatum(indcollation);
628 values[Anum_pg_index_indexprs - 1] = exprsDatum;
629 if (exprsDatum == (
Datum) 0)
630 nulls[Anum_pg_index_indexprs - 1] =
true;
631 values[Anum_pg_index_indpred - 1] = predDatum;
632 if (predDatum == (
Datum) 0)
633 nulls[Anum_pg_index_indpred - 1] =
true;
699 const char *indexRelationName,
701 Oid parentIndexRelid,
702 Oid parentConstraintId,
706 Oid accessMethodObjectId,
708 Oid *collationObjectId,
714 bool allow_system_table_mods,
722 bool shared_relation;
723 bool mapped_relation;
737 Assert((constr_flags == 0) ||
742 relkind = partitioned ? RELKIND_PARTITIONED_INDEX : RELKIND_INDEX;
754 shared_relation = heapRelation->
rd_rel->relisshared;
756 relpersistence = heapRelation->
rd_rel->relpersistence;
762 elog(
ERROR,
"must index at least one column");
764 if (!allow_system_table_mods &&
768 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
769 errmsg(
"user-defined indexes on system catalog tables are not supported")));
792 Oid collation = collationObjectId[
i];
793 Oid opclass = classObjectId[
i];
797 if ((opclass == TEXT_BTREE_PATTERN_OPS_OID ||
798 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||
799 opclass == BPCHAR_BTREE_PATTERN_OPS_OID) &&
806 elog(
ERROR,
"cache lookup failed for operator class %u", opclass);
808 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
809 errmsg(
"nondeterministic collations are not supported for operator class \"%s\"",
823 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
824 errmsg(
"concurrent index creation on system catalog tables is not supported")));
830 if (concurrent && is_exclusion)
832 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
833 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
841 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
842 errmsg(
"shared indexes cannot be created after initdb")));
847 if (shared_relation && tableSpaceId != GLOBALTABLESPACE_OID)
848 elog(
ERROR,
"shared relations must be placed in pg_global tablespace");
861 (
errcode(ERRCODE_DUPLICATE_TABLE),
862 errmsg(
"relation \"%s\" already exists, skipping",
863 indexRelationName)));
869 (
errcode(ERRCODE_DUPLICATE_TABLE),
870 errmsg(
"relation \"%s\" already exists",
871 indexRelationName)));
874 if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0 &&
884 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
894 accessMethodObjectId,
911 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
912 errmsg(
"pg_class index OID value not set when in binary upgrade mode")));
934 accessMethodObjectId,
940 allow_system_table_mods,
961 indexRelation->
rd_rel->relowner = heapRelation->
rd_rel->relowner;
962 indexRelation->
rd_rel->relam = accessMethodObjectId;
999 collationObjectId, classObjectId, coloptions,
1000 isprimary, is_exclusion,
1002 !concurrent && !invalid,
1038 *colls_no_version =
NIL;
1042 if ((flags & INDEX_CREATE_ADD_CONSTRAINT) != 0)
1044 char constraintType;
1048 constraintType = CONSTRAINT_PRIMARY;
1050 constraintType = CONSTRAINT_UNIQUE;
1051 else if (is_exclusion)
1052 constraintType = CONSTRAINT_EXCLUSION;
1055 elog(
ERROR,
"constraint must be PRIMARY, UNIQUE or EXCLUDE");
1066 allow_system_table_mods,
1069 *constraintId = localaddr.
objectId;
1073 bool have_simple_col =
false;
1086 have_simple_col =
true;
1096 if (!have_simple_col)
1125 Oid colloid = collationObjectId[
i];
1129 Oid opclass = classObjectId[
i];
1139 if (opclass == TEXT_BTREE_PATTERN_OPS_OID ||
1140 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||
1141 opclass == BPCHAR_BTREE_PATTERN_OPS_OID)
1142 colls_no_version =
lappend_oid(colls_no_version, colloid);
1150 Assert(i < indexTupDesc->natts);
1165 if (colls_no_version !=
NIL && colls !=
NIL)
1169 if (colls_no_version !=
NIL)
1207 Assert((flags & INDEX_CREATE_ADD_CONSTRAINT) == 0);
1212 indexRelationId, 0, is_internal);
1253 else if ((flags & INDEX_CREATE_SKIP_BUILD) != 0)
1268 index_build(heapRelation, indexRelation, indexInfo,
false,
true);
1277 return indexRelationId;
1292 const char *version,
1297 char *current_version;
1300 if (!version || otherObject->
classId != CollationRelationId)
1306 if (!current_version)
1317 if (strcmp(current_version, version) != 0)
1324 (
errmsg(
"index \"%s\" depends on collation \"%s\" version \"%s\", but the current version is \"%s\"",
1329 errdetail(
"The index may be corrupted due to changes in sort order."),
1330 errhint(
"REINDEX to avoid the risk of corruption.")));
1356 object.classId = RelationRelationId;
1357 object.objectId =
relid;
1358 object.objectSubId = 0;
1370 const char *version,
1377 if (!version || otherObject->
classId != CollationRelationId)
1398 object.
classId = RelationRelationId;
1399 object.objectId =
relid;
1400 object.objectSubId = 0;
1415 Oid tablespaceOid,
const char *newName)
1423 Datum indclassDatum,
1444 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1445 errmsg(
"concurrent index creation for exclusion constraints is not supported")));
1450 elog(
ERROR,
"cache lookup failed for index %u", oldIndexId);
1452 Anum_pg_index_indclass, &isnull);
1457 Anum_pg_index_indoption, &isnull);
1464 elog(
ERROR,
"cache lookup failed for relation %u", oldIndexId);
1466 Anum_pg_class_reloptions, &isnull);
1479 Anum_pg_index_indexprs, &isnull);
1491 Anum_pg_index_indpred, &isnull);
1544 indexRelation->
rd_rel->relam,
1575 Oid indexRelationId)
1601 index_build(heapRel, indexRelation, indexInfo,
false,
true);
1639 Oid indexConstraintOid;
1655 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1659 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1669 isPartition = newClassForm->relispartition;
1670 newClassForm->relispartition = oldClassForm->relispartition;
1671 oldClassForm->relispartition = isPartition;
1685 elog(
ERROR,
"could not find tuple for relation %u", oldIndexId);
1689 elog(
ERROR,
"could not find tuple for relation %u", newIndexId);
1698 newIndexForm->indisprimary = oldIndexForm->indisprimary;
1699 oldIndexForm->indisprimary =
false;
1700 newIndexForm->indisexclusion = oldIndexForm->indisexclusion;
1701 oldIndexForm->indisexclusion =
false;
1702 newIndexForm->indimmediate = oldIndexForm->indimmediate;
1703 oldIndexForm->indimmediate =
true;
1706 newIndexForm->indisreplident = oldIndexForm->indisreplident;
1709 newIndexForm->indisclustered = oldIndexForm->indisclustered;
1715 newIndexForm->indisvalid =
true;
1716 oldIndexForm->indisvalid =
false;
1717 oldIndexForm->indisclustered =
false;
1718 oldIndexForm->indisreplident =
false;
1735 constraintOids =
lappend_oid(constraintOids, indexConstraintOid);
1740 foreach(lc, constraintOids)
1753 elog(
ERROR,
"could not find tuple for constraint %u", constraintOid);
1757 if (conForm->conindid == oldIndexId)
1759 conForm->conindid = newIndexId;
1768 Anum_pg_trigger_tgconstraint,
1779 if (tgForm->tgconstrindid != oldIndexId)
1786 tgForm->tgconstrindid = newIndexId;
1805 bool nulls[Natts_pg_description] = {0};
1806 bool replaces[Natts_pg_description] = {0};
1809 replaces[Anum_pg_description_objoid - 1] =
true;
1812 Anum_pg_description_objoid,
1816 Anum_pg_description_classoid,
1820 Anum_pg_description_objsubid,
1832 values, nulls, replaces);
1908 Anum_pg_attribute_attrelid,
1912 true, NULL, 1, key);
1917 Datum repl_val[Natts_pg_attribute];
1918 bool repl_null[Natts_pg_attribute];
1919 bool repl_repl[Natts_pg_attribute];
1924 if (att->attisdropped)
1933 if (attstattarget == att->attstattarget)
1936 memset(repl_val, 0,
sizeof(repl_val));
1937 memset(repl_null,
false,
sizeof(repl_null));
1938 memset(repl_repl,
false,
sizeof(repl_repl));
1940 repl_repl[Anum_pg_attribute_attstattarget - 1] =
true;
1941 repl_val[Anum_pg_attribute_attstattarget - 1] =
Int32GetDatum(attstattarget);
1945 repl_val, repl_null, repl_repl);
2037 Oid indexRelationId,
2038 Oid parentConstraintId,
2040 const char *constraintName,
2041 char constraintType,
2043 bool allow_system_table_mods,
2052 bool mark_as_primary;
2065 if (!allow_system_table_mods &&
2069 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2070 errmsg(
"user-defined indexes on system catalog tables are not supported")));
2074 constraintType != CONSTRAINT_EXCLUSION)
2075 elog(
ERROR,
"constraints cannot have index expressions");
2172 trigger->
trigname = (constraintType == CONSTRAINT_PRIMARY) ?
2173 "PK_ConstraintTrigger" :
2174 "Unique_ConstraintTrigger";
2178 trigger->
row =
true;
2179 trigger->
timing = TRIGGER_TYPE_AFTER;
2180 trigger->
events = TRIGGER_TYPE_INSERT | TRIGGER_TYPE_UPDATE;
2202 (mark_as_primary || deferrable))
2214 elog(
ERROR,
"cache lookup failed for index %u", indexRelationId);
2217 if (mark_as_primary && !indexForm->indisprimary)
2219 indexForm->indisprimary =
true;
2223 if (deferrable && indexForm->indimmediate)
2225 indexForm->indimmediate =
false;
2276 (!concurrent && !concurrent_lock_mode));
2298 userHeapRelation =
table_open(heapId, lockmode);
2299 userIndexRelation =
index_open(indexId, lockmode);
2355 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2356 errmsg(
"DROP INDEX CONCURRENTLY must be first action in transaction")));
2451 if (userIndexRelation->
rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
2470 elog(
ERROR,
"cache lookup failed for index %u", indexId);
2551 numAtts = indexStruct->indnatts;
2553 elog(
ERROR,
"invalid indnatts %d for index %u",
2561 indexStruct->indnkeyatts,
2565 indexStruct->indisunique,
2566 indexStruct->indisready,
2570 for (i = 0; i < numAtts; i++)
2574 if (indexStruct->indisexclusion)
2610 numAtts = indexStruct->indnatts;
2612 elog(
ERROR,
"invalid indnatts %d for index %u",
2620 indexStruct->indnkeyatts,
2624 indexStruct->indisunique,
2625 indexStruct->indisready,
2629 for (i = 0; i < numAtts; i++)
2649 Oid *collations1,
Oid *collations2,
2650 Oid *opfamilies1,
Oid *opfamilies2,
2691 if (collations1[i] != collations2[i])
2693 if (opfamilies1[i] != opfamilies2[i])
2705 bool found_whole_row;
2711 if (found_whole_row)
2729 bool found_whole_row;
2735 if (found_whole_row)
2779 if (index->
rd_rel->relam != BTREE_AM_OID)
2780 elog(
ERROR,
"unexpected non-btree speculative unique index");
2791 for (i = 0; i < indnkeyatts; i++)
2800 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
2855 else if (keycol != 0)
2868 if (indexpr_item == NULL)
2869 elog(
ERROR,
"wrong number of index expressions");
2879 if (indexpr_item != NULL)
2880 elog(
ERROR,
"wrong number of index expressions");
2975 elog(
ERROR,
"could not find tuple for relation %u", relid);
2979 Assert(rd_rel->relkind != RELKIND_PARTITIONED_INDEX);
2987 if (reltuples == 0 && rd_rel->reltuples < 0)
2993 if (rd_rel->relhasindex != hasindex)
2995 rd_rel->relhasindex = hasindex;
3004 if (rd_rel->relkind != RELKIND_INDEX)
3009 if (rd_rel->relpages != (
int32) relpages)
3011 rd_rel->relpages = (
int32) relpages;
3014 if (rd_rel->reltuples != (
float4) reltuples)
3016 rd_rel->reltuples = (
float4) reltuples;
3019 if (rd_rel->relallvisible != (
int32) relallvisible)
3021 rd_rel->relallvisible = (
int32) relallvisible;
3071 int save_sec_context;
3089 indexRelation->
rd_rel->relam == BTREE_AM_OID)
3101 (
errmsg_internal(
"building index \"%s\" on table \"%s\" with request for %d parallel workers",
3118 const int progress_index[] = {
3126 const int64 progress_vals[] = {
3149 if (indexRelation->
rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
3200 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3204 Assert(!indexForm->indcheckxmin);
3206 indexForm->indcheckxmin =
true;
3309 if (predicate != NULL)
3311 if (!
ExecQual(predicate, econtext))
3328 indexRelation, indexInfo,
3329 &(slot->
tts_tid), values, isnull,
3420 int save_sec_context;
3424 const int progress_index[] = {
3431 const int64 progress_vals[] = {
3467 ivinfo.
index = indexRelation;
3493 const int progress_index[] = {
3498 const int64 progress_vals[] = {
3522 "validate_index found %.0f heap tuples, %.0f index tuples; inserted %.0f missing tuples",
3572 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3580 Assert(indexForm->indislive);
3581 Assert(!indexForm->indisready);
3582 Assert(!indexForm->indisvalid);
3583 indexForm->indisready =
true;
3587 Assert(indexForm->indislive);
3588 Assert(indexForm->indisready);
3589 Assert(!indexForm->indisvalid);
3590 indexForm->indisvalid =
true;
3608 indexForm->indisvalid =
false;
3609 indexForm->indisclustered =
false;
3610 indexForm->indisreplident =
false;
3621 Assert(!indexForm->indisvalid);
3622 Assert(!indexForm->indisclustered);
3623 Assert(!indexForm->indisreplident);
3624 indexForm->indisready =
false;
3625 indexForm->indislive =
false;
3652 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3655 Assert(index->indexrelid == indexId);
3657 result = index->indrelid;
3673 volatile bool skipped_constraint =
false;
3676 bool set_tablespace =
false;
3701 const int progress_cols[] = {
3705 const int64 progress_vals[] = {
3729 if (iRel->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
3730 elog(
ERROR,
"cannot reindex partitioned index \"%s.%s\"",
3740 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3741 errmsg(
"cannot reindex temporary tables of other sessions")));
3751 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3752 errmsg(
"cannot reindex invalid index on TOAST table")));
3767 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3768 errmsg(
"cannot move system relation \"%s\"",
3774 set_tablespace =
true;
3809 if (skip_constraint_checks)
3812 skipped_constraint =
true;
3827 index_build(heapRelation, iRel, indexInfo,
true,
true);
3865 if (!skipped_constraint)
3878 elog(
ERROR,
"cache lookup failed for index %u", indexId);
3881 index_bad = (!indexForm->indisvalid ||
3882 !indexForm->indisready ||
3883 !indexForm->indislive);
3886 early_pruning_enabled)
3889 indexForm->indcheckxmin =
false;
3890 else if (index_bad || early_pruning_enabled)
3891 indexForm->indcheckxmin =
true;
3892 indexForm->indisvalid =
true;
3893 indexForm->indisready =
true;
3894 indexForm->indislive =
true;
3913 (
errmsg(
"index \"%s\" was reindexed",
3993 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
3994 elog(
ERROR,
"cannot reindex partitioned table \"%s.%s\"",
3998 toast_relid = rel->
rd_rel->reltoastrelid;
4024 persistence = RELPERSISTENCE_UNLOGGED;
4026 persistence = RELPERSISTENCE_PERMANENT;
4028 persistence = rel->
rd_rel->relpersistence;
4032 foreach(indexId, indexIds)
4046 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4047 errmsg(
"cannot reindex invalid index \"%s.%s\" on TOAST table, skipping",
4054 persistence, params);
4072 result = (indexIds !=
NIL);
4155 elog(
ERROR,
"cannot reindex while reindexing");
4186 if (pendingReindexedIndexes)
4187 elog(
ERROR,
"cannot reindex while reindexing");
4189 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
4190 pendingReindexedIndexes =
list_copy(indexes);
4202 elog(
ERROR,
"cannot modify reindex state during a parallel operation");
4230 pendingReindexedIndexes =
NIL;
4261 foreach(lc, pendingReindexedIndexes)
4282 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)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
int errhint(const char *fmt,...)
#define DescriptionObjIndexId
bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)
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 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)
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)
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
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)
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)
void pgstat_progress_end_command(void)
int errdetail_internal(const char *fmt,...)
static void ResetReindexProcessing(void)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
List * RelationGetIndexPredicate(Relation relation)
void pg_rusage_init(PGRUsage *ru0)
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
char * get_collation_version_for_oid(Oid oid, bool missing_ok)
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)
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
#define IsNormalProcessingMode()
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
#define AttributeRelidNumIndexId
bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
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)
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)
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
void RelationAssumeNewRelfilenode(Relation relation)
Size mul_size(Size s1, Size s2)
#define TextDatumGetCString(d)
#define PROGRESS_SCAN_BLOCKS_DONE
int get_attstattarget(Oid relid, AttrNumber attnum)
void RelationDropStorage(Relation rel)
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
int errmsg_internal(const char *fmt,...)
#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)
void pgstat_progress_update_param(int index, int64 val)
#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 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 InvalidCompressionMethod
#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)
void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, Oid newRelFileNode)
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)