summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorunknown <timour@mysql.com>2006-03-31 12:39:33 +0300
committerunknown <timour@mysql.com>2006-03-31 12:39:33 +0300
commit085aa5c99e7935b0895d09acad13685ba2e6c3e4 (patch)
tree88258692d6bed7dc04376eda6523507dc716bcd6 /sql/opt_range.cc
parent86504f87851d7eb5947d3bba41ae0ddf45aa92ab (diff)
parenta01d48f92e9c2eebe91e92962b5fdb075978c712 (diff)
downloadmariadb-git-085aa5c99e7935b0895d09acad13685ba2e6c3e4.tar.gz
Merge mysql.com:/home/timka/mysql/src/5.0-virgin
into mysql.com:/home/timka/mysql/src/5.0-bug-16710 mysql-test/r/group_min_max.result: Auto merged mysql-test/t/group_min_max.test: Auto merged sql/item.cc: Auto merged sql/item.h: Auto merged sql/opt_range.cc: Auto merged
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 634c9db18a8..d76495a0678 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -6895,6 +6895,7 @@ cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
bool have_min, bool have_max,
double *read_cost, ha_rows *records);
+
/*
Test if this access method is applicable to a GROUP query with MIN/MAX
functions, and if so, construct a new TRP object.
@@ -7301,11 +7302,36 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
}
else if (min_max_arg_part &&
(min_max_arg_part - first_non_group_part > 0))
+ {
/*
There is a gap but no range tree, thus no predicates at all for the
non-group keyparts.
*/
goto next_index;
+ }
+ else if (first_non_group_part && join->conds)
+ {
+ /*
+ If there is no MIN/MAX function in the query, but some index
+ key part is referenced in the WHERE clause, then this index
+ cannot be used because the WHERE condition over the keypart's
+ field cannot be 'pushed' to the index (because there is no
+ range 'tree'), and the WHERE clause must be evaluated before
+ GROUP BY/DISTINCT.
+ */
+ /*
+ Store the first and last keyparts that need to be analyzed
+ into one array that can be passed as parameter.
+ */
+ KEY_PART_INFO *key_part_range[2];
+ key_part_range[0]= first_non_group_part;
+ key_part_range[1]= last_part;
+
+ /* Check if cur_part is referenced in the WHERE clause. */
+ if (join->conds->walk(&Item::find_item_in_field_list_processor,
+ (byte*) key_part_range))
+ goto next_index;
+ }
}
/*