77 #include "utils/fmgroids.h" 110 bool is_validated,
bool is_local,
int inhcount,
111 bool is_no_inherit,
bool is_internal);
115 bool allow_merge,
bool is_local,
116 bool is_initially_valid,
120 Node *raw_constraint,
150 false,
'p',
's',
true,
false,
false,
'\0',
false,
true, 0
154 0, {
"oid"}, OIDOID, 0,
sizeof(
Oid),
156 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
162 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
166 0, {
"cmin"}, CIDOID, 0,
sizeof(
CommandId),
168 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
174 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
178 0, {
"cmax"}, CIDOID, 0,
sizeof(
CommandId),
180 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
190 0, {
"tableoid"}, OIDOID, 0,
sizeof(
Oid),
192 true,
'p',
'i',
true,
false,
false,
'\0',
false,
true, 0
206 elog(
ERROR,
"invalid system attribute number %d", attno);
208 elog(
ERROR,
"invalid system attribute number %d", attno);
209 return SysAtt[-attno - 1];
227 if (strcmp(
NameStr(att->attname), attname) == 0)
261 bool shared_relation,
262 bool mapped_relation,
263 bool allow_system_table_mods)
280 if (!allow_system_table_mods &&
285 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
286 errmsg(
"permission denied to create \"%s.%s\"",
288 errdetail(
"System catalog modifications are currently disallowed.")));
297 case RELKIND_COMPOSITE_TYPE:
298 case RELKIND_FOREIGN_TABLE:
299 case RELKIND_PARTITIONED_TABLE:
300 case RELKIND_PARTITIONED_INDEX:
301 create_storage =
false;
309 case RELKIND_SEQUENCE:
310 create_storage =
true;
319 create_storage =
true;
329 create_storage =
false;
415 bool allow_system_table_mods)
419 int natts = tupdesc->
natts;
424 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
425 errmsg(
"tables can have at most %d columns",
426 MaxHeapAttributeNumber)));
434 if (relkind != RELKIND_VIEW && relkind != RELKIND_COMPOSITE_TYPE)
436 for (i = 0; i < natts; i++)
443 (
errcode(ERRCODE_DUPLICATE_COLUMN),
444 errmsg(
"column name \"%s\" conflicts with a system column name",
452 for (i = 1; i < natts; i++)
454 for (j = 0; j <
i; j++)
459 (
errcode(ERRCODE_DUPLICATE_COLUMN),
460 errmsg(
"column name \"%s\" specified more than once",
468 for (i = 0; i < natts; i++)
474 allow_system_table_mods);
496 List *containing_rowtypes,
497 bool allow_system_table_mods)
502 if (att_typtype == TYPTYPE_PSEUDO)
510 if (atttypid != ANYARRAYOID || !allow_system_table_mods)
512 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
513 errmsg(
"column \"%s\" has pseudo-type %s",
516 else if (att_typtype == TYPTYPE_DOMAIN)
523 allow_system_table_mods);
525 else if (att_typtype == TYPTYPE_COMPOSITE)
542 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
543 errmsg(
"composite type %s cannot be made a member of itself",
546 containing_rowtypes =
lcons_oid(atttypid, containing_rowtypes);
552 for (i = 0; i < tupdesc->
natts; i++)
556 if (attr->attisdropped)
559 attr->atttypid, attr->attcollation,
561 allow_system_table_mods);
575 allow_system_table_mods);
584 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
585 errmsg(
"no collation was derived for column \"%s\" with collatable type %s",
587 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
609 bool nulls[Natts_pg_attribute];
613 memset(values, 0,
sizeof(values));
614 memset(nulls,
false,
sizeof(nulls));
616 values[Anum_pg_attribute_attrelid - 1] =
ObjectIdGetDatum(new_attribute->attrelid);
617 values[Anum_pg_attribute_attname - 1] =
NameGetDatum(&new_attribute->attname);
618 values[Anum_pg_attribute_atttypid - 1] =
ObjectIdGetDatum(new_attribute->atttypid);
619 values[Anum_pg_attribute_attstattarget - 1] =
Int32GetDatum(new_attribute->attstattarget);
620 values[Anum_pg_attribute_attlen - 1] =
Int16GetDatum(new_attribute->attlen);
621 values[Anum_pg_attribute_attnum - 1] =
Int16GetDatum(new_attribute->attnum);
622 values[Anum_pg_attribute_attndims - 1] =
Int32GetDatum(new_attribute->attndims);
623 values[Anum_pg_attribute_attcacheoff - 1] =
Int32GetDatum(new_attribute->attcacheoff);
624 values[Anum_pg_attribute_atttypmod - 1] =
Int32GetDatum(new_attribute->atttypmod);
625 values[Anum_pg_attribute_attbyval - 1] =
BoolGetDatum(new_attribute->attbyval);
626 values[Anum_pg_attribute_attstorage - 1] =
CharGetDatum(new_attribute->attstorage);
627 values[Anum_pg_attribute_attalign - 1] =
CharGetDatum(new_attribute->attalign);
628 values[Anum_pg_attribute_attnotnull - 1] =
BoolGetDatum(new_attribute->attnotnull);
629 values[Anum_pg_attribute_atthasdef - 1] =
BoolGetDatum(new_attribute->atthasdef);
630 values[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(new_attribute->atthasmissing);
631 values[Anum_pg_attribute_attidentity - 1] =
CharGetDatum(new_attribute->attidentity);
632 values[Anum_pg_attribute_attisdropped - 1] =
BoolGetDatum(new_attribute->attisdropped);
633 values[Anum_pg_attribute_attislocal - 1] =
BoolGetDatum(new_attribute->attislocal);
634 values[Anum_pg_attribute_attinhcount - 1] =
Int32GetDatum(new_attribute->attinhcount);
635 values[Anum_pg_attribute_attcollation - 1] =
ObjectIdGetDatum(new_attribute->attcollation);
638 nulls[Anum_pg_attribute_attacl - 1] =
true;
639 nulls[Anum_pg_attribute_attoptions - 1] =
true;
640 nulls[Anum_pg_attribute_attfdwoptions - 1] =
true;
641 nulls[Anum_pg_attribute_attmissingval - 1] =
true;
646 if (indstate != NULL)
672 int natts = tupdesc->
natts;
687 for (i = 0; i < natts; i++)
691 attr->attrelid = new_rel_oid;
693 attr->attstattarget = -1;
694 attr->attcacheoff = -1;
699 myself.
classId = RelationRelationId;
702 referenced.
classId = TypeRelationId;
703 referenced.
objectId = attr->atttypid;
709 attr->attcollation != DEFAULT_COLLATION_OID)
711 referenced.
classId = CollationRelationId;
712 referenced.
objectId = attr->attcollation;
723 if (relkind != RELKIND_VIEW && relkind != RELKIND_COMPOSITE_TYPE)
737 attStruct.attrelid = new_rel_oid;
742 attStruct.attislocal = oidislocal;
743 attStruct.attinhcount = oidinhcount;
780 bool nulls[Natts_pg_class];
784 memset(values, 0,
sizeof(values));
785 memset(nulls,
false,
sizeof(nulls));
787 values[Anum_pg_class_relname - 1] =
NameGetDatum(&rd_rel->relname);
788 values[Anum_pg_class_relnamespace - 1] =
ObjectIdGetDatum(rd_rel->relnamespace);
793 values[Anum_pg_class_relfilenode - 1] =
ObjectIdGetDatum(rd_rel->relfilenode);
794 values[Anum_pg_class_reltablespace - 1] =
ObjectIdGetDatum(rd_rel->reltablespace);
795 values[Anum_pg_class_relpages - 1] =
Int32GetDatum(rd_rel->relpages);
796 values[Anum_pg_class_reltuples - 1] =
Float4GetDatum(rd_rel->reltuples);
797 values[Anum_pg_class_relallvisible - 1] =
Int32GetDatum(rd_rel->relallvisible);
798 values[Anum_pg_class_reltoastrelid - 1] =
ObjectIdGetDatum(rd_rel->reltoastrelid);
799 values[Anum_pg_class_relhasindex - 1] =
BoolGetDatum(rd_rel->relhasindex);
800 values[Anum_pg_class_relisshared - 1] =
BoolGetDatum(rd_rel->relisshared);
801 values[Anum_pg_class_relpersistence - 1] =
CharGetDatum(rd_rel->relpersistence);
802 values[Anum_pg_class_relkind - 1] =
CharGetDatum(rd_rel->relkind);
803 values[Anum_pg_class_relnatts - 1] =
Int16GetDatum(rd_rel->relnatts);
804 values[Anum_pg_class_relchecks - 1] =
Int16GetDatum(rd_rel->relchecks);
805 values[Anum_pg_class_relhasoids - 1] =
BoolGetDatum(rd_rel->relhasoids);
806 values[Anum_pg_class_relhasrules - 1] =
BoolGetDatum(rd_rel->relhasrules);
807 values[Anum_pg_class_relhastriggers - 1] =
BoolGetDatum(rd_rel->relhastriggers);
808 values[Anum_pg_class_relrowsecurity - 1] =
BoolGetDatum(rd_rel->relrowsecurity);
809 values[Anum_pg_class_relforcerowsecurity - 1] =
BoolGetDatum(rd_rel->relforcerowsecurity);
810 values[Anum_pg_class_relhassubclass - 1] =
BoolGetDatum(rd_rel->relhassubclass);
811 values[Anum_pg_class_relispopulated - 1] =
BoolGetDatum(rd_rel->relispopulated);
812 values[Anum_pg_class_relreplident - 1] =
CharGetDatum(rd_rel->relreplident);
813 values[Anum_pg_class_relispartition - 1] =
BoolGetDatum(rd_rel->relispartition);
814 values[Anum_pg_class_relrewrite - 1] =
ObjectIdGetDatum(rd_rel->relrewrite);
817 if (relacl != (
Datum) 0)
818 values[Anum_pg_class_relacl - 1] = relacl;
820 nulls[Anum_pg_class_relacl - 1] =
true;
821 if (reloptions != (
Datum) 0)
822 values[Anum_pg_class_reloptions - 1] = reloptions;
824 nulls[Anum_pg_class_reloptions - 1] =
true;
827 nulls[Anum_pg_class_relpartbound - 1] =
true;
867 new_rel_reltup = new_rel_desc->
rd_rel;
871 case RELKIND_RELATION:
872 case RELKIND_MATVIEW:
874 case RELKIND_TOASTVALUE:
876 new_rel_reltup->relpages = 0;
877 new_rel_reltup->reltuples = 0;
878 new_rel_reltup->relallvisible = 0;
880 case RELKIND_SEQUENCE:
882 new_rel_reltup->relpages = 1;
883 new_rel_reltup->reltuples = 1;
884 new_rel_reltup->relallvisible = 0;
888 new_rel_reltup->relpages = 0;
889 new_rel_reltup->reltuples = 0;
890 new_rel_reltup->relallvisible = 0;
895 if (relkind == RELKIND_RELATION ||
896 relkind == RELKIND_MATVIEW ||
897 relkind == RELKIND_TOASTVALUE)
928 new_rel_reltup->relowner =
relowner;
929 new_rel_reltup->reltype = new_type_oid;
933 new_rel_reltup->relispartition =
false;
967 TYPCATEGORY_COMPOSITE,
1035 List *cooked_constraints,
1038 bool shared_relation,
1039 bool mapped_relation,
1045 bool allow_system_table_mods,
1075 (
errcode(ERRCODE_DUPLICATE_TABLE),
1076 errmsg(
"relation \"%s\" already exists", relname)));
1092 errmsg(
"type \"%s\" already exists", relname),
1093 errhint(
"A relation has an associated type of the same name, " 1094 "so you must use a name that doesn't conflict " 1095 "with any existing type.")));
1101 if (shared_relation && reltablespace != GLOBALTABLESPACE_OID)
1102 elog(
ERROR,
"shared relations must be placed in pg_global tablespace");
1114 (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
1115 relkind == RELKIND_VIEW || relkind == RELKIND_MATVIEW ||
1116 relkind == RELKIND_COMPOSITE_TYPE || relkind == RELKIND_FOREIGN_TABLE ||
1117 relkind == RELKIND_PARTITIONED_TABLE))
1121 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1122 errmsg(
"pg_class heap OID value not set when in binary upgrade mode")));
1130 relkind == RELKIND_TOASTVALUE)
1147 case RELKIND_RELATION:
1149 case RELKIND_MATVIEW:
1150 case RELKIND_FOREIGN_TABLE:
1151 case RELKIND_PARTITIONED_TABLE:
1155 case RELKIND_SEQUENCE:
1182 allow_system_table_mods);
1195 relkind == RELKIND_VIEW ||
1196 relkind == RELKIND_MATVIEW ||
1197 relkind == RELKIND_FOREIGN_TABLE ||
1198 relkind == RELKIND_COMPOSITE_TYPE ||
1199 relkind == RELKIND_PARTITIONED_TABLE))
1219 new_type_oid = new_type_addr.
objectId;
1221 *typaddress = new_type_addr;
1264 pfree(relarrayname);
1288 oidislocal, oidinhcount);
1305 if (relkind != RELKIND_COMPOSITE_TYPE &&
1306 relkind != RELKIND_TOASTVALUE &&
1312 myself.
classId = RelationRelationId;
1315 referenced.
classId = NamespaceRelationId;
1326 referenced.
classId = TypeRelationId;
1337 nnewmembers =
aclmembers(relacl, &newmembers);
1341 nnewmembers, newmembers);
1367 if (relpersistence == RELPERSISTENCE_UNLOGGED &&
1368 relkind != RELKIND_PARTITIONED_TABLE)
1394 rel->
rd_rel->relkind == RELKIND_MATVIEW ||
1395 rel->
rd_rel->relkind == RELKIND_TOASTVALUE);
1422 Anum_pg_inherits_inhrelid,
1455 elog(
ERROR,
"cache lookup failed for relation %u", relid);
1486 Anum_pg_attribute_attrelid,
1523 Anum_pg_attribute_attrelid,
1527 Anum_pg_attribute_attnum,
1575 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1590 attStruct->attisdropped =
true;
1604 attStruct->attnotnull =
false;
1607 attStruct->attstattarget = 0;
1612 snprintf(newattname,
sizeof(newattname),
1613 "........pg.dropped.%d........", attnum);
1614 namestrcpy(&(attStruct->attname), newattname);
1652 Anum_pg_attrdef_adrelid,
1656 Anum_pg_attrdef_adnum,
1668 object.
classId = AttrDefaultRelationId;
1670 object.objectSubId = 0;
1681 if (complain && !found)
1682 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
1719 elog(
ERROR,
"could not find tuple for attrdef %u", attrdefId);
1740 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1786 elog(
ERROR,
"cache lookup failed for relation %u", relid);
1797 if (
OidIsValid(defaultPartOid) && relid != defaultPartOid)
1826 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
1835 elog(
ERROR,
"cache lookup failed for foreign table %u", relid);
1846 if (rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1853 if (relid == defaultPartOid)
1859 if (rel->
rd_rel->relkind != RELKIND_VIEW &&
1860 rel->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1861 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1862 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1920 if (
OidIsValid(defaultPartOid) && relid != defaultPartOid)
1950 Datum repl_val[Natts_pg_attribute];
1951 bool repl_null[Natts_pg_attribute];
1952 bool repl_repl[Natts_pg_attribute];
1957 memset(repl_val, 0,
sizeof(repl_val));
1958 memset(repl_null,
false,
sizeof(repl_null));
1959 memset(repl_repl,
false,
sizeof(repl_repl));
1961 repl_val[Anum_pg_attribute_atthasmissing - 1] =
BoolGetDatum(
false);
1962 repl_null[Anum_pg_attribute_attmissingval - 1] =
true;
1964 repl_repl[Anum_pg_attribute_atthasmissing - 1] =
true;
1965 repl_repl[Anum_pg_attribute_attmissingval - 1] =
true;
1972 for (attnum = 1; attnum <= natts; attnum++)
1978 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1984 if (attrtuple->atthasmissing)
1987 repl_val, repl_null, repl_repl);
2017 Node *expr,
bool is_internal,
bool add_column_mode)
2024 static bool nulls[4] = {
false,
false,
false,
false};
2049 values[Anum_pg_attrdef_adnum - 1] =
attnum;
2058 defobject.
classId = AttrDefaultRelationId;
2080 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
2083 if (!attStruct->atthasdef)
2091 Datum valuesAtt[Natts_pg_attribute];
2092 bool nullsAtt[Natts_pg_attribute];
2093 bool replacesAtt[Natts_pg_attribute];
2095 bool missingIsNull =
true;
2097 MemSet(valuesAtt, 0,
sizeof(valuesAtt));
2098 MemSet(nullsAtt,
false,
sizeof(nullsAtt));
2099 MemSet(replacesAtt,
false,
sizeof(replacesAtt));
2100 valuesAtt[Anum_pg_attribute_atthasdef - 1] =
true;
2101 replacesAtt[Anum_pg_attribute_atthasdef - 1] =
true;
2103 if (add_column_mode)
2120 missingval = (
Datum) 0;
2128 defAttStruct->atttypid,
2129 defAttStruct->attlen,
2130 defAttStruct->attbyval,
2131 defAttStruct->attalign));
2134 valuesAtt[Anum_pg_attribute_atthasmissing - 1] = !missingIsNull;
2135 replacesAtt[Anum_pg_attribute_atthasmissing - 1] =
true;
2136 valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
2137 replacesAtt[Anum_pg_attribute_attmissingval - 1] =
true;
2138 nullsAtt[Anum_pg_attribute_attmissingval - 1] = missingIsNull;
2141 valuesAtt, nullsAtt, replacesAtt);
2156 colobject.
classId = RelationRelationId;
2191 bool is_validated,
bool is_local,
int inhcount,
2192 bool is_no_inherit,
bool is_internal)
2230 foreach(vl, varList)
2235 for (j = 0; j <
i; j++)
2250 if (is_no_inherit &&
2251 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2253 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2254 errmsg(
"cannot add NO INHERIT constraint to partitioned table \"%s\"",
2314 if (cooked_constraints ==
NIL)
2324 foreach(lc, cooked_constraints)
2332 is_internal,
false);
2343 elog(
ERROR,
"unrecognized constraint type: %d",
2380 List *newColDefaults,
2381 List *newConstraints,
2386 List *cookedConstraints =
NIL;
2402 oldconstr = tupleDesc->
constr;
2423 foreach(cell, newColDefaults)
2430 atp->atttypid, atp->atttypmod,
2458 cooked->
name = NULL;
2460 cooked->
expr = expr;
2463 cooked->
inhcount = is_local ? 0 : 1;
2465 cookedConstraints =
lappend(cookedConstraints, cooked);
2471 numchecks = numoldchecks;
2473 foreach(cell, newConstraints)
2514 foreach(cell2, checknames)
2516 if (strcmp((
char *)
lfirst(cell2), ccname) == 0)
2519 errmsg(
"check constraint \"%s\" already exists",
2524 checknames =
lappend(checknames, ccname);
2533 allow_merge, is_local,
2574 checknames =
lappend(checknames, ccname);
2588 cooked->
conoid = constrOid;
2589 cooked->
name = ccname;
2591 cooked->
expr = expr;
2594 cooked->
inhcount = is_local ? 0 : 1;
2596 cookedConstraints =
lappend(cookedConstraints, cooked);
2608 return cookedConstraints;
2623 bool allow_merge,
bool is_local,
2624 bool is_initially_valid,
2639 Anum_pg_constraint_conname,
2644 Anum_pg_constraint_connamespace,
2658 if (con->contype == CONSTRAINT_CHECK)
2664 Anum_pg_constraint_conbin,
2665 conDesc->
rd_att, &isnull);
2682 if (is_local && !con->conislocal && !rel->
rd_rel->relispartition)
2685 if (!found || !allow_merge)
2688 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
2692 if (con->connoinherit)
2694 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2695 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on relation \"%s\"",
2703 if (con->coninhcount > 0 && is_no_inherit)
2705 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2706 errmsg(
"constraint \"%s\" conflicts with inherited constraint on relation \"%s\"",
2713 if (is_initially_valid && !con->convalidated)
2715 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2716 errmsg(
"constraint \"%s\" conflicts with NOT VALID constraint on relation \"%s\"",
2721 (
errmsg(
"merging constraint \"%s\" with inherited definition",
2732 if (rel->
rd_rel->relispartition)
2734 con->coninhcount = 1;
2735 con->conislocal =
false;
2740 con->conislocal =
true;
2748 con->connoinherit =
true;
2782 elog(
ERROR,
"cache lookup failed for relation %u",
2786 if (relStruct->relchecks != numchecks)
2788 relStruct->relchecks = numchecks;
2823 Assert(raw_default != NULL);
2836 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2837 errmsg(
"cannot use column references in default expression")));
2855 atttypid, atttypmod,
2861 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2862 errmsg(
"column \"%s\" is of type %s" 2863 " but default expression is of type %s",
2867 errhint(
"You will need to rewrite or cast the expression.")));
2887 Node *raw_constraint,
2913 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2914 errmsg(
"only table \"%s\" can be referenced in check constraint",
2939 Anum_pg_statistic_starelid,
2948 Anum_pg_statistic_staattnum,
2999 index_build(heapRelation, currentIndex, indexInfo,
false,
true,
false);
3022 foreach(cell, relids)
3028 relations =
lappend(relations, rel);
3035 foreach(cell, relations)
3068 toastrelid = rel->
rd_rel->reltoastrelid;
3106 foreach(cell, relations)
3110 if (rel->
rd_rel->relhastriggers)
3125 if (dependents ==
NIL)
3142 foreach(cell2, dependents)
3153 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3154 errmsg(
"unsupported ON COMMIT and foreign key combination"),
3155 errdetail(
"Table \"%s\" references \"%s\", but they do not have the same ON COMMIT setting.",
3156 relname2, relname)));
3159 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3160 errmsg(
"cannot truncate a table referenced in a foreign key constraint"),
3161 errdetail(
"Table \"%s\" references \"%s\".",
3163 errhint(
"Truncate table \"%s\" at the same time, " 3164 "or use TRUNCATE ... CASCADE.",
3207 if (con->contype != CONSTRAINT_FOREIGN)
3252 if (curr == NULL || datum <
lfirst_oid(curr))
3282 Datum partexprDatum;
3286 bool nulls[Natts_pg_partitioned_table];
3290 Assert(rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
3307 partexprDatum = (
Datum) 0;
3311 MemSet(nulls,
false,
sizeof(nulls));
3315 nulls[Anum_pg_partitioned_table_partexprs - 1] =
true;
3318 values[Anum_pg_partitioned_table_partstrat - 1] =
CharGetDatum(strategy);
3319 values[Anum_pg_partitioned_table_partnatts - 1] =
Int16GetDatum(partnatts);
3321 values[Anum_pg_partitioned_table_partattrs - 1] =
PointerGetDatum(partattrs_vec);
3322 values[Anum_pg_partitioned_table_partclass - 1] =
PointerGetDatum(partopclass_vec);
3323 values[Anum_pg_partitioned_table_partcollation - 1] =
PointerGetDatum(partcollation_vec);
3324 values[Anum_pg_partitioned_table_partexprs - 1] = partexprDatum;
3332 myself.
classId = RelationRelationId;
3337 for (i = 0; i < partnatts; i++)
3339 referenced.
classId = OperatorClassRelationId;
3347 partcollation[i] != DEFAULT_COLLATION_OID)
3349 referenced.
classId = CollationRelationId;
3391 elog(
ERROR,
"cache lookup failed for partition key of relation %u",
3418 Datum new_val[Natts_pg_class];
3419 bool new_null[Natts_pg_class],
3420 new_repl[Natts_pg_class];
3428 elog(
ERROR,
"cache lookup failed for relation %u",
3431 #ifdef USE_ASSERT_CHECKING 3437 Assert(!classForm->relispartition);
3445 memset(new_val, 0,
sizeof(new_val));
3446 memset(new_null,
false,
sizeof(new_null));
3447 memset(new_repl,
false,
sizeof(new_repl));
3449 new_null[Anum_pg_class_relpartbound - 1] =
false;
3450 new_repl[Anum_pg_class_relpartbound - 1] =
true;
3452 new_val, new_null, new_repl);
#define AttributeRelidNumIndexId
HeapTuple heap_copytuple(HeapTuple tuple)
static const Form_pg_attribute SysAtt[]
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
void * stringToNode(char *str)
void register_on_commit_action(Oid relid, OnCommitAction action)
#define IsA(nodeptr, _type_)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
static void SetRelationNumChecks(Relation rel, int numchecks)
int errhint(const char *fmt,...)
Relation RelationBuildLocalRelation(const char *relname, Oid relnamespace, TupleDesc tupDesc, Oid relid, Oid relfilenode, Oid reltablespace, bool shared_relation, bool mapped_relation, char relpersistence, char relkind)
void systable_endscan(SysScanDesc sysscan)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
#define fastgetattr(tup, attnum, tupleDesc, isnull)
#define MultiXactIdGetDatum(X)
void RemoveSubscriptionRel(Oid subid, Oid relid)
void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, bool allow_system_table_mods)
void StorePartitionKey(Relation rel, char strategy, int16 partnatts, AttrNumber *partattrs, List *partexprs, Oid *partopclass, Oid *partcollation)
Oid binary_upgrade_next_heap_pg_class_oid
bool equal(const void *a, const void *b)
#define RelationGetDescr(relation)
#define ObjectIdAttributeNumber
#define RelationGetNumberOfAttributes(relation)
Oid binary_upgrade_next_toast_pg_class_oid
Oid get_element_type(Oid typid)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
struct SMgrRelationData * rd_smgr
static Node * cookConstraint(ParseState *pstate, Node *raw_constraint, char *relname)
int2vector * buildint2vector(const int16 *int2s, int n)
void heap_truncate_one_rel(Relation rel)
Expr * expression_planner(Expr *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
void update_default_partition_oid(Oid parentId, Oid defaultPartId)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Form_pg_attribute SystemAttributeByName(const char *attname, bool relhasoids)
static FormData_pg_attribute a3
#define AttrDefaultOidIndexId
void remove_on_commit_action(Oid relid)
int errcode(int sqlerrcode)
void heap_truncate_check_FKs(List *relations, bool tempTables)
char get_typtype(Oid typid)
void relation_close(Relation relation, LOCKMODE lockmode)
#define MemSet(start, val, len)
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void RelationForgetRelation(Oid rid)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
List * pull_var_clause(Node *node, int flags)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
List * lcons_oid(Oid datum, List *list)
List * list_union(const List *list1, const List *list2)
IndexInfo * BuildIndexInfo(Relation index)
bool contain_var_clause(Node *node)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
bool contain_volatile_functions(Node *clause)
#define MinCommandIdAttributeNumber
static FormData_pg_attribute a7
bool IsToastNamespace(Oid namespaceId)
void heap_freetuple(HeapTuple htup)
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isprimary, bool isreindex, bool parallel)
int namestrcpy(Name name, const char *str)
List * lappend_oid(List *list, Oid datum)
#define OidIsValid(objectId)
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
#define GetSysCacheOid2(cacheId, key1, key2)
#define BTLessEqualStrategyNumber
ParseState * make_parsestate(ParseState *parentParseState)
#define HeapTupleSetOid(tuple, oid)
Node * cookDefault(ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, const char *attname)
void assign_expr_collations(ParseState *pstate, Node *expr)
void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, Datum reloptions)
#define RelationOpenSmgr(relation)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
HeapTuple systable_getnext(SysScanDesc sysscan)
Oid get_typ_typrelid(Oid typid)
void pfree(void *pointer)
Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid reltypeid, Oid reloftypeid, Oid ownerid, TupleDesc tupdesc, List *cooked_constraints, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool oidislocal, int oidinhcount, OnCommitAction oncommit, Datum reloptions, bool use_user_acl, bool allow_system_table_mods, bool is_internal, Oid relrewrite, ObjectAddress *typaddress)
#define ObjectIdGetDatum(X)
Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, Oid relfilenode, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods)
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Oid get_partition_parent(Oid relid)
Datum Float4GetDatum(float4 X)
#define AttrDefaultIndexId
const ObjectAddress * object
Oid get_relname_relid(const char *relname, Oid relnamespace)
RelFileNodeBackend smgr_rnode
ListCell * lappend_cell_oid(List *list, ListCell *prev, Oid datum)
char * get_namespace_name(Oid nspid)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
#define IsNormalProcessingMode()
void heap_create_init_fork(Relation rel)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
List * deparse_context_for(const char *aliasname, Oid relid)
int errdetail(const char *fmt,...)
#define CStringGetDatum(X)
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
void RemoveAttributeById(Oid relid, AttrNumber attnum)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
static ObjectAddress AddNewRelationType(const char *typeName, Oid typeNamespace, Oid new_rel_oid, char new_rel_kind, Oid ownerid, Oid new_row_type, Oid new_array_type)
void CacheInvalidateRelcacheByRelid(Oid relid)
#define InvalidTransactionId
static void StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
#define RelationGetRelationName(relation)
static ListCell * list_head(const List *l)
FormData_pg_attribute * Form_pg_attribute
#define TableOidAttributeNumber
void RelationClearMissing(Relation rel)
void CheckTableNotInUse(Relation rel, const char *stmt)
void RemoveAttrDefaultById(Oid attrdefId)
#define ereport(elevel, rest)
static void AddNewAttributeTuples(Oid new_rel_oid, TupleDesc tupdesc, char relkind, bool oidislocal, int oidinhcount)
void addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
Oid get_default_partition_oid(Oid parentId)
EState * CreateExecutorState(void)
#define MaxCommandIdAttributeNumber
#define MaxTransactionIdAttributeNumber
List * lappend(List *list, void *datum)
void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, bool allow_system_table_mods)
Oid StoreAttrDefault(Relation rel, AttrNumber attnum, Node *expr, bool is_internal, bool add_column_mode)
FormData_pg_attrdef * Form_pg_attrdef
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define TextDatumGetCString(d)
#define TransactionIdGetDatum(X)
MultiXactId GetOldestMultiXactId(void)
static FormData_pg_attribute a4
void RelationDropStorage(Relation rel)
void CommandCounterIncrement(void)
void ReleaseSysCache(HeapTuple tuple)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define list_make1_oid(x1)
static bool MergeWithExistingConstraint(Relation rel, const char *ccname, Node *expr, bool allow_merge, bool is_local, bool is_initially_valid, bool is_no_inherit)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
#define InvalidMultiXactId
#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)
static FormData_pg_attribute a6
bool IsSystemNamespace(Oid namespaceId)
Form_pg_attribute SystemAttributeDefinition(AttrNumber attno, bool relhasoids)
void StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
void DeleteRelationTuple(Oid relid)
#define ConstraintNameNspIndexId
static FormData_pg_attribute a1
#define MaxHeapAttributeNumber
FormData_pg_constraint * Form_pg_constraint
bool list_member_oid(const List *list, Oid datum)
#define HeapTupleIsValid(tuple)
int aclmembers(const Acl *acl, Oid **roleids)
#define Assert(condition)
oidvector * buildoidvector(const Oid *oids, int n)
static void RelationRemoveInheritance(Oid relid)
#define StatisticRelidAttnumInhIndexId
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
struct ItemPointerData ItemPointerData
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
static List * insert_ordered_unique_oid(List *list, Oid datum)
#define InheritsRelidSeqnoIndexId
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Oid exprType(const Node *expr)
void heap_truncate(List *relids)
static int list_length(const List *l)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
RangeTblEntry * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, Alias *alias, bool inh, bool inFromCl)
void CheckTableForSerializableConflictIn(Relation relation)
void DeleteAttributeTuples(Oid relid)
List * RelationGetIndexList(Relation relation)
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool ignore_self)
Oid AssignTypeArrayOid(void)
void index_close(Relation relation, LOCKMODE lockmode)
static void AddNewRelationTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Oid new_type_oid, Oid reloftype, Oid relowner, char relkind, Datum relacl, Datum reloptions)
#define DatumGetPointer(X)
void CacheInvalidateRelcache(Relation relation)
void RemoveStatistics(Oid relid, AttrNumber attnum)
static Datum values[MAXATTR]
#define IsBootstrapProcessingMode()
FormData_pg_class * Form_pg_class
#define SearchSysCacheCopy1(cacheId, key1)
#define AccessExclusiveLock
void InsertPgAttributeTuple(Relation pg_attribute_rel, Form_pg_attribute new_attribute, CatalogIndexState indstate)
void RemovePartitionKeyByRelId(Oid relid)
int errmsg(const char *fmt,...)
ObjectAddress TypeCreate(Oid newTypeOid, const char *typeName, Oid typeNamespace, Oid relationOid, char relationKind, Oid ownerId, int16 internalSize, char typeType, char typeCategory, bool typePreferred, char typDelim, Oid inputProcedure, Oid outputProcedure, Oid receiveProcedure, Oid sendProcedure, Oid typmodinProcedure, Oid typmodoutProcedure, Oid analyzeProcedure, Oid elementType, bool isImplicitArray, Oid arrayType, Oid baseType, const char *defaultTypeValue, char *defaultTypeBin, bool passedByValue, char alignment, char storage, int32 typeMod, int32 typNDims, bool typeNotNull, Oid typeCollation)
void DeleteSystemAttributeTuples(Oid relid)
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, const char *conSrc, bool conIsLocal, int conInhCount, bool conNoInherit, bool is_internal)
void log_smgrcreate(RelFileNode *rnode, ForkNumber forkNum)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define CStringGetTextDatum(s)
char * nodeToString(const void *obj)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void CatalogCloseIndexes(CatalogIndexState indstate)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
void RemoveAttrDefault(Oid relid, AttrNumber attnum, DropBehavior behavior, bool complain, bool internal)
#define SelfItemPointerAttributeNumber
Oid CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup, CatalogIndexState indstate)
#define HeapTupleGetOid(tuple)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define SearchSysCacheCopy2(cacheId, key1, key2)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Oid getBaseType(Oid typid)
void heap_drop_with_catalog(Oid relid)
#define MinTransactionIdAttributeNumber
bool type_is_collatable(Oid typid)
#define ERRCODE_DUPLICATE_OBJECT
char * get_rel_name(Oid relid)
void smgrimmedsync(SMgrRelation reln, ForkNumber forknum)
void RelationCreateStorage(RelFileNode rnode, char relpersistence)
static FormData_pg_attribute a5
#define RelationGetRelid(relation)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
Relation index_open(Oid relationId, LOCKMODE lockmode)
List * AddRelationNewConstraints(Relation rel, List *newColDefaults, List *newConstraints, bool allow_merge, bool is_local, bool is_internal)
#define BTEqualStrategyNumber
static Oid StoreRelCheck(Relation rel, const char *ccname, Node *expr, bool is_validated, bool is_local, int inhcount, bool is_no_inherit, bool is_internal)
List * heap_truncate_find_FKs(List *relationIds)
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
List * list_delete_first(List *list)
#define RelationGetPartitionDesc(relation)
#define PERFORM_DELETION_INTERNAL
static void RelationTruncateIndexes(Relation heapRelation)
static FormData_pg_attribute a2
void RelationTruncate(Relation rel, BlockNumber nblocks)
#define RelationGetNamespace(relation)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)