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

Function ATExecSetStatistics

src/backend/commands/tablecmds.c:9882–9995  ·  view source on GitHub ↗

* ALTER TABLE ALTER COLUMN SET STATISTICS * * Return value is the address of the modified column */

Source from the content-addressed store, hash-verified

9880 * Return value is the address of the modified column
9881 */
9882static ObjectAddress
9883ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode)
9884{
9885 int newtarget;
9886 Relation attrelation;
9887 HeapTuple tuple;
9888 Form_pg_attribute attrtuple;
9889 AttrNumber attnum;
9890 ObjectAddress address;
9891
9892 /*
9893 * We allow referencing columns by numbers only for indexes, since table
9894 * column numbers could contain gaps if columns are later dropped.
9895 */
9896 if (rel->rd_rel->relkind != RELKIND_INDEX &&
9897 rel->rd_rel->relkind != RELKIND_PARTITIONED_INDEX &&
9898 !colName)
9899 ereport(ERROR,
9900 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
9901 errmsg("cannot refer to non-index column by number")));
9902
9903 Assert(IsA(newValue, Integer));
9904 newtarget = intVal(newValue);
9905
9906 /*
9907 * Limit target to a sane range
9908 */
9909 if (newtarget < -1)
9910 {
9911 ereport(ERROR,
9912 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9913 errmsg("statistics target %d is too low",
9914 newtarget)));
9915 }
9916 else if (newtarget > 10000)
9917 {
9918 newtarget = 10000;
9919 ereport(WARNING,
9920 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
9921 errmsg("lowering statistics target to %d",
9922 newtarget)));
9923 }
9924
9925 attrelation = table_open(AttributeRelationId, RowExclusiveLock);
9926
9927 if (colName)
9928 {
9929 tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
9930
9931 if (!HeapTupleIsValid(tuple))
9932 ereport(ERROR,
9933 (errcode(ERRCODE_UNDEFINED_COLUMN),
9934 errmsg("column \"%s\" of relation \"%s\" does not exist",
9935 colName, RelationGetRelationName(rel))));
9936 }
9937 else
9938 {
9939 tuple = SearchSysCacheCopyAttNum(RelationGetRelid(rel), colNum);

Callers 1

ATExecCmdFunction · 0.85

Calls 12

table_openFunction · 0.85
SearchSysCacheCopyAttNumFunction · 0.85
CatalogTupleUpdateFunction · 0.85
heap_freetupleFunction · 0.85
table_closeFunction · 0.85
MetaTrackValidKindNspFunction · 0.85
MetaTrackUpdObjectFunction · 0.85
GetUserIdFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected