diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-09 03:16:47 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-09 03:16:47 +0000 |
commit | 14f84cd82103c3797980125bb44a76446e0c0dc6 (patch) | |
tree | 27dd1bcb5186440311b59772755f40ffb32e8541 /src/backend/commands | |
parent | 5af4b04f31a27ed60fe360e70acf67d208f883b3 (diff) | |
download | postgresql-14f84cd82103c3797980125bb44a76446e0c0dc6.tar.gz postgresql-14f84cd82103c3797980125bb44a76446e0c0dc6.zip |
Store -1 in attdisbursion to signal 'no duplicates in column'.
Centralize att_disbursion readout logic.
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/vacuum.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 0418a8d3a38..b480b44f347 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.117 1999/08/08 17:13:10 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.118 1999/08/09 03:16:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2346,36 +2346,46 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex, VRelStats * } else if (stats->null_cnt <= 1 && stats->best_cnt == 1) { - /* looks like we have a unique-key attribute */ - double total = ((double) stats->nonnull_cnt) + ((double) stats->null_cnt); - - selratio = 1.0 / total; - } - else if (VacAttrStatsLtGtValid(stats) && stats->min_cnt + stats->max_cnt == stats->nonnull_cnt) - { - /* exact result when there are just 1 or 2 values... */ - double min_cnt_d = stats->min_cnt, - max_cnt_d = stats->max_cnt, - null_cnt_d = stats->null_cnt; - double total = ((double) stats->nonnull_cnt) + null_cnt_d; - - selratio = (min_cnt_d * min_cnt_d + max_cnt_d * max_cnt_d + null_cnt_d * null_cnt_d) / (total * total); + /* looks like we have a unique-key attribute --- + * flag this with special -1.0 flag value. + * + * The correct disbursion is 1.0/numberOfRows, but since + * the relation row count can get updated without + * recomputing disbursion, we want to store a "symbolic" + * value and figure 1.0/numberOfRows on the fly. + */ + selratio = -1; } else { - double most = (double) (stats->best_cnt > stats->null_cnt ? stats->best_cnt : stats->null_cnt); - double total = ((double) stats->nonnull_cnt) + ((double) stats->null_cnt); + if (VacAttrStatsLtGtValid(stats) && + stats->min_cnt + stats->max_cnt == stats->nonnull_cnt) + { + /* exact result when there are just 1 or 2 values... */ + double min_cnt_d = stats->min_cnt, + max_cnt_d = stats->max_cnt, + null_cnt_d = stats->null_cnt; + double total = ((double) stats->nonnull_cnt) + null_cnt_d; - /* - * we assume count of other values are 20% of best - * count in table - */ - selratio = (most * most + 0.20 * most * (total - most)) / (total * total); + selratio = (min_cnt_d * min_cnt_d + max_cnt_d * max_cnt_d + null_cnt_d * null_cnt_d) / (total * total); + } + else + { + double most = (double) (stats->best_cnt > stats->null_cnt ? stats->best_cnt : stats->null_cnt); + double total = ((double) stats->nonnull_cnt) + ((double) stats->null_cnt); + + /* + * we assume count of other values are 20% of best + * count in table + */ + selratio = (most * most + 0.20 * most * (total - most)) / (total * total); + } + /* Make sure calculated values are in-range */ + if (selratio < 0.0) + selratio = 0.0; + else if (selratio > 1.0) + selratio = 1.0; } - if (selratio < 0.0) - selratio = 0.0; - else if (selratio > 1.0) - selratio = 1.0; attp->attdisbursion = selratio; /* |