62 #include "utils/fmgroids.h"
83 List *exclusionOpNames,
85 const char *accessMethodName,
Oid accessMethodId,
90 int *ddl_save_nestlevel);
92 List *colnames,
List *exclusionOpNames,
93 bool primary,
bool isconstraint);
172 const char *accessMethodName,
174 List *exclusionOpNames)
178 Oid *collationObjectId;
190 int numberOfAttributes;
206 isconstraint =
false;
209 Assert(numberOfAttributes > 0);
216 (
errcode(ERRCODE_UNDEFINED_OBJECT),
217 errmsg(
"access method \"%s\" does not exist",
220 accessMethodId = accessMethodForm->oid;
235 indexInfo =
makeIndexInfo(numberOfAttributes, numberOfAttributes,
236 accessMethodId,
NIL,
NIL,
false,
false,
237 false,
false, amsummarizing);
243 typeObjectId, collationObjectId, classObjectId,
244 coloptions, attributeList,
245 exclusionOpNames, relationId,
246 accessMethodName, accessMethodId,
247 amcanorder, isconstraint,
InvalidOid, 0, NULL);
253 elog(
ERROR,
"cache lookup failed for index %u", oldId);
262 indexForm->indisvalid))
269 old_natts = indexForm->indnkeyatts;
270 Assert(old_natts == numberOfAttributes);
278 ret = (memcmp(old_indclass->
values, classObjectId,
279 old_natts *
sizeof(
Oid)) == 0 &&
280 memcmp(old_indcollation->
values, collationObjectId,
281 old_natts *
sizeof(
Oid)) == 0);
290 for (
i = 0;
i < old_natts;
i++)
309 pfree(opclassOptions);
321 old_natts *
sizeof(
Oid)) == 0;
326 for (
i = 0;
i < old_natts && ret;
i++)
332 if ((IsPolymorphicType(left) || IsPolymorphicType(right)) &&
357 if (!opts1 && !opts2)
360 for (
i = 0;
i < natts;
i++)
365 if (opt1 == (
Datum) 0)
367 if (opt2 == (
Datum) 0)
372 else if (opt2 == (
Datum) 0)
433 for (
i = 0;
i < n_old_snapshots;
i++)
442 int n_newer_snapshots;
451 for (
j =
i;
j < n_old_snapshots;
j++)
455 for (k = 0; k < n_newer_snapshots; k++)
461 if (k >= n_newer_snapshots)
464 pfree(newer_snapshots);
531 Oid parentConstraintId,
535 bool check_not_in_use,
540 char *indexRelationName;
541 char *accessMethodName;
543 Oid *collationObjectId;
550 List *allIndexParams;
556 bool amissummarizing;
565 int numberOfAttributes;
566 int numberOfKeyAttributes;
573 Oid root_save_userid;
574 int root_save_sec_context;
575 int root_save_nestlevel;
584 if (
stmt->reset_default_tblspc)
635 stmt->indexIncludingParams);
638 if (numberOfKeyAttributes <= 0)
640 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
641 errmsg(
"must specify at least one column")));
644 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
645 errmsg(
"cannot use more than %d columns in an index",
678 switch (rel->
rd_rel->relkind)
680 case RELKIND_RELATION:
681 case RELKIND_MATVIEW:
682 case RELKIND_PARTITIONED_TABLE:
687 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
688 errmsg(
"cannot create index on relation \"%s\"",
702 partitioned = rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE;
711 if (
stmt->concurrent)
713 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
714 errmsg(
"cannot create index on partitioned table \"%s\" concurrently",
716 if (
stmt->excludeOpNames)
718 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
719 errmsg(
"cannot create exclusion constraints on partitioned table \"%s\"",
728 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
729 errmsg(
"cannot create indexes on temporary tables of other sessions")));
737 if (check_not_in_use)
750 aclresult =
object_aclcheck(NamespaceRelationId, namespaceId, root_save_userid,
761 if (
stmt->tableSpace)
766 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
767 errmsg(
"cannot specify default tablespace for partitioned relations")));
782 aclresult =
object_aclcheck(TableSpaceRelationId, tablespaceId, root_save_userid,
794 if (rel->
rd_rel->relisshared)
795 tablespaceId = GLOBALTABLESPACE_OID;
796 else if (tablespaceId == GLOBALTABLESPACE_OID)
798 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
799 errmsg(
"only shared relations can be placed in pg_global tablespace")));
809 indexRelationName =
stmt->idxname;
810 if (indexRelationName == NULL)
814 stmt->excludeOpNames,
821 accessMethodName =
stmt->accessMethod;
829 if (strcmp(accessMethodName,
"rtree") == 0)
832 (
errmsg(
"substituting access method \"gist\" for obsolete method \"rtree\"")));
833 accessMethodName =
"gist";
839 (
errcode(ERRCODE_UNDEFINED_OBJECT),
840 errmsg(
"access method \"%s\" does not exist",
844 accessMethodId = accessMethodForm->oid;
852 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
853 errmsg(
"access method \"%s\" does not support unique indexes",
857 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
858 errmsg(
"access method \"%s\" does not support included columns",
862 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
863 errmsg(
"access method \"%s\" does not support multicolumn indexes",
867 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
868 errmsg(
"access method \"%s\" does not support exclusion constraints",
881 if (
stmt->whereClause)
888 NULL, NULL,
false,
false);
898 numberOfKeyAttributes,
903 stmt->nulls_not_distinct,
913 typeObjectId, collationObjectId, classObjectId,
914 coloptions, allIndexParams,
915 stmt->excludeOpNames, relationId,
916 accessMethodName, accessMethodId,
917 amcanorder,
stmt->isconstraint, root_save_userid,
918 root_save_sec_context, &root_save_nestlevel);
935 if (partitioned && (
stmt->unique ||
stmt->primary))
938 const char *constraint_type;
942 constraint_type =
"PRIMARY KEY";
943 else if (
stmt->unique)
944 constraint_type =
"UNIQUE";
945 else if (
stmt->excludeOpNames !=
NIL)
946 constraint_type =
"EXCLUDE";
950 constraint_type = NULL;
957 for (
i = 0;
i <
key->partnatts;
i++)
976 key->partopcintype[
i],
977 key->partopcintype[
i],
980 elog(
ERROR,
"missing operator %d(%u,%u) in partition opfamily %u",
981 eq_strategy,
key->partopcintype[
i],
key->partopcintype[
i],
982 key->partopfamily[
i]);
990 if (accessMethodId == BTREE_AM_OID)
994 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
995 errmsg(
"cannot match partition key to an index using access method \"%s\"",
1002 if (
key->partattrs[
i] == 0)
1004 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1005 errmsg(
"unsupported %s constraint with partition key definition",
1007 errdetail(
"%s constraints cannot be used when partition keys include expressions.",
1029 if (ptkey_eqop == idx_eqop)
1043 key->partattrs[
i] - 1);
1045 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1046 errmsg(
"unique constraint on partitioned table must include all partitioning columns"),
1047 errdetail(
"%s constraint on table \"%s\" lacks column \"%s\" which is part of the partition key.",
1065 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1066 errmsg(
"index creation on system columns is not supported")));
1084 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1085 errmsg(
"index creation on system columns is not supported")));
1097 if (
stmt->isconstraint && !quiet)
1099 const char *constraint_type;
1102 constraint_type =
"PRIMARY KEY";
1103 else if (
stmt->unique)
1104 constraint_type =
"UNIQUE";
1105 else if (
stmt->excludeOpNames !=
NIL)
1106 constraint_type =
"EXCLUDE";
1110 constraint_type = NULL;
1114 (
errmsg_internal(
"%s %s will create implicit index \"%s\" for table \"%s\"",
1115 is_alter_table ?
"ALTER TABLE / ADD" :
"CREATE TABLE /",
1132 flags = constr_flags = 0;
1133 if (
stmt->isconstraint)
1135 if (skip_build || concurrent || partitioned)
1137 if (
stmt->if_not_exists)
1150 if (partitioned &&
stmt->relation && !
stmt->relation->inh)
1158 if (
stmt->deferrable)
1160 if (
stmt->initdeferred)
1164 index_create(rel, indexRelationName, indexRelationId, parentIndexId,
1166 stmt->oldNumber, indexInfo, indexColNames,
1167 accessMethodId, tablespaceId,
1168 collationObjectId, classObjectId,
1169 coloptions, reloptions,
1170 flags, constr_flags,
1172 &createdConstraintId);
1205 if (
stmt->idxcomment != NULL)
1220 if ((!
stmt->relation ||
stmt->relation->inh) && partdesc->
nparts > 0)
1222 int nparts = partdesc->
nparts;
1224 bool invalidate_parent =
false;
1247 if (total_parts < 0)
1261 memcpy(part_oids, partdesc->
oids,
sizeof(
Oid) * nparts);
1271 parentIndex =
index_open(indexRelationId, lockmode);
1284 for (
int i = 0;
i < nparts;
i++)
1286 Oid childRelid = part_oids[
i];
1288 Oid child_save_userid;
1289 int child_save_sec_context;
1290 int child_save_nestlevel;
1299 &child_save_sec_context);
1309 if (childrel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1313 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1314 errmsg(
"cannot create unique index on partitioned table \"%s\"",
1316 errdetail(
"Table \"%s\" contains partitions that are foreign tables.",
1321 child_save_sec_context);
1332 foreach(cell, childidxs)
1378 createdConstraintId,
1382 invalidate_parent =
true;
1408 child_save_sec_context);
1417 bool found_whole_row;
1454 if (found_whole_row)
1455 elog(
ERROR,
"cannot convert whole-row table reference");
1462 if (found_whole_row)
1463 elog(
ERROR,
"cannot convert whole-row table reference");
1471 root_save_sec_context);
1475 createdConstraintId,
1477 is_alter_table, check_rights, check_not_in_use,
1480 child_save_sec_context);
1493 if (invalidate_parent)
1502 elog(
ERROR,
"cache lookup failed for index %u",
1592 const int progress_cols[] = {
1596 const int64 progress_vals[] = {
1699 limitXmin = snapshot->
xmin;
1810 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1811 errmsg(
"functions in index predicate must be marked IMMUTABLE")));
1830 List *exclusionOpNames,
1832 const char *accessMethodName,
1837 int ddl_sec_context,
1838 int *ddl_save_nestlevel)
1845 int save_sec_context;
1848 if (exclusionOpNames)
1854 nextExclOp =
list_head(exclusionOpNames);
1866 foreach(lc, attList)
1875 if (attribute->
name != NULL)
1888 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1889 errmsg(
"column \"%s\" named in key does not exist",
1893 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1894 errmsg(
"column \"%s\" does not exist",
1899 atttype = attform->atttypid;
1900 attcollation = attform->attcollation;
1910 if (attn >= nkeycols)
1912 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1913 errmsg(
"expressions are not supported in included columns")));
1953 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1954 errmsg(
"functions in index expression must be marked IMMUTABLE")));
1958 typeOidP[attn] = atttype;
1964 if (attn >= nkeycols)
1968 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1969 errmsg(
"including column does not support a collation")));
1972 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1973 errmsg(
"including column does not support an operator class")));
1976 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1977 errmsg(
"including column does not support ASC/DESC options")));
1980 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1981 errmsg(
"including column does not support NULLS FIRST/LAST options")));
1984 colOptionP[attn] = 0;
2021 (
errcode(ERRCODE_INDETERMINATE_COLLATION),
2022 errmsg(
"could not determine which collation to use for index expression"),
2023 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
2029 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2030 errmsg(
"collations are not supported by type %s",
2034 collationOidP[attn] = attcollation;
2094 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2095 errmsg(
"operator %s is not commutative",
2097 errdetail(
"Only commutative operators can be used in exclusion constraints.")));
2117 elog(
ERROR,
"cache lookup failed for opfamily %u",
2122 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2123 errmsg(
"operator %s is not a member of operator family \"%s\"",
2126 errdetail(
"The exclusion operator must be related to the index operator class for the constraint.")));
2132 nextExclOp =
lnext(exclusionOpNames, nextExclOp);
2140 colOptionP[attn] = 0;
2145 colOptionP[attn] |= INDOPTION_DESC;
2150 colOptionP[attn] |= INDOPTION_NULLS_FIRST;
2153 colOptionP[attn] |= INDOPTION_NULLS_FIRST;
2160 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2161 errmsg(
"access method \"%s\" does not support ASC/DESC options",
2162 accessMethodName)));
2165 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2166 errmsg(
"access method \"%s\" does not support NULLS FIRST/LAST options",
2167 accessMethodName)));
2181 NULL, NULL,
false,
false);
2196 const char *accessMethodName,
Oid accessMethodId)
2211 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2212 errmsg(
"data type %s has no default operator class for access method \"%s\"",
2214 errhint(
"You must specify an operator class for the index or define a default operator class for the data type.")));
2242 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2243 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2244 opcname, accessMethodName)));
2250 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2251 errmsg(
"operator class \"%s\" does not exist for access method \"%s\"",
2259 opClassId = opform->oid;
2260 opInputType = opform->opcintype;
2264 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2265 errmsg(
"operator class \"%s\" does not accept data type %s",
2284 int ncompatible = 0;
2285 int ncompatiblepreferred = 0;
2312 Anum_pg_opclass_opcmethod,
2324 if (!opclass->opcdefault)
2326 if (opclass->opcintype == type_id)
2329 result = opclass->oid;
2331 else if (nexact == 0 &&
2336 ncompatiblepreferred++;
2337 result = opclass->oid;
2339 else if (ncompatiblepreferred == 0)
2342 result = opclass->oid;
2355 errmsg(
"there are multiple default operator classes for data type %s",
2359 ncompatiblepreferred == 1 ||
2360 (ncompatiblepreferred == 0 && ncompatible == 1))
2398 name1chars = strlen(name1);
2401 name2chars = strlen(name2);
2407 overhead += strlen(
label) + 1;
2417 while (name1chars + name2chars > availchars)
2419 if (name1chars > name2chars)
2425 name1chars =
pg_mbcliplen(name1, name1chars, name1chars);
2427 name2chars =
pg_mbcliplen(name2, name2chars, name2chars);
2430 name =
palloc(name1chars + name2chars + overhead + 1);
2431 memcpy(
name, name1, name1chars);
2436 memcpy(
name + ndx, name2, name2chars);
2476 const char *
label,
Oid namespaceid,
2492 if (!isconstraint ||
2499 snprintf(modlabel,
sizeof(modlabel),
"%s%d",
label, ++pass);
2512 List *colnames,
List *exclusionOpNames,
2513 bool primary,
bool isconstraint)
2526 else if (exclusionOpNames !=
NIL)
2534 else if (isconstraint)
2573 foreach(lc, colnames)
2575 const char *
name = (
const char *)
lfirst(lc);
2578 buf[buflen++] =
'_';
2585 buflen += strlen(
buf + buflen);
2605 foreach(lc, indexElems)
2608 const char *origname;
2609 const char *curname;
2616 else if (ielem->
name)
2617 origname = ielem->
name;
2629 foreach(lc2, result)
2631 if (strcmp(curname, (
char *)
lfirst(lc2)) == 0)
2642 memcpy(
buf, origname, nlen);
2643 strcpy(
buf + nlen, nbuf);
2665 bool concurrently =
false;
2667 char *tablespacename = NULL;
2670 foreach(lc,
stmt->params)
2674 if (strcmp(opt->
defname,
"verbose") == 0)
2676 else if (strcmp(opt->
defname,
"concurrently") == 0)
2678 else if (strcmp(opt->
defname,
"tablespace") == 0)
2682 (
errcode(ERRCODE_SYNTAX_ERROR),
2683 errmsg(
"unrecognized REINDEX option \"%s\"",
2690 "REINDEX CONCURRENTLY");
2700 if (tablespacename != NULL)
2741 "REINDEX DATABASE");
2745 elog(
ERROR,
"unrecognized object type: %d",
2789 if (relkind == RELKIND_PARTITIONED_INDEX)
2792 persistence != RELPERSISTENCE_TEMP)
2830 if (relId != oldRelId &&
OidIsValid(oldRelId))
2848 if (relkind != RELKIND_INDEX &&
2849 relkind != RELKIND_PARTITIONED_INDEX)
2851 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2863 if (relId != oldRelId)
2872 state->locked_table_oid = table_oid;
2910 (
errmsg(
"table \"%s\" has no indexes that can be reindexed concurrently",
2924 (
errmsg(
"table \"%s\" has no indexes to reindex",
2952 bool concurrent_warning =
false;
2953 bool tablespace_warning =
false;
2968 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2969 errmsg(
"cannot reindex system catalogs concurrently")));
2992 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2993 errmsg(
"can only reindex the currently open database")));
3007 "ReindexMultipleTables",
3019 Anum_pg_class_relnamespace,
3037 Oid relid = classtuple->oid;
3046 if (classtuple->relkind != RELKIND_RELATION &&
3047 classtuple->relkind != RELKIND_MATVIEW)
3051 if (classtuple->relpersistence == RELPERSISTENCE_TEMP &&
3075 if (classtuple->relisshared &&
3087 if (!concurrent_warning)
3089 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3090 errmsg(
"cannot reindex system catalogs concurrently, skipping all")));
3091 concurrent_warning =
true;
3101 bool skip_rel =
false;
3107 if (RELKIND_HAS_STORAGE(classtuple->relkind) &&
3120 if (!tablespace_warning)
3122 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
3123 errmsg(
"cannot move system relations, skipping all")));
3124 tablespace_warning =
true;
3139 if (relid == RelationRelationId)
3168 if (errinfo->
relkind == RELKIND_PARTITIONED_TABLE)
3169 errcontext(
"while reindexing partitioned table \"%s.%s\"",
3171 else if (errinfo->
relkind == RELKIND_PARTITIONED_INDEX)
3172 errcontext(
"while reindexing partitioned index \"%s.%s\"",
3195 Assert(RELKIND_HAS_PARTITIONS(relkind));
3205 errcallback.
arg = (
void *) &errinfo;
3210 relkind == RELKIND_PARTITIONED_TABLE ?
3211 "REINDEX TABLE" :
"REINDEX INDEX");
3233 foreach(lc, inhoids)
3243 if (!RELKIND_HAS_STORAGE(partkind))
3246 Assert(partkind == RELKIND_INDEX ||
3247 partkind == RELKIND_RELATION);
3288 char relpersistence;
3328 Assert(!RELKIND_HAS_PARTITIONS(relkind));
3331 relpersistence != RELPERSISTENCE_TEMP)
3339 else if (relkind == RELKIND_INDEX)
3363 (
errmsg(
"table \"%s.%s\" was reindexed",
3403 typedef struct ReindexIndexInfo
3420 char *relationName = NULL;
3421 char *relationNamespace = NULL;
3423 const int progress_index[] = {
3429 int64 progress_vals[4];
3438 "ReindexConcurrent",
3462 case RELKIND_RELATION:
3463 case RELKIND_MATVIEW:
3464 case RELKIND_TOASTVALUE:
3476 heapRelationIds =
lappend_oid(heapRelationIds, relationOid);
3482 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3483 errmsg(
"cannot reindex system catalogs concurrently")));
3501 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3502 errmsg(
"cannot move system relation \"%s\"",
3512 if (!indexRelation->
rd_index->indisvalid)
3514 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3515 errmsg(
"cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3518 else if (indexRelation->
rd_index->indisexclusion)
3520 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3521 errmsg(
"cannot reindex exclusion constraint index \"%s.%s\" concurrently, skipping",
3526 ReindexIndexInfo *
idx;
3532 idx->indexId = cellOid;
3546 Oid toastOid = heapRelation->
rd_rel->reltoastrelid;
3554 heapRelationIds =
lappend_oid(heapRelationIds, toastOid);
3564 if (!indexRelation->
rd_index->indisvalid)
3566 (
errcode(ERRCODE_INDEX_CORRUPTED),
3567 errmsg(
"cannot reindex invalid index \"%s.%s\" concurrently, skipping",
3572 ReindexIndexInfo *
idx;
3581 idx->indexId = cellOid;
3602 ReindexIndexInfo *
idx;
3610 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3611 errmsg(
"cannot reindex system catalogs concurrently")));
3621 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3622 errmsg(
"cannot reindex invalid index on TOAST table")));
3645 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3646 errmsg(
"cannot move system relation \"%s\"",
3662 idx->indexId = relationOid;
3670 case RELKIND_PARTITIONED_TABLE:
3671 case RELKIND_PARTITIONED_INDEX:
3675 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3676 errmsg(
"cannot reindex this type of relation concurrently")));
3687 if (indexIds ==
NIL)
3696 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3697 errmsg(
"cannot move non-shared relation to tablespace \"%s\"",
3727 foreach(lc, indexIds)
3729 char *concurrentName;
3731 ReindexIndexInfo *newidx;
3736 int save_sec_context;
3763 if (indexRel->
rd_rel->relpersistence == RELPERSISTENCE_TEMP)
3764 elog(
ERROR,
"cannot reindex a temporary table concurrently");
3770 progress_vals[1] = 0;
3771 progress_vals[2] =
idx->indexId;
3772 progress_vals[3] =
idx->amId;
3784 heapRel->
rd_rel->relkind != RELKIND_TOASTVALUE)
3787 tablespaceid = indexRel->
rd_rel->reltablespace;
3807 newidx->indexId = newIndexId;
3808 newidx->safe =
idx->safe;
3809 newidx->tableId =
idx->tableId;
3810 newidx->amId =
idx->amId;
3812 newIndexIds =
lappend(newIndexIds, newidx);
3822 relationLocks =
lappend(relationLocks, lockrelid);
3825 relationLocks =
lappend(relationLocks, lockrelid);
3845 foreach(lc, heapRelationIds)
3857 relationLocks =
lappend(relationLocks, lockrelid);
3863 lockTags =
lappend(lockTags, heaplocktag);
3872 foreach(lc, relationLocks)
3903 foreach(lc, newIndexIds)
3905 ReindexIndexInfo *newidx =
lfirst(lc);
3931 progress_vals[2] = newidx->indexId;
3932 progress_vals[3] = newidx->amId;
3962 foreach(lc, newIndexIds)
3964 ReindexIndexInfo *newidx =
lfirst(lc);
3996 progress_vals[2] = newidx->indexId;
3997 progress_vals[3] = newidx->amId;
4006 limitXmin = snapshot->
xmin;
4055 forboth(lc, indexIds, lc2, newIndexIds)
4057 ReindexIndexInfo *oldidx =
lfirst(lc);
4058 ReindexIndexInfo *newidx =
lfirst(lc2);
4120 foreach(lc, indexIds)
4122 ReindexIndexInfo *oldidx =
lfirst(lc);
4159 foreach(lc, indexIds)
4164 object.
classId = RelationRelationId;
4165 object.objectId =
idx->indexId;
4166 object.objectSubId = 0;
4185 foreach(lc, relationLocks)
4198 if (relkind == RELKIND_INDEX)
4200 (
errmsg(
"index \"%s.%s\" was reindexed",
4201 relationNamespace, relationName),
4206 foreach(lc, newIndexIds)
4209 Oid indOid =
idx->indexId;
4212 (
errmsg(
"index \"%s.%s\" was reindexed",
4219 (
errmsg(
"table \"%s.%s\" was reindexed",
4220 relationNamespace, relationName),
4250 Assert(partitionIdx->
rd_rel->relkind == RELKIND_INDEX ||
4251 partitionIdx->
rd_rel->relkind == RELKIND_PARTITIONED_INDEX);
4258 Anum_pg_inherits_inhrelid,
4262 Anum_pg_inherits_inhseqno,
4304 if (inhForm->inhparent != parentOid)
4307 elog(
ERROR,
"bogus pg_inherit row: inhrelid %u inhparent %u",
4308 inhForm->inhrelid, inhForm->inhparent);
4377 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 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(Node *clause)
char * get_database_name(Oid dbid)
elog(ERROR, "%s: %s", p2, msg)
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,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_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 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)
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrMap *attmap)
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, Oid tableSpaceId, Oid *collationObjectId, Oid *classObjectId, int16 *coloptions, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
void reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, ReindexParams *params)
bool reindex_relation(Oid relid, int flags, ReindexParams *params)
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
IndexInfo * BuildIndexInfo(Relation index)
#define INDEX_CREATE_IS_PRIMARY
#define INDEX_CREATE_IF_NOT_EXISTS
#define REINDEX_REL_PROCESS_TOAST
#define INDEX_CREATE_PARTITIONED
#define REINDEXOPT_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)
char * makeObjectName(const char *name1, const char *name2, const char *label)
void ExecReindex(ParseState *pstate, ReindexStmt *stmt, bool isTopLevel)
static void set_indexsafe_procflags(void)
static bool ReindexRelationConcurrently(Oid relationOid, ReindexParams *params)
static void reindex_error_callback(void *arg)
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
static char * ChooseIndexName(const char *tabname, Oid namespaceId, List *colnames, List *exclusionOpNames, bool primary, bool isconstraint)
static void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, ReindexParams *params)
static bool CompareOpclassOptions(Datum *opts1, Datum *opts2, int natts)
bool CheckIndexCompatible(Oid oldId, const char *accessMethodName, List *attributeList, List *exclusionOpNames)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
static void ReindexIndex(RangeVar *indexRelation, ReindexParams *params, bool isTopLevel)
ObjectAddress DefineIndex(Oid relationId, 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 bool CheckMutability(Expr *expr)
static void update_relispartition(Oid relationId, bool newval)
static void ReindexMultipleInternal(List *relids, ReindexParams *params)
Oid ResolveOpClass(List *opclass, Oid attrType, const char *accessMethodName, Oid accessMethodId)
void WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
static void ReindexPartitions(Oid relid, ReindexParams *params, bool isTopLevel)
struct ReindexErrorInfo ReindexErrorInfo
static Oid ReindexTable(RangeVar *relation, ReindexParams *params, bool isTopLevel)
static void CheckPredicate(Expr *predicate)
static void RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
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, Oid ddl_userid, int ddl_sec_context, int *ddl_save_nestlevel)
static List * ChooseIndexColumnNames(List *indexElems)
static char * ChooseIndexNameAddition(List *colnames)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
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)
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)
void DeconstructQualifiedName(List *names, char **nspname_p, char **objname_p)
bool isTempNamespace(Oid namespaceId)
Oid get_collation_oid(List *collname, bool missing_ok)
Oid get_namespace_oid(const char *nspname, bool missing_ok)
char * NameListToString(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_)
#define ObjectAddressSet(addr, class_id, object_id)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
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)
Expr * expression_planner(Expr *expr)
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
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
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)
Datum * RelationGetIndexRawAttOptions(Relation indexrel)
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)
PGPROC * BackendIdGetProc(int backendID)
Snapshot GetTransactionSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
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
Datum * ii_OpclassOptions
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)
bool has_partition_ancestor_privs(Oid relid, Oid userid, AclMode acl)
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)