yjhjstz commented on code in PR #2027:
URL: https://github.com/apache/cloudberry/pull/2027#discussion_r4076924864
##########
src/backend/commands/analyze.c:
##########
@@ -4977,6 +4978,28 @@ merge_leaf_stats(VacAttrStatsP stats,
if (valid)
{
+ /*
+ * The leaves' values are summed, which is only right
when leaves hold
+ * disjoint values, e.g. for the partitioning key. A
value repeated in
+ * every partition is counted once per partition, so
the sum grows
+ * with the number of partitions and ORCA overestimates
the output of
+ * a local aggregate. A segment cannot have more
distinct values than
+ * the whole table, so clamp to the root's ndistinct
times the number
+ * of segments.
+ */
+ double root_ndistinct = stats->stadistinct < 0
?
+ -stats->stadistinct * totalTuples :
stats->stadistinct;
+
+ if (root_ndistinct > 0)
+ {
+ GpPolicy *policy =
GpPolicyFetch(stats->attr->attrelid);
Review Comment:
need `pfree(policy);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]