Changed aggregate distinct optimization with indexes to be cost based.
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.
Showing
Please register or sign in to comment