MCPcopy Create free account
hub / github.com/apache/cloudberry / ATExecSetOptions

Function ATExecSetOptions

src/backend/commands/tablecmds.c:10000–10071  ·  view source on GitHub ↗

* Return value is the address of the modified column */

Source from the content-addressed store, hash-verified

9998 * Return value is the address of the modified column
9999 */
10000static ObjectAddress
10001ATExecSetOptions(Relation rel, const char *colName, Node *options,
10002 bool isReset, LOCKMODE lockmode)
10003{
10004 Relation attrelation;
10005 HeapTuple tuple,
10006 newtuple;
10007 Form_pg_attribute attrtuple;
10008 AttrNumber attnum;
10009 Datum datum,
10010 newOptions;
10011 bool isnull;
10012 ObjectAddress address;
10013 Datum repl_val[Natts_pg_attribute];
10014 bool repl_null[Natts_pg_attribute];
10015 bool repl_repl[Natts_pg_attribute];
10016
10017 attrelation = table_open(AttributeRelationId, RowExclusiveLock);
10018
10019 tuple = SearchSysCacheAttName(RelationGetRelid(rel), colName);
10020
10021 if (!HeapTupleIsValid(tuple))
10022 ereport(ERROR,
10023 (errcode(ERRCODE_UNDEFINED_COLUMN),
10024 errmsg("column \"%s\" of relation \"%s\" does not exist",
10025 colName, RelationGetRelationName(rel))));
10026 attrtuple = (Form_pg_attribute) GETSTRUCT(tuple);
10027
10028 attnum = attrtuple->attnum;
10029 if (attnum <= 0)
10030 ereport(ERROR,
10031 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10032 errmsg("cannot alter system column \"%s\"",
10033 colName)));
10034
10035 /* Generate new proposed attoptions (text array) */
10036 datum = SysCacheGetAttr(ATTNAME, tuple, Anum_pg_attribute_attoptions,
10037 &isnull);
10038 newOptions = transformRelOptions(isnull ? (Datum) 0 : datum,
10039 castNode(List, options), NULL, NULL,
10040 false, isReset);
10041 /* Validate new options */
10042 (void) attribute_reloptions(newOptions, true);
10043
10044 /* Build new tuple. */
10045 memset(repl_null, false, sizeof(repl_null));
10046 memset(repl_repl, false, sizeof(repl_repl));
10047 if (newOptions != (Datum) 0)
10048 repl_val[Anum_pg_attribute_attoptions - 1] = newOptions;
10049 else
10050 repl_null[Anum_pg_attribute_attoptions - 1] = true;
10051 repl_repl[Anum_pg_attribute_attoptions - 1] = true;
10052 newtuple = heap_modify_tuple(tuple, RelationGetDescr(attrelation),
10053 repl_val, repl_null, repl_repl);
10054
10055 /* Update system catalog. */
10056 CatalogTupleUpdate(attrelation, &newtuple->t_self, newtuple);
10057

Callers 1

ATExecCmdFunction · 0.85

Calls 12

table_openFunction · 0.85
SearchSysCacheAttNameFunction · 0.85
SysCacheGetAttrFunction · 0.85
transformRelOptionsFunction · 0.85
attribute_reloptionsFunction · 0.85
heap_modify_tupleFunction · 0.85
CatalogTupleUpdateFunction · 0.85
heap_freetupleFunction · 0.85
ReleaseSysCacheFunction · 0.85
table_closeFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected