62 #include "utils/fmgroids.h"
81 Datum *opclassOptions,
84 const List *exclusionOpNames,
86 const char *accessMethodName,
92 int *ddl_save_nestlevel);
94 const List *colnames,
const List *exclusionOpNames,
95 bool primary,
bool isconstraint);
175 const char *accessMethodName,
176 const List *attributeList,
177 const List *exclusionOpNames)
183 Datum *opclassOptions;
194 int numberOfAttributes;
210 isconstraint =
false;
213 Assert(numberOfAttributes > 0);
220 (
errcode(ERRCODE_UNDEFINED_OBJECT),
221 errmsg(
"access method \"%s\" does not exist",
224 accessMethodId = accessMethodForm->oid;
239 indexInfo =
makeIndexInfo(numberOfAttributes, numberOfAttributes,
240 accessMethodId,
NIL,
NIL,
false,
false,
241 false,
false, amsummarizing);
248 typeIds, collationIds, opclassIds, opclassOptions,
249 coloptions, attributeList,
250 exclusionOpNames, relationId,
251 accessMethodName, accessMethodId,
252 amcanorder, isconstraint,
InvalidOid, 0, NULL);
258 elog(
ERROR,
"cache lookup failed for index %u", oldId);
267 indexForm->indisvalid))
274 old_natts = indexForm->indnkeyatts;
275 Assert(old_natts == numberOfAttributes);
283 ret = (memcmp(old_indclass->
values, opclassIds, old_natts *
sizeof(
Oid)) == 0 &&
284 memcmp(old_indcollation->
values, collationIds, old_natts *
sizeof(
Oid)) == 0);
293 for (
i = 0;
i < old_natts;
i++)
308 for (
i = 0;
i < old_natts;
i++)
313 pfree(oldOpclassOptions);
325 old_natts *
sizeof(
Oid)) == 0;
330 for (
i = 0;
i < old_natts && ret;
i++)
336 if ((IsPolymorphicType(left) || IsPolymorphicType(right)) &&
361 if (!opts1 && !opts2)
364 for (
i = 0;
i < natts;
i++)
369 if (opt1 == (
Datum) 0)
371 if (opt2 == (
Datum) 0)
376 else if (opt2 == (
Datum) 0)
437 for (
i = 0;
i < n_old_snapshots;
i++)
446 int n_newer_snapshots;
455 for (
j =
i;
j < n_old_snapshots;
j++)
459 for (k = 0; k < n_newer_snapshots; k++)
465 if (k >= n_newer_snapshots)
468 pfree(newer_snapshots);
535 Oid parentConstraintId,
539 bool check_not_in_use,
544 char *indexRelationName;
545 char *accessMethodName;
549 Datum *opclassOptions;
555 List *allIndexParams;
561 bool amissummarizing;
570 int numberOfAttributes;
571 int numberOfKeyAttributes;
578 Oid root_save_userid;
579 int root_save_sec_context;
580 int root_save_nestlevel;
591 if (
stmt->reset_default_tblspc)
641 stmt->indexIncludingParams);
644 if (numberOfKeyAttributes <= 0)
646 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
647 errmsg(
"must specify at least one column")));
650 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
651 errmsg(
"cannot use more than %d columns in an index",
684 switch (rel->
rd_rel->relkind)
686 case RELKIND_RELATION:
687 case RELKIND_MATVIEW:
688 case RELKIND_PARTITIONED_TABLE:
693 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
694 errmsg(
"cannot create index on relation \"%s\"",
708 partitioned = rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE;
717 if (
stmt->concurrent)
719 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
720 errmsg(
"cannot create index on partitioned table \"%s\" concurrently",
729 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
730 errmsg(
"cannot create indexes on temporary tables of other sessions")));
738 if (check_not_in_use)
751 aclresult =
object_aclcheck(NamespaceRelationId, namespaceId, root_save_userid,
762 if (
stmt->tableSpace)
767 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
768 errmsg(
"cannot specify default tablespace for partitioned relations")));
783 aclresult =
object_aclcheck(TableSpaceRelationId, tablespaceId, root_save_userid,
795 if (rel->
rd_rel->relisshared)
796 tablespaceId = GLOBALTABLESPACE_OID;
797 else if (tablespaceId == GLOBALTABLESPACE_OID)
799 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
800 errmsg(
"only shared relations can be placed in pg_global tablespace")));
810 indexRelationName =
stmt->idxname;
811 if (indexRelationName == NULL)
815 stmt->excludeOpNames,
822 accessMethodName =
stmt->accessMethod;
830 if (strcmp(accessMethodName,
"rtree") == 0)
833 (
errmsg(
"substituting access method \"gist\" for obsolete method \"rtree\"")));
834 accessMethodName =
"gist";
840 (
errcode(ERRCODE_UNDEFINED_OBJECT),
841 errmsg(
"access method \"%s\" does not exist",
845 accessMethodId = accessMethodForm->oid;
853 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
854 errmsg(
"access method \"%s\" does not support unique indexes",
858 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
859 errmsg(
"access method \"%s\" does not support included columns",
863 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
864 errmsg(
"access method \"%s\" does not support multicolumn indexes",
868 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
869 errmsg(
"access method \"%s\" does not support exclusion constraints",
882 if (
stmt->whereClause)
889 NULL, NULL,
false,
false);
899 numberOfKeyAttributes,
904 stmt->nulls_not_distinct,
915 typeIds, collationIds, opclassIds, opclassOptions,
916 coloptions, allIndexParams,
917 stmt->excludeOpNames, tableId,
918 accessMethodName, accessMethodId,
919 amcanorder,
stmt->isconstraint, root_save_userid,
920 root_save_sec_context, &root_save_nestlevel);
938 if (partitioned && (
stmt->unique ||
stmt->excludeOpNames))
941 const char *constraint_type;
945 constraint_type =
"PRIMARY KEY";
946 else if (
stmt->unique)
947 constraint_type =
"UNIQUE";
948 else if (
stmt->excludeOpNames)
949 constraint_type =
"EXCLUDE";
953 constraint_type = NULL;
960 for (
i = 0;
i <
key->partnatts;
i++)
979 key->partopcintype[
i],
980 key->partopcintype[
i],
983 elog(
ERROR,
"missing operator %d(%u,%u) in partition opfamily %u",
984 eq_strategy,
key->partopcintype[
i],
key->partopcintype[
i],
985 key->partopfamily[
i]);
995 if (
stmt->unique && accessMethodId != BTREE_AM_OID)
997 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
998 errmsg(
"cannot match partition key to an index using access method \"%s\"",
1005 if (
key->partattrs[
i] == 0)
1007 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1008 errmsg(
"unsupported %s constraint with partition key definition",
1010 errdetail(
"%s constraints cannot be used when partition keys include expressions.",
1025 if (
key->partcollation[
i] != collationIds[
j])
1039 else if (
stmt->excludeOpNames)
1043 if (ptkey_eqop == idx_eqop)
1048 else if (
stmt->excludeOpNames)
1059 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1060 errmsg(
"cannot match partition key to index on column \"%s\" using non-equal operator \"%s\"",
1073 key->partattrs[
i] - 1);
1075 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1076 errmsg(
"unique constraint on partitioned table must include all partitioning columns"),
1077 errdetail(
"%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
1095 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1096 errmsg(
"index creation on system columns is not supported")));
1114 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1115 errmsg(
"index creation on system columns is not supported")));
1127 if (
stmt->isconstraint && !quiet)
1129 const char *constraint_type;
1132 constraint_type =
"PRIMARY KEY";
1133 else if (
stmt->unique)
1134 constraint_type =
"UNIQUE";
1135 else if (
stmt->excludeOpNames)
1136 constraint_type =
"EXCLUDE";
1140 constraint_type = NULL;
1144 (
errmsg_internal(
"%s %s will create implicit index \"%s\" for table \"%s\"",
1145 is_alter_table ?
"ALTER TABLE / ADD" :
"CREATE TABLE /",
1162 flags = constr_flags = 0;
1163 if (
stmt->isconstraint)
1165 if (skip_build || concurrent || partitioned)
1167 if (
stmt->if_not_exists)
1180 if (partitioned &&
stmt->relation && !
stmt->relation->inh)
1188 if (
stmt->deferrable)
1190 if (
stmt->initdeferred)
1194 index_create(rel, indexRelationName, indexRelationId, parentIndexId,
1196 stmt->oldNumber, indexInfo, indexColNames,
1197 accessMethodId, tablespaceId,
1198 collationIds, opclassIds, opclassOptions,
1199 coloptions, NULL, reloptions,
1200 flags, constr_flags,
1202 &createdConstraintId);
1236 if (
stmt->idxcomment != NULL)
1251 if ((!
stmt->relation ||
stmt->relation->inh) && partdesc->
nparts > 0)
1253 int nparts = partdesc->
nparts;
1255 bool invalidate_parent =
false;
1278 if (total_parts < 0)
1291 memcpy(part_oids, partdesc->
oids,
sizeof(
Oid) * nparts);
1301 parentIndex =
index_open(indexRelationId, lockmode);
1314 for (
int i = 0;
i < nparts;
i++)
1316 Oid childRelid = part_oids[
i];
1318 Oid child_save_userid;
1319 int child_save_sec_context;
1320 int child_save_nestlevel;
1329 &child_save_sec_context);
1340 if (childrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1344 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1345 errmsg(
"cannot create unique index on partitioned table \"%s\"",
1347 errdetail(
"Table \"%s\" contains partitions that are foreign tables.",
1352 child_save_sec_context);
1363 foreach(cell, childidxs)
1409 createdConstraintId,
1413 invalidate_parent =
true;
1439 child_save_sec_context);
1448 bool found_whole_row;
1486 if (found_whole_row)
1487 elog(
ERROR,
"cannot convert whole-row table reference");
1494 if (found_whole_row)
1495 elog(
ERROR,
"cannot convert whole-row table reference");
1503 root_save_sec_context);
1508 createdConstraintId,
1510 is_alter_table, check_rights,
1514 child_save_sec_context);
1522 invalidate_parent =
true;
1535 if (invalidate_parent)
1544 elog(
ERROR,
"cache lookup failed for index %u",
1640 const int progress_cols[] = {
1644 const int64 progress_vals[] = {
1747 limitXmin = snapshot->
xmin;
1831 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1832 errmsg(
"functions in index predicate must be marked IMMUTABLE")));
1849 Datum *opclassOptions,
1851 const List *attList,
1852 const List *exclusionOpNames,
1854 const char *accessMethodName,
1859 int ddl_sec_context,
1860 int *ddl_save_nestlevel)
1867 int save_sec_context;
1870 if (exclusionOpNames)
1876 nextExclOp =
list_head(exclusionOpNames);
1888 foreach(lc, attList)
1897 if (attribute->
name != NULL)
1910 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1911 errmsg(
"column \"%s\" named in key does not exist",
1915 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1916 errmsg(
"column \"%s\" does not exist",
1921 atttype = attform->atttypid;
1922 attcollation = attform->attcollation;
1932 if (attn >= nkeycols)
1934 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1935 errmsg(
"expressions are not supported in included columns")));
1975 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1976 errmsg(
"functions in index expression must be marked IMMUTABLE")));
1980 typeOids[attn] = atttype;
1986 if (attn >= nkeycols)
1990 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1991 errmsg(
"including column does not support a collation")));
1994 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1995 errmsg(
"including column does not support an operator class")));
1998 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1999 errmsg(
"including column does not support ASC/DESC options")));
2002 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2003 errmsg(
"including column does not support NULLS FIRST/LAST options")));
2006 opclassOptions[attn] = (
Datum) 0;
2007 colOptions[attn] = 0;
2045 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
2046 errmsg(
"could not determine which collation to use for index expression"),
2047 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
2053 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2054 errmsg(
"collations are not supported by type %s",
2058 collationOids[attn] = attcollation;
2120 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2121 errmsg(
"operator %s is not commutative",
2123 errdetail(
"Only commutative operators can be used in exclusion constraints.")));
2143 elog(
ERROR,
"cache lookup failed for opfamily %u",
2148 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2149 errmsg(
"operator %s is not a member of operator family \"%s\"",
2152 errdetail(
"The exclusion operator must be related to the index operator class for the constraint.")));
2158 nextExclOp =
lnext(exclusionOpNames, nextExclOp);
2166 colOptions[attn] = 0;
2171 colOptions[attn] |= INDOPTION_DESC;
2176 colOptions[attn] |= INDOPTION_NULLS_FIRST;
2179 colOptions[attn] |= INDOPTION_NULLS_FIRST;
2186 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2187 errmsg(
"access method \"%s\" does not support ASC/DESC options",
2188 accessMethodName)));
2191 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2192 errmsg(
"access method \"%s\" does not support NULLS FIRST/LAST options",
2193 accessMethodName)));
2201 opclassOptions[attn] =
2203 NULL, NULL,
false,
false);
2206 opclassOptions[attn] = (
Datum) 0;
2220 const char *accessMethodName,
Oid accessMethodId)
2235 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2236 errmsg(
"data type %s has no default operator class for access method \"%s\"",
2238 errhint(
"You must specify an operator class for the index or define a default operator class for the data type.")));
2266 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2267 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2268 opcname, accessMethodName)));
2274 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2275 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2283 opClassId = opform->oid;
2284 opInputType = opform->opcintype;
2288 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2289 errmsg(
"operator class \"%s\" does not accept data type %s",
2308 int ncompatible = 0;
2309 int ncompatiblepreferred = 0;
2336 Anum_pg_opclass_opcmethod,
2348 if (!opclass->opcdefault)
2350 if (opclass->opcintype == type_id)
2353 result = opclass->oid;
2355 else if (nexact == 0 &&
2360 ncompatiblepreferred++;
2361 result = opclass->oid;
2363 else if (ncompatiblepreferred == 0)
2366 result = opclass->oid;
2379 errmsg(
"there are multiple default operator classes for data type %s",
2383 ncompatiblepreferred == 1 ||
2384 (ncompatiblepreferred == 0 && ncompatible == 1))
2422 name1chars = strlen(name1);
2425 name2chars = strlen(name2);
2431 overhead += strlen(
label) + 1;
2441 while (name1chars + name2chars > availchars)
2443 if (name1chars > name2chars)
2449 name1chars =
pg_mbcliplen(name1, name1chars, name1chars);
2451 name2chars =
pg_mbcliplen(name2, name2chars, name2chars);
2454 name =
palloc(name1chars + name2chars + overhead + 1);
2455 memcpy(
name, name1, name1chars);
2460 memcpy(
name + ndx, name2, name2chars);
2500 const char *
label,
Oid namespaceid,
2516 if (!isconstraint ||
2523 snprintf(modlabel,
sizeof(modlabel),
"%s%d",
label, ++pass);
2536 const List *colnames,
const List *exclusionOpNames,
2537 bool primary,
bool isconstraint)
2550 else if (exclusionOpNames !=
NIL)
2558 else if (isconstraint)
2597 foreach(lc, colnames)
2599 const char *
name = (
const char *)
lfirst(lc);
2602 buf[buflen++] =
'_';
2609 buflen += strlen(
buf + buflen);
2629 foreach(lc, indexElems)
2632 const char *origname;
2633 const char *curname;
2640 else if (ielem->
name)
2641 origname = ielem->
name;
2653 foreach(lc2, result)
2655 if (strcmp(curname, (
char *)
lfirst(lc2)) == 0)
2666 memcpy(
buf, origname, nlen);
2667 strcpy(
buf + nlen, nbuf);
2689 bool concurrently =
false;
2691 char *tablespacename = NULL;
2694 foreach(lc,
stmt->params)
2698 if (strcmp(opt->
defname,
"verbose") == 0)
2700 else if (strcmp(opt->
defname,
"concurrently") == 0)
2702 else if (strcmp(opt->
defname,
"tablespace") == 0)
2706 (
errcode(ERRCODE_SYNTAX_ERROR),
2707 errmsg(
"unrecognized REINDEX option \"%s\"",
2714 "REINDEX CONCURRENTLY");
2724 if (tablespacename != NULL)
2765 "REINDEX DATABASE");
2769 elog(
ERROR,
"unrecognized object type: %d",
2814 if (relkind == RELKIND_PARTITIONED_INDEX)
2817 persistence != RELPERSISTENCE_TEMP)
2855 if (relId != oldRelId &&
OidIsValid(oldRelId))
2873 if (relkind != RELKIND_INDEX &&
2874 relkind != RELKIND_PARTITIONED_INDEX)
2876 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2891 if (relId != oldRelId)
2900 state->locked_table_oid = table_oid;
2939 (
errmsg(
"table \"%s\" has no indexes that can be reindexed concurrently",
2953 (
errmsg(
"table \"%s\" has no indexes to reindex",
2981 bool concurrent_warning =
false;
2982 bool tablespace_warning =
false;
2983 const char *objectName =
stmt->name;
2999 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3000 errmsg(
"cannot reindex system catalogs concurrently")));
3023 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3024 errmsg(
"can only reindex the currently open database")));
3038 "ReindexMultipleTables",
3050 Anum_pg_class_relnamespace,
3068 Oid relid = classtuple->oid;
3077 if (classtuple->relkind != RELKIND_RELATION &&
3078 classtuple->relkind != RELKIND_MATVIEW)
3082 if (classtuple->relpersistence == RELPERSISTENCE_TEMP &&
3102 if (classtuple->relisshared &&
3113 if (!concurrent_warning)
3115 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3116 errmsg(
"cannot reindex system catalogs concurrently, skipping all")));
3117 concurrent_warning =
true;
3127 bool skip_rel =
false;
3133 if (RELKIND_HAS_STORAGE(classtuple->relkind) &&
3146 if (!tablespace_warning)
3148 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3149 errmsg(
"cannot move system relations, skipping all")));
3150 tablespace_warning =
true;
3165 if (relid == RelationRelationId)
3194 if (errinfo->
relkind == RELKIND_PARTITIONED_TABLE)
3195 errcontext(
"while reindexing partitioned table \"%s.%s\"",
3197 else if (errinfo->
relkind == RELKIND_PARTITIONED_INDEX)
3198 errcontext(
"while reindexing partitioned index \"%s.%s\"",
3221 Assert(RELKIND_HAS_PARTITIONS(relkind));
3231 errcallback.
arg = (
void *) &errinfo;
3236 relkind == RELKIND_PARTITIONED_TABLE ?
3237 "REINDEX TABLE" :
"REINDEX INDEX");
3259 foreach(lc, inhoids)
3269 if (!RELKIND_HAS_STORAGE(partkind))
3272 Assert(partkind == RELKIND_INDEX ||
3273 partkind == RELKIND_RELATION);
3314 char relpersistence;
3354 Assert(!RELKIND_HAS_PARTITIONS(relkind));
3357 relpersistence != RELPERSISTENCE_TEMP)
3367 else if (relkind == RELKIND_INDEX)
3391 (
errmsg(
"table \"%s.%s\" was reindexed",
3431 typedef struct ReindexIndexInfo
3448 char *relationName = NULL;
3449 char *relationNamespace = NULL;
3451 const int progress_index[] = {
3457 int64 progress_vals[4];
3466 "ReindexConcurrent",
3490 case RELKIND_RELATION:
3491 case RELKIND_MATVIEW:
3492 case RELKIND_TOASTVALUE:
3504 heapRelationIds =
lappend_oid(heapRelationIds, relationOid);
3510 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3511 errmsg(
"cannot reindex system catalogs concurrently")));
3529 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3530 errmsg(
"cannot move system relation \"%s\"",
3540 if (!indexRelation->
rd_index->indisvalid)
3542 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3543 errmsg(
"skipping reindex of invalid index \"%s.%s\"",
3546 errhint(
"Use DROP INDEX or REINDEX INDEX.")));
3547 else if (indexRelation->
rd_index->indisexclusion)
3549 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3550 errmsg(
"cannot reindex exclusion constraint index \"%s.%s\" concurrently, skipping",
3555 ReindexIndexInfo *
idx;
3561 idx->indexId = cellOid;
3575 Oid toastOid = heapRelation->
rd_rel->reltoastrelid;
3583 heapRelationIds =
lappend_oid(heapRelationIds, toastOid);
3593 if (!indexRelation->
rd_index->indisvalid)
3595 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3596 errmsg(
"skipping reindex of invalid index \"%s.%s\"",
3599 errhint(
"Use DROP INDEX or REINDEX INDEX.")));
3602 ReindexIndexInfo *
idx;
3611 idx->indexId = cellOid;
3632 ReindexIndexInfo *
idx;
3640 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3641 errmsg(
"cannot reindex system catalogs concurrently")));
3651 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3652 errmsg(
"cannot reindex invalid index on TOAST table")));
3675 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3676 errmsg(
"cannot move system relation \"%s\"",
3692 idx->indexId = relationOid;
3700 case RELKIND_PARTITIONED_TABLE:
3701 case RELKIND_PARTITIONED_INDEX:
3705 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3706 errmsg(
"cannot reindex this type of relation concurrently")));
3717 if (indexIds ==
NIL)
3723 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3724 errmsg(
"cannot move non-shared relation to tablespace \"%s\"",
3754 foreach(lc, indexIds)
3756 char *concurrentName;
3758 ReindexIndexInfo *newidx;
3763 int save_sec_context;
3791 if (indexRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
3792 elog(
ERROR,
"cannot reindex a temporary table concurrently");
3797 progress_vals[1] = 0;
3798 progress_vals[2] =
idx->indexId;
3799 progress_vals[3] =
idx->amId;
3811 heapRel->
rd_rel->relkind != RELKIND_TOASTVALUE)
3814 tablespaceid = indexRel->
rd_rel->reltablespace;
3834 newidx->indexId = newIndexId;
3835 newidx->safe =
idx->safe;
3836 newidx->tableId =
idx->tableId;
3837 newidx->amId =
idx->amId;
3839 newIndexIds =
lappend(newIndexIds, newidx);
3849 relationLocks =
lappend(relationLocks, lockrelid);
3852 relationLocks =
lappend(relationLocks, lockrelid);
3886 foreach(lc, heapRelationIds)
3898 relationLocks =
lappend(relationLocks, lockrelid);
3904 lockTags =
lappend(lockTags, heaplocktag);
3913 foreach(lc, relationLocks)
3944 foreach(lc, newIndexIds)
3946 ReindexIndexInfo *newidx =
lfirst(lc);
3972 progress_vals[2] = newidx->indexId;
3973 progress_vals[3] = newidx->amId;
4003 foreach(lc, newIndexIds)
4005 ReindexIndexInfo *newidx =
lfirst(lc);
4036 progress_vals[2] = newidx->indexId;
4037 progress_vals[3] = newidx->amId;
4046 limitXmin = snapshot->
xmin;
4095 forboth(lc, indexIds, lc2, newIndexIds)
4097 ReindexIndexInfo *oldidx =
lfirst(lc);
4098 ReindexIndexInfo *newidx =
lfirst(lc2);
4160 foreach(lc, indexIds)
4162 ReindexIndexInfo *oldidx =
lfirst(lc);
4199 foreach(lc, indexIds)
4204 object.
classId = RelationRelationId;
4205 object.objectId =
idx->indexId;
4206 object.objectSubId = 0;
4225 foreach(lc, relationLocks)
4238 if (relkind == RELKIND_INDEX)
4240 (
errmsg(
"index \"%s.%s\" was reindexed",
4241 relationNamespace, relationName),
4246 foreach(lc, newIndexIds)
4249 Oid indOid =
idx->indexId;
4252 (
errmsg(
"index \"%s.%s\" was reindexed",
4259 (
errmsg(
"table \"%s.%s\" was reindexed",
4260 relationNamespace, relationName),
4290 Assert(partitionIdx->
rd_rel->relkind == RELKIND_INDEX ||
4291 partitionIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
4298 Anum_pg_inherits_inhrelid,
4302 Anum_pg_inherits_inhseqno,
4344 if (inhForm->inhparent != parentOid)
4347 elog(
ERROR,
"bogus pg_inherit row: inhrelid %u inhparent %u",
4348 inhForm->inhrelid, inhForm->inhparent);
4420 elog(
ERROR,
"cache lookup failed for relation %u", relationId);
Datum idx(PG_FUNCTION_ARGS)
bool has_privs_of_role(Oid member, Oid role)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
IndexAmRoutine * GetIndexAmRoutine(Oid amhandler)
bytea *(* amoptions_function)(Datum reloptions, bool validate)
Datum array_eq(PG_FUNCTION_ARGS)
void free_attrmap(AttrMap *map)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_incr_param(int index, int64 incr)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
@ PROGRESS_COMMAND_CREATE_INDEX
bool bms_is_member(int x, const Bitmapset *a)
#define InvalidSubTransactionId
#define Assert(condition)
#define OidIsValid(objectId)
bool IsToastNamespace(Oid namespaceId)
bool IsSystemRelation(Relation relation)
bool IsCatalogRelationOid(Oid relid)
bool IsSystemClass(Oid relid, Form_pg_class reltuple)
bool contain_mutable_functions_after_planning(Expr *expr)
char * get_database_name(Oid dbid)
bool defGetBoolean(DefElem *def)
char * defGetString(DefElem *def)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
@ DEPENDENCY_PARTITION_PRI
@ DEPENDENCY_PARTITION_SEC
#define PERFORM_DELETION_CONCURRENT_LOCK
#define PERFORM_DELETION_INTERNAL
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define palloc_object(type)
#define palloc_array(type, count)
#define DirectFunctionCall2(func, arg1, arg2)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
bool allowSystemTableMods
int NewGUCNestLevel(void)
void RestrictSearchPath(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
HeapTuple heap_copytuple(HeapTuple tuple)
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Oid IndexGetRelation(Oid indexId, bool missing_ok)
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, const List *indexColNames, Oid accessMethodId, Oid tableSpaceId, const Oid *collationIds, const Oid *opclassIds, const Datum *opclassOptions, const int16 *coloptions, const NullableDatum *stattargets, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, const Oid *collations1, const Oid *collations2, const Oid *opfamilies1, const Oid *opfamilies2, const AttrMap *attmap)
bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
IndexInfo * BuildIndexInfo(Relation index)
void reindex_index(const ReindexStmt *stmt, Oid indexId, bool skip_constraint_checks, char persistence, const ReindexParams *params)
#define INDEX_CREATE_IS_PRIMARY
#define INDEX_CREATE_IF_NOT_EXISTS
#define REINDEX_REL_PROCESS_TOAST
#define INDEX_CREATE_PARTITIONED
#define REINDEXOPT_CONCURRENTLY
#define REINDEXOPT_MISSING_OK
#define INDEX_CREATE_INVALID
#define INDEX_CREATE_ADD_CONSTRAINT
#define INDEX_CREATE_SKIP_BUILD
#define INDEX_CONSTR_CREATE_DEFERRABLE
#define REINDEXOPT_REPORT_PROGRESS
#define INDEX_CONSTR_CREATE_INIT_DEFERRED
#define INDEX_CREATE_CONCURRENT
#define REINDEXOPT_VERBOSE
#define REINDEX_REL_CHECK_CONSTRAINTS
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
static bool ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const ReindexParams *params)
char * makeObjectName(const char *name1, const char *name2, const char *label)
void ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, const List *attributeList, const List *exclusionOpNames)
ObjectAddress DefineIndex(Oid tableId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, int total_parts, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
static void set_indexsafe_procflags(void)
static void reindex_error_callback(void *arg)
static void ReindexIndex(const ReindexStmt *stmt, const ReindexParams *params, bool isTopLevel)
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
static char * ChooseIndexNameAddition(const List *colnames)
static void ReindexMultipleTables(const ReindexStmt *stmt, const ReindexParams *params)
static void ComputeIndexAttrs(IndexInfo *indexInfo, Oid *typeOids, Oid *collationOids, Oid *opclassOids, Datum *opclassOptions, int16 *colOptions, const List *attList, const List *exclusionOpNames, Oid relId, const char *accessMethodName, Oid accessMethodId, bool amcanorder, bool isconstraint, Oid ddl_userid, int ddl_sec_context, int *ddl_save_nestlevel)
static bool CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts)
static void update_relispartition(Oid relationId, bool newval)
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
Oid ResolveOpClass(const List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId)
static void ReindexPartitions(const ReindexStmt *stmt, Oid relid, const ReindexParams *params, bool isTopLevel)
struct ReindexErrorInfo ReindexErrorInfo
static Oid ReindexTable(const ReindexStmt *stmt, const ReindexParams *params, bool isTopLevel)
static void CheckPredicate(Expr *predicate)
static void ReindexMultipleInternal(const ReindexStmt *stmt, const List *relids, const ReindexParams *params)
static void RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
static List * ChooseIndexColumnNames(const List *indexElems)
static char * ChooseIndexName(const char *tabname, Oid namespaceId, const List *colnames, const List *exclusionOpNames, bool primary, bool isconstraint)
char * ChooseRelationName(const char *name1, const char *name2, const char *label, Oid namespaceid, bool isconstraint)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void CacheInvalidateRelcacheByRelid(Oid relid)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
void list_free(List *list)
List * lcons_oid(Oid datum, List *list)
List * list_concat_copy(const List *list1, const List *list2)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
#define VirtualTransactionIdIsValid(vxid)
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
#define VirtualTransactionIdEquals(vxid1, vxid2)
#define SetInvalidVirtualTransactionId(vxid)
#define AccessExclusiveLock
#define ShareUpdateExclusiveLock
char get_rel_persistence(Oid relid)
char * get_opname(Oid opno)
bool get_index_isvalid(Oid index_oid)
Oid get_opclass_input_type(Oid opclass)
Oid get_opclass_family(Oid opclass)
char * get_namespace_name(Oid nspid)
bool get_opclass_opfamily_and_input_type(Oid opclass, Oid *opfamily, Oid *opcintype)
Datum get_attoptions(Oid relid, int16 attnum)
char get_rel_relkind(Oid relid)
Oid get_rel_namespace(Oid relid)
RegProcedure get_opcode(Oid opno)
int get_op_opfamily_strategy(Oid opno, Oid opfamily)
char * get_rel_name(Oid relid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
bool type_is_collatable(Oid typid)
Oid getBaseType(Oid typid)
Oid get_relname_relid(const char *relname, Oid relnamespace)
Oid get_commutator(Oid opno)
void op_input_types(Oid opno, Oid *lefttype, Oid *righttype)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
List * make_ands_implicit(Expr *clause)
IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool nulls_not_distinct, bool isready, bool concurrent, bool summarizing)
int pg_mbcliplen(const char *mbstr, int len, int limit)
char * pstrdup(const char *in)
void pfree(void *pointer)
void MemoryContextDelete(MemoryContext context)
MemoryContext PortalContext
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define IsBootstrapProcessingMode()
#define SECURITY_RESTRICTED_OPERATION
#define CHECK_FOR_INTERRUPTS()
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
Oid OpclassnameGetOpcid(Oid amid, const char *opcname)
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
bool isTempNamespace(Oid namespaceId)
Oid get_collation_oid(List *collname, bool missing_ok)
void DeconstructQualifiedName(const List *names, char **nspname_p, char **objname_p)
Oid get_namespace_oid(const char *nspname, bool missing_ok)
char * NameListToString(const List *names)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
#define IsA(nodeptr, _type_)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
TYPCATEGORY TypeCategory(Oid type)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
bool IsPreferredType(TYPCATEGORY category, Oid type)
int parser_errposition(ParseState *pstate, int location)
Oid compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError)
@ PARTITION_STRATEGY_HASH
@ REINDEX_OBJECT_DATABASE
PartitionKey RelationGetPartitionKey(Relation rel)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
FormData_pg_am * Form_pg_am
FormData_pg_attribute * Form_pg_attribute
static void fix_dependencies(ArchiveHandle *AH)
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
Oid get_relation_idx_constraint_oid(Oid relationId, Oid indexId)
void ConstraintSetParentConstraint(Oid childConstrId, Oid parentConstrId, Oid childTableId)
bool ConstraintNameExists(const char *conname, Oid namespaceid)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
FormData_pg_index * Form_pg_index
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)
bool has_superclass(Oid relationId)
FormData_pg_inherits * Form_pg_inherits
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define list_make1_oid(x1)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
FormData_pg_opclass * Form_pg_opclass
FormData_pg_opfamily * Form_pg_opfamily
const char * pg_rusage_show(const PGRUsage *ru0)
void pg_rusage_init(PGRUsage *ru0)
size_t strlcpy(char *dst, const char *src, size_t siz)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
#define PROC_IS_AUTOVACUUM
PGPROC * ProcNumberGetProc(ProcNumber procNumber)
VirtualTransactionId * GetCurrentVirtualXIDs(TransactionId limitXmin, bool excludeXmin0, bool allDbs, int excludeVacuum, int *nvxids)
#define PROGRESS_CREATEIDX_PHASE_WAIT_4
#define PROGRESS_CREATEIDX_PHASE_BUILD
#define PROGRESS_CREATEIDX_PARTITIONS_DONE
#define PROGRESS_CREATEIDX_PHASE_WAIT_1
#define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY
#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID
#define PROGRESS_WAITFOR_DONE
#define PROGRESS_CREATEIDX_PHASE_WAIT_3
#define PROGRESS_WAITFOR_TOTAL
#define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY
#define PROGRESS_CREATEIDX_COMMAND_CREATE
#define PROGRESS_WAITFOR_CURRENT_PID
#define PROGRESS_CREATEIDX_PHASE_WAIT_2
#define PROGRESS_CREATEIDX_PHASE
#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN
#define PROGRESS_CREATEIDX_PHASE_WAIT_5
#define PROGRESS_CREATEIDX_INDEX_OID
#define PROGRESS_CREATEIDX_PARTITIONS_TOTAL
#define PROGRESS_CREATEIDX_COMMAND
MemoryContextSwitchTo(old_ctx)
char * format_operator(Oid operator_oid)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationGetNamespace(relation)
List * RelationGetIndexList(Relation relation)
void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)
bytea * index_reloptions(amoptions_function amoptions, Datum reloptions, bool validate)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
#define InvalidRelFileNumber
#define RelFileNumberIsValid(relnumber)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Snapshot GetTransactionSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
bool ActiveSnapshotSet(void)
Snapshot RegisterSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
#define HTEqualStrategyNumber
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
struct ErrorContextCallback * previous
void(* callback)(void *arg)
amoptions_function amoptions
amgettuple_function amgettuple
SortByNulls nulls_ordering
uint16 * ii_ExclusionStrats
AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]
SubTransactionId oldFirstRelfilelocatorSubid
SubTransactionId oldCreateSubid
Oid values[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists1(cacheId, key1)
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
static void table_endscan(TableScanDesc scan)
void CheckTableNotInUse(Relation rel, const char *stmt)
void SetRelationHasSubclass(Oid relationId, bool relhassubclass)
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define InvalidTransactionId
#define TupleDescAttr(tupdesc, i)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
void CommandCounterIncrement(void)
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
void StartTransactionCommand(void)
void CommitTransactionCommand(void)