• Monty's avatar
    Changed aggregate distinct optimization with indexes to be cost based. · 43dc831e
    Monty authored
    Before the cost of an aggregate distinct (COUNT(DISTINCT ...)) was set
    to 0 if the values where part of an index and the cost of grouping
    was higher than the best cost so far.  This was shown in explain with
    "Using index for group-by (scanning)".
    
    This patch fixes it by calculating the cost of aggregate distinct
    and using scanning only if the cost was better than group-by-optimization.
    
    Thing taken into account:
    - When using aggregate distinct on index, the filtering is done before
      the row is checked against the WHERE and we have thus less WHERE cost.
    - When comparing a cost from aggregate distinct, we add to the compared
      to plan the cost of doing the filtering later in the SQL level.
    43dc831e
optimizer_costs.h 5.9 KB