summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc13
1 files changed, 10 insertions, 3 deletions
diff --git a/sql/table.cc b/sql/table.cc
index d2938a29ea6..f6d4a4ddc63 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -7126,10 +7126,17 @@ bool TABLE::add_tmp_key(uint key, uint key_parts,
This handles the case when we have a single select in the derived table
*/
st_select_lex* first= derived->first_select();
- if ((first && !first->is_part_of_union() &&
- first->options & SELECT_DISTINCT) ||
- derived->check_distinct_in_union())
+ if (first)
+ {
+ if (!first->is_part_of_union() && first->options & SELECT_DISTINCT)
keyinfo->rec_per_key[key_parts-1]=1;
+ else
+ {
+ if (derived->check_distinct_in_union() ||
+ (first->select_items_in_group_by()))
+ keyinfo->rec_per_key[key_parts-1]=1;
+ }
+ }
}
keyinfo->read_stats= NULL;