mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Make stxstattarget nullable
To match attstattarget change (commit 4f622503d6). 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
This commit is contained in:
@@ -495,9 +495,9 @@ CreateStatistics(CreateStatsStmt *stmt)
|
||||
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
|
||||
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
|
||||
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
|
||||
values[Anum_pg_statistic_ext_stxstattarget - 1] = Int16GetDatum(-1);
|
||||
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
|
||||
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);
|
||||
nulls[Anum_pg_statistic_ext_stxstattarget - 1] = true;
|
||||
values[Anum_pg_statistic_ext_stxkind - 1] = PointerGetDatum(stxkind);
|
||||
|
||||
values[Anum_pg_statistic_ext_stxexprs - 1] = exprsDatum;
|
||||
@@ -606,23 +606,36 @@ AlterStatistics(AlterStatsStmt *stmt)
|
||||
bool repl_null[Natts_pg_statistic_ext];
|
||||
bool repl_repl[Natts_pg_statistic_ext];
|
||||
ObjectAddress address;
|
||||
int newtarget = stmt->stxstattarget;
|
||||
int newtarget;
|
||||
bool newtarget_default;
|
||||
|
||||
/* Limit statistics target to a sane range */
|
||||
if (newtarget < -1)
|
||||
/* -1 was used in previous versions for the default setting */
|
||||
if (stmt->stxstattarget && intVal(stmt->stxstattarget) != -1)
|
||||
{
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("statistics target %d is too low",
|
||||
newtarget)));
|
||||
newtarget = intVal(stmt->stxstattarget);
|
||||
newtarget_default = false;
|
||||
}
|
||||
else if (newtarget > MAX_STATISTICS_TARGET)
|
||||
else
|
||||
newtarget_default = true;
|
||||
|
||||
if (!newtarget_default)
|
||||
{
|
||||
newtarget = MAX_STATISTICS_TARGET;
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("lowering statistics target to %d",
|
||||
newtarget)));
|
||||
/* Limit statistics target to a sane range */
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
/* lookup OID of the statistics object */
|
||||
@@ -673,7 +686,10 @@ AlterStatistics(AlterStatsStmt *stmt)
|
||||
|
||||
/* replace the stxstattarget column */
|
||||
repl_repl[Anum_pg_statistic_ext_stxstattarget - 1] = true;
|
||||
repl_val[Anum_pg_statistic_ext_stxstattarget - 1] = Int16GetDatum(newtarget);
|
||||
if (!newtarget_default)
|
||||
repl_val[Anum_pg_statistic_ext_stxstattarget - 1] = Int16GetDatum(newtarget);
|
||||
else
|
||||
repl_null[Anum_pg_statistic_ext_stxstattarget - 1] = true;
|
||||
|
||||
newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
|
||||
repl_val, repl_null, repl_repl);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user