Fix hypopg_analyze() behavior for hash partitions.

We do not need (nor can use) statistics for hash partitions, but those can
exist anywhere in the partitioning tree.  So just forbidding hypopg_analyze()
if the first level is partitioned by hash was wrong.
This commit is contained in:
Julien Rouhaud 2018-10-12 21:45:28 +02:00
parent d8d94e8112
commit 65ead65f33
2 changed files with 30 additions and 4 deletions

View file

@ -328,7 +328,21 @@ SELECT * FROM hypopg_analyze('hypo_part_list',100);
(1 row)
SELECT * FROM hypopg_analyze('hypo_part_hash',100);
ERROR: hypopg: hypopg_analyze() on hypothetical hash partitioning is not supported
NOTICE: hypothetical partition "hypo_part_hash_9" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_8" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_7" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_6" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_5" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_4" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_3" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_2" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_1" is a hash partition, skipping
NOTICE: hypothetical partition "hypo_part_hash_0" is a hash partition, skipping
hypopg_analyze
----------------
(1 row)
SELECT * FROM hypopg_analyze('hypo_part_multi',100);
hypopg_analyze
----------------

View file

@ -220,6 +220,21 @@ static void hypo_do_analyze_partition(Relation onerel, Relation pgstats,
Assert(hypoStatsHash);
/*
* We can't use the same heuristics for hash partitions selectivity
* estimation, because its constraint is using satisfies_hash_partition(),
* for which the selectivity estimation won't have any knowledge and will
* therefore apply some default selectivty which will be totally wrong.
* Instead, we'll just compute the selectivity of hash partitions using the
* modulus, so don't bother computing and storing statistics;
*/
if (part->boundspec->strategy == PARTITION_STRATEGY_HASH)
{
elog(NOTICE, "hypothetical partition \"%s\" is a hash partition,"
" skipping", part->tablename);
return;
}
/*
* Set up a working context so that we can easily free whatever junk gets
* created.
@ -569,9 +584,6 @@ HYPO_PARTITION_NOT_SUPPORTED();
|| fraction <= 0 || fraction > 100)
elog(ERROR, "hypopg: invalid fraction: %f", fraction);
if (root_entry->partkey->strategy == PARTITION_STRATEGY_HASH)
elog(ERROR, "hypopg: hypopg_analyze() on hypothetical hash partitioning is not supported");
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
/* internal error */