diff --git a/Docs/manual.texi b/Docs/manual.texi index 232e0c0a2f1..5ded6e75cf1 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -49456,7 +49456,12 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}. @itemize @bullet @item -Fixed a bug in optimiser when a range specified makes index grouping impossible +Fixed a bug in optimiser with merge tables when non-uniques values are +used in summing up. +This consistently crashed MySQL. +@item +Fixed a bug in optimiser when a range specified makes index grouping impossible. +This consistently crashed MySQL. @item Fixed a rare bug when fulltext index is present and no tables are used @item diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 9b72ff26350..1e657883253 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -462,3 +462,12 @@ a b 6 1 6 2 drop table if exists t6, t5, t4, t3, t2, t1; +CREATE TABLE t1 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) TYPE=MyISAM; +INSERT INTO t1 VALUES (1,1), (2,1); +CREATE TABLE t2 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) TYPE=MyISAM; +INSERT INTO t2 VALUES (1,2), (2,2); +CREATE TABLE t ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', KEY a (a,b)) TYPE=MRG_MyISAM UNION=(t1,t2); +select max(b) from t where a = 2; +max(b) +NULL +drop table if exists t,t1,t2; diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 5bd78769a05..de26d7eb1d3 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -168,3 +168,10 @@ select * from t3 order by a,b; select * from t4 order by a,b; select * from t5 order by a,b; drop table if exists t6, t5, t4, t3, t2, t1; +CREATE TABLE t1 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) TYPE=MyISAM; +INSERT INTO t1 VALUES (1,1), (2,1); +CREATE TABLE t2 ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', PRIMARY KEY (a,b)) TYPE=MyISAM; +INSERT INTO t2 VALUES (1,2), (2,2); +CREATE TABLE t ( a int(11) NOT NULL default '0', b int(11) NOT NULL default '0', KEY a (a,b)) TYPE=MRG_MyISAM UNION=(t1,t2); +select max(b) from t where a = 2; +drop table if exists t,t1,t2; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index efb4c4916a5..7ffbb7ba8ea 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -152,11 +152,12 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) error=table->file->index_last(table->record[0]) !=0; else { - (void) table->file->index_read(table->record[0], key_buff, + error= table->file->index_read(table->record[0], key_buff, ref.key_length, HA_READ_AFTER_KEY); - error=table->file->index_prev(table->record[0]) || - key_cmp(table,key_buff,ref.key,ref.key_length); + if (!error) + error=table->file->index_prev(table->record[0]) || + key_cmp(table,key_buff,ref.key,ref.key_length); } if (table->key_read) {