diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-03-17 12:22:05 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-03-17 12:26:26 +0100 |
commit | 012460ee93c304fbc7220e5b55d9d0577fc766ab (patch) | |
tree | af8936fda212e29d7678141691e2ad7e4b3ccd69 /src/backend/commands/tablecmds.c | |
parent | 33e729c5148c3a697abc552621b34bdc5fd497ed (diff) |
Make stxstattarget nullable
To match attstattarget change (commit 4f622503d6d). The logic inside
CreateStatistics() is clarified a bit compared to that previous patch,
and so here we also update ATExecSetStatistics() to match.
Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/4da8d211-d54d-44b9-9847-f2a9f1184c76@eisentraut.org
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 2470265561a..ae6719329e7 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8712,6 +8712,7 @@ static ObjectAddress ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newValue, LOCKMODE lockmode) { int newtarget; + bool newtarget_default; Relation attrelation; HeapTuple tuple, newtuple; @@ -8733,35 +8734,35 @@ ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot refer to non-index column by number"))); - if (newValue) + /* -1 was used in previous versions for the default setting */ + if (newValue && intVal(newValue) != -1) { newtarget = intVal(newValue); + newtarget_default = false; } else + newtarget_default = true; + + if (!newtarget_default) { /* - * -1 was used in previous versions to represent the default setting + * Limit target to a sane range */ - newtarget = -1; - } - - /* - * Limit target to a sane range - */ - if (newtarget < -1) - { - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("statistics target %d is too low", - newtarget))); - } - else if (newtarget > MAX_STATISTICS_TARGET) - { - newtarget = MAX_STATISTICS_TARGET; - ereport(WARNING, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("lowering statistics target to %d", - newtarget))); + if (newtarget < 0) + { + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("statistics target %d is too low", + newtarget))); + } + else if (newtarget > MAX_STATISTICS_TARGET) + { + newtarget = MAX_STATISTICS_TARGET; + ereport(WARNING, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("lowering statistics target to %d", + newtarget))); + } } attrelation = table_open(AttributeRelationId, RowExclusiveLock); @@ -8815,7 +8816,7 @@ ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa /* Build new tuple. */ memset(repl_null, false, sizeof(repl_null)); memset(repl_repl, false, sizeof(repl_repl)); - if (newtarget != -1) + if (!newtarget_default) repl_val[Anum_pg_attribute_attstattarget - 1] = newtarget; else repl_null[Anum_pg_attribute_attstattarget - 1] = true; |