Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7a7f60a

Browse files
committed
Add macro for maximum statistics target
The number of places where 10000 was hardcoded had grown a bit beyond the comfort level. Introduce a macro MAX_STATISTICS_TARGET instead. Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/d6069765-5971-04d3-c10d-e4f7b2e9c459%40eisentraut.org
1 parent 3ee2f25 commit 7a7f60a

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

src/backend/commands/statscmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,9 @@ AlterStatistics(AlterStatsStmt *stmt)
619619
errmsg("statistics target %d is too low",
620620
newtarget)));
621621
}
622-
else if (newtarget > 10000)
622+
else if (newtarget > MAX_STATISTICS_TARGET)
623623
{
624-
newtarget = 10000;
624+
newtarget = MAX_STATISTICS_TARGET;
625625
ereport(WARNING,
626626
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
627627
errmsg("lowering statistics target to %d",

src/backend/commands/tablecmds.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "commands/trigger.h"
6262
#include "commands/typecmds.h"
6363
#include "commands/user.h"
64+
#include "commands/vacuum.h"
6465
#include "executor/executor.h"
6566
#include "foreign/fdwapi.h"
6667
#include "foreign/foreign.h"
@@ -8180,9 +8181,9 @@ ATExecSetStatistics(Relation rel, const char *colName, int16 colNum, Node *newVa
81808181
errmsg("statistics target %d is too low",
81818182
newtarget)));
81828183
}
8183-
else if (newtarget > 10000)
8184+
else if (newtarget > MAX_STATISTICS_TARGET)
81848185
{
8185-
newtarget = 10000;
8186+
newtarget = MAX_STATISTICS_TARGET;
81868187
ereport(WARNING,
81878188
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
81888189
errmsg("lowering statistics target to %d",

src/backend/statistics/extended_stats.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ statext_compute_stattarget(int stattarget, int nattrs, VacAttrStats **stats)
379379
stattarget = default_statistics_target;
380380

381381
/* As this point we should have a valid statistics target. */
382-
Assert((stattarget >= 0) && (stattarget <= 10000));
382+
Assert((stattarget >= 0) && (stattarget <= MAX_STATISTICS_TARGET));
383383

384384
return stattarget;
385385
}

src/backend/utils/misc/guc_tables.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ struct config_int ConfigureNamesInt[] =
20352035
"column-specific target set via ALTER TABLE SET STATISTICS.")
20362036
},
20372037
&default_statistics_target,
2038-
100, 1, 10000,
2038+
100, 1, MAX_STATISTICS_TARGET,
20392039
NULL, NULL, NULL
20402040
},
20412041
{

src/include/catalog/pg_attribute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75,
165165
* that no value has been explicitly set for this column, so ANALYZE
166166
* should use the default setting.
167167
*
168-
* int16 is sufficient because the max value is currently 10000.
168+
* int16 is sufficient for the current max value (MAX_STATISTICS_TARGET).
169169
*/
170170
int16 attstattarget BKI_DEFAULT(-1);
171171

src/include/commands/vacuum.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ extern PGDLLIMPORT int vacuum_multixact_freeze_table_age;
305305
extern PGDLLIMPORT int vacuum_failsafe_age;
306306
extern PGDLLIMPORT int vacuum_multixact_failsafe_age;
307307

308+
/*
309+
* Maximum value for default_statistics_target and per-column statistics
310+
* targets. This is fairly arbitrary, mainly to prevent users from creating
311+
* unreasonably large statistics that the system cannot handle well.
312+
*/
313+
#define MAX_STATISTICS_TARGET 10000
314+
308315
/* Variables for cost-based parallel vacuum */
309316
extern PGDLLIMPORT pg_atomic_uint32 *VacuumSharedCostBalance;
310317
extern PGDLLIMPORT pg_atomic_uint32 *VacuumActiveNWorkers;

src/include/statistics/statistics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ typedef struct MVDependencies
6666
#define STATS_MCV_MAGIC 0xE1A651C2 /* marks serialized bytea */
6767
#define STATS_MCV_TYPE_BASIC 1 /* basic MCV list type */
6868

69-
/* max items in MCV list (should be equal to max default_statistics_target) */
70-
#define STATS_MCVLIST_MAX_ITEMS 10000
69+
/* max items in MCV list */
70+
#define STATS_MCVLIST_MAX_ITEMS MAX_STATISTICS_TARGET
7171

7272
/*
7373
* Multivariate MCV (most-common value) lists

0 commit comments

Comments
 (0)