diff --git a/expected/hypo_table.out b/expected/hypo_table.out index 2d787ee..5ea8e57 100644 --- a/expected/hypo_table.out +++ b/expected/hypo_table.out @@ -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 ---------------- diff --git a/hypopg_analyze.c b/hypopg_analyze.c index 158c479..3702b95 100644 --- a/hypopg_analyze.c +++ b/hypopg_analyze.c @@ -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 */