From 5c0cdea62341da75f0560216af1b363b156ed1ab Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2006 17:30:59 +0500 Subject: BUG#20357 - Got error 124 from storage engine using MIN and MAX functions in queries Using MAX()/MIN() on table with disabled indexes (by ALTER TABLE) results in error 124 (wrong index) from storage engine. The problem was that optimizer use disabled index to optimize MAX()/MIN(). Normally it must skip disabled index and perform table scan. This patch skips disabled indexes for min/max optimization. mysql-test/r/myisam.result: Test case for BUG#20357. mysql-test/t/myisam.test: Test case for BUG#20357. sql/opt_sum.cc: Skip disabled/ignored indexes for min/max optimization. --- sql/opt_sum.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sql/opt_sum.cc') diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index cfb5b3695a3..63373a8579a 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -673,6 +673,12 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, { KEY_PART_INFO *part,*part_end; key_part_map key_part_to_use= 0; + /* + Perform a check if index is not disabled by ALTER TABLE + or IGNORE INDEX. + */ + if (!table->keys_in_use_for_query.is_set(idx)) + continue; uint jdx= 0; *prefix_len= 0; for (part= keyinfo->key_part, part_end= part+keyinfo->key_parts ; -- cgit v1.2.1