|
Line 0
Link Here
|
|
|
1 |
--- sql/sql_select.cc.orig Wed Jul 19 17:10:38 2006 |
| 2 |
+++ sql/sql_select.cc Sun Nov 19 21:07:19 2006 |
| 3 |
@@ -630,6 +630,36 @@ |
| 4 |
if (!order && org_order) |
| 5 |
skip_sort_order= 1; |
| 6 |
} |
| 7 |
+ /* |
| 8 |
+ Check if we can optimize away GROUP BY/DISTINCT. |
| 9 |
+ We can do that if there are no aggregate functions and the |
| 10 |
+ fields in DISTINCT clause (if present) and/or columns in GROUP BY |
| 11 |
+ (if present) contain direct references to all key parts of |
| 12 |
+ an unique index (in whatever order). |
| 13 |
+ Note that the unique keys for DISTINCT and GROUP BY should not |
| 14 |
+ be the same (as long as they are unique). |
| 15 |
+ |
| 16 |
+ The FROM clause must contain a single non-constant table. |
| 17 |
+ */ |
| 18 |
+ if (tables - const_tables == 1 && (group_list || select_distinct) && |
| 19 |
+ !tmp_table_param.sum_func_count) |
| 20 |
+ { |
| 21 |
+ if (group_list && |
| 22 |
+ list_contains_unique_index(join_tab[const_tables].table, |
| 23 |
+ find_field_in_order_list, |
| 24 |
+ (void *) group_list)) |
| 25 |
+ { |
| 26 |
+ group_list= 0; |
| 27 |
+ group= 0; |
| 28 |
+ } |
| 29 |
+ if (select_distinct && |
| 30 |
+ list_contains_unique_index(join_tab[const_tables].table, |
| 31 |
+ find_field_in_item_list, |
| 32 |
+ (void *) &fields_list)) |
| 33 |
+ { |
| 34 |
+ select_distinct= 0; |
| 35 |
+ } |
| 36 |
+ } |
| 37 |
if (group_list || tmp_table_param.sum_func_count) |
| 38 |
{ |
| 39 |
if (! hidden_group_fields && rollup.state == ROLLUP::STATE_NONE) |
| 40 |
@@ -698,36 +728,6 @@ |
| 41 |
&simple_group); |
| 42 |
if (old_group_list && !group_list) |
| 43 |
select_distinct= 0; |
| 44 |
- } |
| 45 |
- /* |
| 46 |
- Check if we can optimize away GROUP BY/DISTINCT. |
| 47 |
- We can do that if there are no aggregate functions and the |
| 48 |
- fields in DISTINCT clause (if present) and/or columns in GROUP BY |
| 49 |
- (if present) contain direct references to all key parts of |
| 50 |
- an unique index (in whatever order). |
| 51 |
- Note that the unique keys for DISTINCT and GROUP BY should not |
| 52 |
- be the same (as long as they are unique). |
| 53 |
- |
| 54 |
- The FROM clause must contain a single non-constant table. |
| 55 |
- */ |
| 56 |
- if (tables - const_tables == 1 && (group_list || select_distinct) && |
| 57 |
- !tmp_table_param.sum_func_count) |
| 58 |
- { |
| 59 |
- if (group_list && |
| 60 |
- list_contains_unique_index(join_tab[const_tables].table, |
| 61 |
- find_field_in_order_list, |
| 62 |
- (void *) group_list)) |
| 63 |
- { |
| 64 |
- group_list= 0; |
| 65 |
- group= 0; |
| 66 |
- } |
| 67 |
- if (select_distinct && |
| 68 |
- list_contains_unique_index(join_tab[const_tables].table, |
| 69 |
- find_field_in_item_list, |
| 70 |
- (void *) &fields_list)) |
| 71 |
- { |
| 72 |
- select_distinct= 0; |
| 73 |
- } |
| 74 |
} |
| 75 |
if (!group_list && group) |
| 76 |
{ |