summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2005-03-30 15:57:42 +0400
committerunknown <sergefp@mysql.com>2005-03-30 15:57:42 +0400
commit5ac4670bf7f17374e8bae1bd27625ccabc1eac82 (patch)
treef1b5f4d005ed6b67c11d3881df26610ec2f06acc /sql/sql_select.cc
parent633a2468ec3407d1900b6cce276cc80a89d978a6 (diff)
downloadmariadb-git-5ac4670bf7f17374e8bae1bd27625ccabc1eac82.tar.gz
Fix for BUG#9213: GROUP BY returns wrong query results:
Make test_if_skip_sort_order() rebuild tab->ref if it decides to use an index different from the index join optimizer has choosen. mysql-test/r/group_by.result: Testcase for BUG#9213 mysql-test/t/group_by.test: Testcase for BUG#9213 sql/table.h: Added comments about TABLE::used_keys
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 364d1c199ac..cbb2c0a621f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -7185,7 +7185,19 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
/* Found key that can be used to retrieve data in sorted order */
if (tab->ref.key >= 0)
{
- tab->ref.key= new_ref_key;
+ /*
+ We'll use ref access method on key new_ref_key. In general case
+ the index search tuple for new_ref_key will be different (e.g.
+ when one of the indexes only covers prefix of the field, see
+ BUG#9213 in group_by.test).
+ So we build tab->ref from scratch here.
+ */
+ KEYUSE *keyuse= tab->keyuse;
+ while (keyuse->key != new_ref_key && keyuse->table == tab->table)
+ keyuse++;
+ if (create_ref_for_key(tab->join, tab, keyuse,
+ tab->join->const_table_map))
+ DBUG_RETURN(0);
}
else
{