Affects Version/s: None
Fix Version/s: 1.5.0
If columns in "select distinct" are already distinct, there can be two sets of equivalent rel before and after AggregateRemoveRule.
Based on the default implementation of rel metadata, the rowCount of the "before" rel is only 1/10 of that of the "after" rel, but meanwhile the "after" rel is definitely cheaper. So the Volcano planner would most likely either fail to pick the cheapest one or have an inconsistent state due to CALCITE-830.
An example (based EnumerableRel cost model):
The plan for
, while it should be