59 #include "utils/fmgroids.h" 79 List *exclusionOpNames,
81 const char *accessMethodName,
Oid accessMethodId,
85 List *colnames,
List *exclusionOpNames,
86 bool primary,
bool isconstraint);
165 const char *accessMethodName,
167 List *exclusionOpNames)
171 Oid *collationObjectId;
182 int numberOfAttributes;
199 isconstraint =
false;
202 Assert(numberOfAttributes > 0);
209 (
errcode(ERRCODE_UNDEFINED_OBJECT),
210 errmsg(
"access method \"%s\" does not exist",
213 accessMethodId = accessMethodForm->oid;
228 indexInfo =
makeIndexInfo(numberOfAttributes, numberOfAttributes,
229 accessMethodId,
NIL,
NIL,
false,
false,
false);
230 typeObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
231 collationObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
232 classObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
235 typeObjectId, collationObjectId, classObjectId,
236 coloptions, attributeList,
237 exclusionOpNames, relationId,
238 accessMethodName, accessMethodId,
239 amcanorder, isconstraint);
245 elog(
ERROR,
"cache lookup failed for index %u", oldId);
254 indexForm->indisvalid))
261 old_natts = indexForm->indnkeyatts;
262 Assert(old_natts == numberOfAttributes);
272 ret = (memcmp(old_indclass->
values, classObjectId,
273 old_natts *
sizeof(
Oid)) == 0 &&
274 memcmp(old_indcollation->
values, collationObjectId,
275 old_natts *
sizeof(
Oid)) == 0);
284 for (i = 0; i < old_natts; i++)
303 pfree(opclassOptions);
315 old_natts *
sizeof(
Oid)) == 0;
320 for (i = 0; i < old_natts && ret; i++)
326 if ((IsPolymorphicType(left) || IsPolymorphicType(right)) &&
351 if (!opts1 && !opts2)
354 for (i = 0; i < natts; i++)
359 if (opt1 == (
Datum) 0)
361 if (opt2 == (
Datum) 0)
366 else if (opt2 == (
Datum) 0)
427 for (i = 0; i < n_old_snapshots; i++)
436 int n_newer_snapshots;
445 for (j = i; j < n_old_snapshots; j++)
449 for (k = 0; k < n_newer_snapshots; k++)
455 if (k >= n_newer_snapshots)
458 pfree(newer_snapshots);
510 Oid parentConstraintId,
513 bool check_not_in_use,
518 char *indexRelationName;
519 char *accessMethodName;
521 Oid *collationObjectId;
528 List *allIndexParams;
542 int numberOfAttributes;
543 int numberOfKeyAttributes;
550 int save_nestlevel = -1;
615 if (numberOfKeyAttributes <= 0)
617 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
618 errmsg(
"must specify at least one column")));
621 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
622 errmsg(
"cannot use more than %d columns in an index",
646 switch (rel->
rd_rel->relkind)
648 case RELKIND_RELATION:
649 case RELKIND_MATVIEW:
650 case RELKIND_PARTITIONED_TABLE:
653 case RELKIND_FOREIGN_TABLE:
660 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
661 errmsg(
"cannot create index on foreign table \"%s\"",
666 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
667 errmsg(
"\"%s\" is not a table or materialized view",
680 partitioned = rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE;
691 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
692 errmsg(
"cannot create index on partitioned table \"%s\" concurrently",
696 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
697 errmsg(
"cannot create exclusion constraints on partitioned table \"%s\"",
706 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
707 errmsg(
"cannot create indexes on temporary tables of other sessions")));
715 if (check_not_in_use)
744 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
745 errmsg(
"cannot specify default tablespace for partitioned relations")));
772 if (rel->
rd_rel->relisshared)
773 tablespaceId = GLOBALTABLESPACE_OID;
774 else if (tablespaceId == GLOBALTABLESPACE_OID)
776 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
777 errmsg(
"only shared relations can be placed in pg_global tablespace")));
787 indexRelationName = stmt->
idxname;
788 if (indexRelationName == NULL)
807 if (strcmp(accessMethodName,
"rtree") == 0)
810 (
errmsg(
"substituting access method \"gist\" for obsolete method \"rtree\"")));
811 accessMethodName =
"gist";
817 (
errcode(ERRCODE_UNDEFINED_OBJECT),
818 errmsg(
"access method \"%s\" does not exist",
822 accessMethodId = accessMethodForm->oid;
830 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
831 errmsg(
"access method \"%s\" does not support unique indexes",
835 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
836 errmsg(
"access method \"%s\" does not support included columns",
840 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
841 errmsg(
"access method \"%s\" does not support multicolumn indexes",
845 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
846 errmsg(
"access method \"%s\" does not support exclusion constraints",
865 NULL, NULL,
false,
false);
875 numberOfKeyAttributes,
883 typeObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
884 collationObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
885 classObjectId = (
Oid *)
palloc(numberOfAttributes *
sizeof(
Oid));
888 typeObjectId, collationObjectId, classObjectId,
889 coloptions, allIndexParams,
891 accessMethodName, accessMethodId,
912 const char *constraint_type;
916 constraint_type =
"PRIMARY KEY";
918 constraint_type =
"UNIQUE";
920 constraint_type =
"EXCLUDE";
924 constraint_type = NULL;
954 elog(
ERROR,
"missing operator %d(%u,%u) in partition opfamily %u",
964 if (accessMethodId == BTREE_AM_OID)
968 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
969 errmsg(
"cannot match partition key to an index using access method \"%s\"",
978 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
979 errmsg(
"unsupported %s constraint with partition key definition",
981 errdetail(
"%s constraints cannot be used when partition keys include expressions.",
1003 if (ptkey_eqop == idx_eqop)
1019 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1020 errmsg(
"unique constraint on partitioned table must include all partitioning columns"),
1021 errdetail(
"%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
1039 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1040 errmsg(
"index creation on system columns is not supported")));
1058 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1059 errmsg(
"index creation on system columns is not supported")));
1073 const char *constraint_type;
1076 constraint_type =
"PRIMARY KEY";
1078 constraint_type =
"UNIQUE";
1080 constraint_type =
"EXCLUDE";
1084 constraint_type = NULL;
1088 (
errmsg_internal(
"%s %s will create implicit index \"%s\" for table \"%s\"",
1089 is_alter_table ?
"ALTER TABLE / ADD" :
"CREATE TABLE /",
1106 flags = constr_flags = 0;
1109 if (skip_build || concurrent || partitioned)
1138 index_create(rel, indexRelationName, indexRelationId, parentIndexId,
1140 stmt->
oldNode, indexInfo, indexColNames,
1141 accessMethodId, tablespaceId,
1142 collationObjectId, classObjectId,
1143 coloptions, reloptions,
1144 flags, constr_flags,
1146 &createdConstraintId);
1154 if (save_nestlevel >= 0)
1186 int nparts = partdesc->
nparts;
1188 bool invalidate_parent =
false;
1195 memcpy(part_oids, partdesc->
oids,
sizeof(
Oid) * nparts);
1198 opfamOids =
palloc(
sizeof(
Oid) * numberOfKeyAttributes);
1199 for (i = 0; i < numberOfKeyAttributes; i++)
1210 for (i = 0; i < nparts; i++)
1212 Oid childRelid = part_oids[
i];
1226 if (childrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1230 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1231 errmsg(
"cannot create unique index on partitioned table \"%s\"",
1233 errdetail(
"Table \"%s\" contains partitions that are foreign tables.",
1245 foreach(cell, childidxs)
1291 createdConstraintId,
1295 invalidate_parent =
true;
1315 bool found_whole_row;
1352 if (found_whole_row)
1353 elog(
ERROR,
"cannot convert whole-row table reference");
1360 if (found_whole_row)
1361 elog(
ERROR,
"cannot convert whole-row table reference");
1366 createdConstraintId,
1367 is_alter_table, check_rights, check_not_in_use,
1381 if (invalidate_parent)
1390 elog(
ERROR,
"cache lookup failed for index %u",
1464 const int progress_cols[] = {
1468 const int64 progress_vals[] = {
1571 limitXmin = snapshot->
xmin;
1682 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1683 errmsg(
"functions in index predicate must be marked IMMUTABLE")));
1698 List *exclusionOpNames,
1700 const char *accessMethodName,
1711 if (exclusionOpNames)
1717 nextExclOp =
list_head(exclusionOpNames);
1726 foreach(lc, attList)
1735 if (attribute->
name != NULL)
1748 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1749 errmsg(
"column \"%s\" named in key does not exist",
1753 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1754 errmsg(
"column \"%s\" does not exist",
1759 atttype = attform->atttypid;
1760 attcollation = attform->attcollation;
1770 if (attn >= nkeycols)
1772 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1773 errmsg(
"expressions are not supported in included columns")));
1813 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1814 errmsg(
"functions in index expression must be marked IMMUTABLE")));
1818 typeOidP[attn] = atttype;
1824 if (attn >= nkeycols)
1828 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1829 errmsg(
"including column does not support a collation")));
1832 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1833 errmsg(
"including column does not support an operator class")));
1836 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1837 errmsg(
"including column does not support ASC/DESC options")));
1840 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1841 errmsg(
"including column does not support NULLS FIRST/LAST options")));
1844 colOptionP[attn] = 0;
1867 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
1868 errmsg(
"could not determine which collation to use for index expression"),
1869 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
1875 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1876 errmsg(
"collations are not supported by type %s",
1880 collationOidP[attn] = attcollation;
1913 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1914 errmsg(
"operator %s is not commutative",
1916 errdetail(
"Only commutative operators can be used in exclusion constraints.")));
1936 elog(
ERROR,
"cache lookup failed for opfamily %u",
1941 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1942 errmsg(
"operator %s is not a member of operator family \"%s\"",
1945 errdetail(
"The exclusion operator must be related to the index operator class for the constraint.")));
1951 nextExclOp =
lnext(exclusionOpNames, nextExclOp);
1959 colOptionP[attn] = 0;
1964 colOptionP[attn] |= INDOPTION_DESC;
1969 colOptionP[attn] |= INDOPTION_NULLS_FIRST;
1972 colOptionP[attn] |= INDOPTION_NULLS_FIRST;
1979 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1980 errmsg(
"access method \"%s\" does not support ASC/DESC options",
1981 accessMethodName)));
1984 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1985 errmsg(
"access method \"%s\" does not support NULLS FIRST/LAST options",
1986 accessMethodName)));
2000 NULL, NULL,
false,
false);
2015 const char *accessMethodName,
Oid accessMethodId)
2030 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2031 errmsg(
"data type %s has no default operator class for access method \"%s\"",
2033 errhint(
"You must specify an operator class for the index or define a default operator class for the data type.")));
2061 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2062 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2063 opcname, accessMethodName)));
2069 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2070 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2078 opClassId = opform->oid;
2079 opInputType = opform->opcintype;
2083 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2084 errmsg(
"operator class \"%s\" does not accept data type %s",
2103 int ncompatible = 0;
2104 int ncompatiblepreferred = 0;
2131 Anum_pg_opclass_opcmethod,
2143 if (!opclass->opcdefault)
2145 if (opclass->opcintype == type_id)
2148 result = opclass->oid;
2150 else if (nexact == 0 &&
2155 ncompatiblepreferred++;
2156 result = opclass->oid;
2158 else if (ncompatiblepreferred == 0)
2161 result = opclass->oid;
2174 errmsg(
"there are multiple default operator classes for data type %s",
2178 ncompatiblepreferred == 1 ||
2179 (ncompatiblepreferred == 0 && ncompatible == 1))
2217 name1chars = strlen(name1);
2220 name2chars = strlen(name2);
2226 overhead += strlen(label) + 1;
2236 while (name1chars + name2chars > availchars)
2238 if (name1chars > name2chars)
2244 name1chars =
pg_mbcliplen(name1, name1chars, name1chars);
2246 name2chars =
pg_mbcliplen(name2, name2chars, name2chars);
2249 name =
palloc(name1chars + name2chars + overhead + 1);
2250 memcpy(name, name1, name1chars);
2255 memcpy(name + ndx, name2, name2chars);
2261 strcpy(name + ndx, label);
2295 const char *
label,
Oid namespaceid,
2303 strlcpy(modlabel, label,
sizeof(modlabel));
2311 if (!isconstraint ||
2318 snprintf(modlabel,
sizeof(modlabel),
"%s%d", label, ++pass);
2331 List *colnames,
List *exclusionOpNames,
2332 bool primary,
bool isconstraint)
2345 else if (exclusionOpNames !=
NIL)
2353 else if (isconstraint)
2392 foreach(lc, colnames)
2394 const char *
name = (
const char *)
lfirst(lc);
2397 buf[buflen++] =
'_';
2404 buflen += strlen(buf + buflen);
2424 foreach(lc, indexElems)
2427 const char *origname;
2428 const char *curname;
2435 else if (ielem->
name)
2436 origname = ielem->
name;
2448 foreach(lc2, result)
2450 if (strcmp(curname, (
char *)
lfirst(lc2)) == 0)
2461 memcpy(buf, origname, nlen);
2462 strcpy(buf + nlen, nbuf);
2484 bool concurrently =
false;
2486 char *tablespacename = NULL;
2489 foreach(lc, stmt->
params)
2493 if (strcmp(opt->
defname,
"verbose") == 0)
2495 else if (strcmp(opt->
defname,
"concurrently") == 0)
2497 else if (strcmp(opt->
defname,
"tablespace") == 0)
2501 (
errcode(ERRCODE_SYNTAX_ERROR),
2502 errmsg(
"unrecognized REINDEX option \"%s\"",
2509 "REINDEX CONCURRENTLY");
2519 if (tablespacename != NULL)
2560 "REINDEX DATABASE");
2564 elog(
ERROR,
"unrecognized object type: %d",
2608 if (relkind == RELKIND_PARTITIONED_INDEX)
2611 persistence != RELPERSISTENCE_TEMP)
2648 if (relId != oldRelId &&
OidIsValid(oldRelId))
2666 if (relkind != RELKIND_INDEX &&
2667 relkind != RELKIND_PARTITIONED_INDEX)
2669 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2677 if (relId != oldRelId)
2726 (
errmsg(
"table \"%s\" has no indexes that can be reindexed concurrently",
2740 (
errmsg(
"table \"%s\" has no indexes to reindex",
2768 bool concurrent_warning =
false;
2769 bool tablespace_warning =
false;
2779 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2780 errmsg(
"cannot reindex system catalogs concurrently")));
2802 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2803 errmsg(
"can only reindex the currently open database")));
2816 "ReindexMultipleTables",
2828 Anum_pg_class_relnamespace,
2846 Oid relid = classtuple->oid;
2855 if (classtuple->relkind != RELKIND_RELATION &&
2856 classtuple->relkind != RELKIND_MATVIEW)
2860 if (classtuple->relpersistence == RELPERSISTENCE_TEMP &&
2877 if (classtuple->relisshared &&
2888 if (!concurrent_warning)
2890 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2891 errmsg(
"cannot reindex system catalogs concurrently, skipping all")));
2892 concurrent_warning =
true;
2902 bool skip_rel =
false;
2908 if (RELKIND_HAS_STORAGE(classtuple->relkind) &&
2921 if (!tablespace_warning)
2923 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2924 errmsg(
"cannot move system relations, skipping all")));
2925 tablespace_warning =
true;
2940 if (relid == RelationRelationId)
2968 errinfo->
relkind == RELKIND_PARTITIONED_TABLE);
2970 if (errinfo->
relkind == RELKIND_PARTITIONED_TABLE)
2971 errcontext(
"while reindexing partitioned table \"%s.%s\"",
2973 else if (errinfo->
relkind == RELKIND_PARTITIONED_INDEX)
2974 errcontext(
"while reindexing partitioned index \"%s.%s\"",
2997 Assert(relkind == RELKIND_PARTITIONED_INDEX ||
2998 relkind == RELKIND_PARTITIONED_TABLE);
3008 errcallback.
arg = (
void *) &errinfo;
3013 relkind == RELKIND_PARTITIONED_TABLE ?
3014 "REINDEX TABLE" :
"REINDEX INDEX");
3036 foreach(lc, inhoids)
3046 if (!RELKIND_HAS_STORAGE(partkind))
3049 Assert(partkind == RELKIND_INDEX ||
3050 partkind == RELKIND_RELATION);
3091 char relpersistence;
3131 Assert(relkind != RELKIND_PARTITIONED_INDEX &&
3132 relkind != RELKIND_PARTITIONED_TABLE);
3135 relpersistence != RELPERSISTENCE_TEMP)
3143 else if (relkind == RELKIND_INDEX)
3167 (
errmsg(
"table \"%s.%s\" was reindexed",
3207 typedef struct ReindexIndexInfo
3224 char *relationName = NULL;
3225 char *relationNamespace = NULL;
3227 const int progress_index[] = {
3233 int64 progress_vals[4];
3242 "ReindexConcurrent",
3266 case RELKIND_RELATION:
3267 case RELKIND_MATVIEW:
3268 case RELKIND_TOASTVALUE:
3280 heapRelationIds =
lappend_oid(heapRelationIds, relationOid);
3286 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3287 errmsg(
"cannot reindex system catalogs concurrently")));
3305 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3306 errmsg(
"cannot move system relation \"%s\"",
3316 if (!indexRelation->
rd_index->indisvalid)
3318 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3319 errmsg(
"cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3322 else if (indexRelation->
rd_index->indisexclusion)
3324 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3325 errmsg(
"cannot reindex exclusion constraint index \"%s.%s\" concurrently, skipping",
3330 ReindexIndexInfo *
idx;
3335 idx =
palloc(
sizeof(ReindexIndexInfo));
3336 idx->indexId = cellOid;
3339 indexIds =
lappend(indexIds, idx);
3350 Oid toastOid = heapRelation->
rd_rel->reltoastrelid;
3358 heapRelationIds =
lappend_oid(heapRelationIds, toastOid);
3368 if (!indexRelation->
rd_index->indisvalid)
3370 (
errcode(ERRCODE_INDEX_CORRUPTED),
3371 errmsg(
"cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3376 ReindexIndexInfo *
idx;
3384 idx =
palloc(
sizeof(ReindexIndexInfo));
3385 idx->indexId = cellOid;
3386 indexIds =
lappend(indexIds, idx);
3406 ReindexIndexInfo *
idx;
3414 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3415 errmsg(
"cannot reindex system catalogs concurrently")));
3425 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3426 errmsg(
"cannot reindex invalid index on TOAST table")));
3449 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3450 errmsg(
"cannot move system relation \"%s\"",
3465 idx =
palloc(
sizeof(ReindexIndexInfo));
3466 idx->indexId = relationOid;
3467 indexIds =
lappend(indexIds, idx);
3474 case RELKIND_PARTITIONED_TABLE:
3475 case RELKIND_PARTITIONED_INDEX:
3479 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3480 errmsg(
"cannot reindex this type of relation concurrently")));
3491 if (indexIds ==
NIL)
3500 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3501 errmsg(
"cannot move non-shared relation to tablespace \"%s\"",
3531 foreach(lc, indexIds)
3533 char *concurrentName;
3535 ReindexIndexInfo *newidx;
3551 idx->amId = indexRel->
rd_rel->relam;
3554 if (indexRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
3555 elog(
ERROR,
"cannot reindex a temporary table concurrently");
3561 progress_vals[1] = 0;
3562 progress_vals[2] = idx->indexId;
3563 progress_vals[3] = idx->amId;
3575 heapRel->
rd_rel->relkind != RELKIND_TOASTVALUE)
3578 tablespaceid = indexRel->
rd_rel->reltablespace;
3597 newidx =
palloc(
sizeof(ReindexIndexInfo));
3598 newidx->indexId = newIndexId;
3599 newidx->safe = idx->safe;
3600 newidx->tableId = idx->tableId;
3601 newidx->amId = idx->amId;
3603 newIndexIds =
lappend(newIndexIds, newidx);
3611 lockrelid =
palloc(
sizeof(*lockrelid));
3613 relationLocks =
lappend(relationLocks, lockrelid);
3614 lockrelid =
palloc(
sizeof(*lockrelid));
3616 relationLocks =
lappend(relationLocks, lockrelid);
3629 foreach(lc, heapRelationIds)
3639 lockrelid =
palloc(
sizeof(*lockrelid));
3641 relationLocks =
lappend(relationLocks, lockrelid);
3647 lockTags =
lappend(lockTags, heaplocktag);
3656 foreach(lc, relationLocks)
3687 foreach(lc, newIndexIds)
3689 ReindexIndexInfo *newidx =
lfirst(lc);
3715 progress_vals[2] = newidx->indexId;
3716 progress_vals[3] = newidx->amId;
3746 foreach(lc, newIndexIds)
3748 ReindexIndexInfo *newidx =
lfirst(lc);
3780 progress_vals[2] = newidx->indexId;
3781 progress_vals[3] = newidx->amId;
3790 limitXmin = snapshot->
xmin;
3839 forboth(lc, indexIds, lc2, newIndexIds)
3841 ReindexIndexInfo *oldidx =
lfirst(lc);
3842 ReindexIndexInfo *newidx =
lfirst(lc2);
3904 foreach(lc, indexIds)
3906 ReindexIndexInfo *oldidx =
lfirst(lc);
3943 foreach(lc, indexIds)
3948 object.
classId = RelationRelationId;
3949 object.objectId = idx->indexId;
3950 object.objectSubId = 0;
3969 foreach(lc, relationLocks)
3982 if (relkind == RELKIND_INDEX)
3984 (
errmsg(
"index \"%s.%s\" was reindexed",
3985 relationNamespace, relationName),
3990 foreach(lc, newIndexIds)
3993 Oid indOid = idx->indexId;
3996 (
errmsg(
"index \"%s.%s\" was reindexed",
4003 (
errmsg(
"table \"%s.%s\" was reindexed",
4004 relationNamespace, relationName),
4034 Assert(partitionIdx->
rd_rel->relkind == RELKIND_INDEX ||
4035 partitionIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
4042 Anum_pg_inherits_inhrelid,
4046 Anum_pg_inherits_inhseqno,
4061 fix_dependencies =
false;
4066 bool isnull[Natts_pg_inherits];
4073 values[Anum_pg_inherits_inhparent - 1] =
4076 memset(isnull,
false,
sizeof(isnull));
4082 fix_dependencies =
true;
4095 fix_dependencies =
true;
4104 if (inhForm->inhparent != parentOid)
4107 elog(
ERROR,
"bogus pg_inherit row: inhrelid %u inhparent %u",
4108 inhForm->inhrelid, inhForm->inhparent);
4112 fix_dependencies =
false;
4127 if (fix_dependencies)
4177 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
#define PROGRESS_CREATEIDX_PHASE_WAIT_3
HeapTuple heap_copytuple(HeapTuple tuple)
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
#define OpclassAmNameNspIndexId
VirtualTransactionId * GetCurrentVirtualXIDs(TransactionId limitXmin, bool excludeXmin0, bool allDbs, int excludeVacuum, int *nvxids)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, List *attributeList, List *exclusionOpNames)
void RangeVarCallbackOwnsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrMap *attmap)
#define IsA(nodeptr, _type_)
static bool CheckMutability(Expr *expr)
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
Oid get_namespace_oid(const char *nspname, bool missing_ok)
static char * ChooseIndexNameAddition(List *colnames)
ObjectAddress DefineIndex(Oid relationId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
void table_close(Relation relation, LOCKMODE lockmode)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
Oid get_commutator(Oid opno)
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
int errhint(const char *fmt,...)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
#define PROGRESS_CREATEIDX_PARTITIONS_DONE
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
#define forboth(cell1, list1, cell2, list2)
void systable_endscan(SysScanDesc sysscan)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
bool IsSystemRelation(Relation relation)
void free_attrmap(AttrMap *map)
SubTransactionId oldCreateSubid
#define INDEX_CREATE_IF_NOT_EXISTS
Snapshot RegisterSnapshot(Snapshot snapshot)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
amgettuple_function amgettuple
static ListCell * lnext(const List *l, const ListCell *c)
#define RelationGetDescr(relation)
#define INDEX_CREATE_INVALID
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
#define PROGRESS_CREATEIDX_PHASE_WAIT_5
void pgstat_progress_update_param(int index, int64 val)
char get_rel_relkind(Oid relid)
char * pstrdup(const char *in)
void CommitTransactionCommand(void)
#define ALLOCSET_SMALL_SIZES
Oid get_rel_namespace(Oid relid)
Expr * expression_planner(Expr *expr)
#define InheritsRelidSeqnoIndexId
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static void reindex_error_callback(void *args)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
int errcode(int sqlerrcode)
#define PROGRESS_CREATEIDX_PHASE_WAIT_1
static Oid ReindexTable(RangeVar *relation, ReindexParams *params, bool isTopLevel)
static void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Datum idx(PG_FUNCTION_ARGS)
#define FirstLowInvalidHeapAttributeNumber
char * format_operator(Oid operator_oid)
void PopActiveSnapshot(void)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
void DeconstructQualifiedName(List *names, char **nspname_p, char **objname_p)
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
List * lcons_oid(Oid datum, List *list)
IndexInfo * BuildIndexInfo(Relation index)
bool ConstraintNameExists(const char *conname, Oid namespaceid)
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
char * ChooseRelationName(const char *name1, const char *name2, const char *label, Oid namespaceid, bool isconstraint)
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)
static List * ChooseIndexColumnNames(List *indexElems)
static void ReindexMultipleInternal(List *relids, ReindexParams *params)
bool IsToastNamespace(Oid namespaceId)
PartitionKey RelationGetPartitionKey(Relation rel)
void heap_freetuple(HeapTuple htup)
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
Oid OpclassnameGetOpcid(Oid amid, const char *opcname)
void(* callback)(void *arg)
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)
struct ErrorContextCallback * previous
Snapshot GetTransactionSnapshot(void)
#define OidIsValid(objectId)
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
bool IsPreferredType(TYPCATEGORY category, Oid type)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
#define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY
MemoryContext PortalContext
bool IsCatalogRelationOid(Oid relid)
List * indexIncludingParams
void pg_rusage_init(PGRUsage *ru0)
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
#define PROGRESS_CREATEIDX_PHASE_WAIT_4
void LWLockRelease(LWLock *lock)
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
ErrorContextCallback * error_context_stack
char * makeObjectName(const char *name1, const char *name2, const char *label)
#define VirtualTransactionIdEquals(vxid1, vxid2)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool defGetBoolean(DefElem *def)
HeapTuple systable_getnext(SysScanDesc sysscan)
#define SearchSysCacheExists1(cacheId, key1)
void pfree(void *pointer)
SortByNulls nulls_ordering
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
#define ObjectIdGetDatum(X)
#define PROGRESS_CREATEIDX_PHASE_WAIT_2
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
amoptions_function amoptions
#define REINDEXOPT_VERBOSE
Relation relation_open(Oid relationId, LOCKMODE lockmode)
char * defGetString(DefElem *def)
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
#define HTEqualStrategyNumber
bool has_superclass(Oid relationId)
int pg_mbcliplen(const char *mbstr, int len, int limit)
Oid get_relname_relid(const char *relname, Oid relnamespace)
#define ALLOCSET_DEFAULT_SIZES
char * get_database_name(Oid dbid)
static void update_relispartition(Oid relationId, bool newval)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
char * get_namespace_name(Oid nspid)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
void PushActiveSnapshot(Snapshot snap)
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
List * list_concat_copy(const List *list1, const List *list2)
#define PROGRESS_CREATEIDX_COMMAND_CREATE
Oid values[FLEXIBLE_ARRAY_MEMBER]
Oid ResolveOpClass(List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId)
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)
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
PartitionDesc RelationGetPartitionDesc(Relation rel)
const char * pg_rusage_show(const PGRUsage *ru0)
void CacheInvalidateRelcacheByRelid(Oid relid)
#define InvalidTransactionId
#define RelationGetRelationName(relation)
static ListCell * list_head(const List *l)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
FormData_pg_attribute * Form_pg_attribute
bool isTempNamespace(Oid namespaceId)
#define REINDEXOPT_REPORT_PROGRESS
SubTransactionId oldFirstRelfilenodeSubid
void op_input_types(Oid opno, Oid *lefttype, Oid *righttype)
static void set_indexsafe_procflags(void)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool isready, bool concurrent)
void CheckTableNotInUse(Relation rel, const char *stmt)
#define AssertArg(condition)
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
void UnregisterSnapshot(Snapshot snapshot)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
#define PROGRESS_WAITFOR_CURRENT_PID
List * lappend(List *list, void *datum)
#define PROGRESS_CREATEIDX_PARTITIONS_TOTAL
void reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, ReindexParams *params)
Datum * RelationGetIndexRawAttOptions(Relation indexrel)
#define REINDEXOPT_MISSING_OK
#define VirtualTransactionIdIsValid(vxid)
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
static void RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
FormData_pg_index * Form_pg_index
HeapTuple SearchSysCache1(int cacheId, Datum key1)
char * NameListToString(List *names)
#define PROGRESS_CREATEIDX_PHASE
bool reset_default_tblspc
FormData_pg_opfamily * Form_pg_opfamily
static void ReindexPartitions(Oid relid, ReindexParams *params, bool isTopLevel)
void * palloc0(Size size)
void pgstat_progress_end_command(void)
void CommandCounterIncrement(void)
void ReleaseSysCache(HeapTuple tuple)
static void fix_dependencies(ArchiveHandle *AH)
List * make_ands_implicit(Expr *clause)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define list_make1_oid(x1)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
#define PARTITION_STRATEGY_HASH
#define INDEX_CREATE_IS_PRIMARY
bool allowSystemTableMods
#define INDEX_CREATE_CONCURRENT
TYPCATEGORY TypeCategory(Oid type)
RegProcedure get_opcode(Oid opno)
static bool ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
#define ereport(elevel,...)
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc)
Datum array_eq(PG_FUNCTION_ARGS)
size_t strlcpy(char *dst, const char *src, size_t siz)
int errmsg_internal(const char *fmt,...)
#define ShareUpdateExclusiveLock
#define HeapTupleIsValid(tuple)
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
#define RELATION_IS_OTHER_TEMP(relation)
#define PROGRESS_CREATEIDX_PHASE_BUILD
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
void StartTransactionCommand(void)
struct ReindexErrorInfo ReindexErrorInfo
#define SetInvalidVirtualTransactionId(vxid)
static void CheckPredicate(Expr *predicate)
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)
bool get_index_isvalid(Oid index_oid)
FormData_pg_inherits * Form_pg_inherits
#define PROGRESS_WAITFOR_DONE
static int list_length(const List *l)
int parser_errposition(ParseState *pstate, int location)
#define REINDEX_REL_CHECK_CONSTRAINTS
Oid exprCollation(const Node *expr)
#define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
#define InvalidSubTransactionId
Oid get_opclass_family(Oid opclass)
List * RelationGetIndexList(Relation relation)
#define InvalidAttrNumber
#define ObjectAddressSet(addr, class_id, object_id)
void index_close(Relation relation, LOCKMODE lockmode)
#define DatumGetPointer(X)
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]
#define IsBootstrapProcessingMode()
int get_op_opfamily_strategy(Oid opno, Oid opfamily)
FormData_pg_class * Form_pg_class
#define INDEX_CREATE_SKIP_BUILD
#define SearchSysCacheCopy1(cacheId, key1)
#define AccessExclusiveLock
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN
#define INDEX_CREATE_PARTITIONED
int NewGUCNestLevel(void)
static void ReindexIndex(RangeVar *indexRelation, ReindexParams *params, bool isTopLevel)
static void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, ReindexParams *params)
FormData_pg_am * Form_pg_am
int errmsg(const char *fmt,...)
Oid compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError)
char * get_tablespace_name(Oid spc_oid)
void list_free(List *list)
#define PERFORM_DELETION_CONCURRENT_LOCK
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
static void ComputeIndexAttrs(IndexInfo *indexInfo, Oid *typeOidP, Oid *collationOidP, Oid *classOidP, int16 *colOptionP, List *attList, List *exclusionOpNames, Oid relId, const char *accessMethodName, Oid accessMethodId, bool amcanorder, bool isconstraint)
#define REINDEX_REL_PROCESS_TOAST
bool contain_mutable_functions(Node *clause)
static char * ChooseIndexName(const char *tabname, Oid namespaceId, List *colnames, List *exclusionOpNames, bool primary, bool isconstraint)
#define CHECK_FOR_INTERRUPTS()
bytea *(* amoptions_function)(Datum reloptions, bool validate)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
uint16 * ii_ExclusionStrats
#define PROGRESS_WAITFOR_TOTAL
#define INDEX_CREATE_ADD_CONSTRAINT
Relation table_open(Oid relationId, LOCKMODE lockmode)
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Oid getBaseType(Oid typid)
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
bool type_is_collatable(Oid typid)
FormData_pg_opclass * Form_pg_opclass
#define ERRCODE_DUPLICATE_OBJECT
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Oid get_collation_oid(List *name, bool missing_ok)
#define REINDEXOPT_CONCURRENTLY
char * get_rel_name(Oid relid)
bool bms_is_member(int x, const Bitmapset *a)
#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)
#define DirectFunctionCall2(func, arg1, arg2)
Datum * ii_OpclassOptions
#define BTEqualStrategyNumber
#define PROC_IS_AUTOVACUUM
#define PERFORM_DELETION_INTERNAL
#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID
PGPROC * BackendIdGetProc(int backendID)
Oid get_opclass_input_type(Oid opclass)
#define RelationGetNamespace(relation)