merge of the fix for bug 27802 & 27216 to 5.1-opt

parent 133175fb
...@@ -3575,22 +3575,22 @@ PRIMARY KEY(a), KEY (b)); ...@@ -3575,22 +3575,22 @@ PRIMARY KEY(a), KEY (b));
INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(); INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),();
CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a; CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a;
SHOW CREATE VIEW v1; SHOW CREATE VIEW v1;
View Create View View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` FORCE INDEX (PRIMARY,`b`) order by `t1`.`a` v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` FORCE INDEX (PRIMARY) FORCE INDEX (`b`) order by `t1`.`a` latin1 latin1_swedish_ci
EXPLAIN SELECT * FROM v1; EXPLAIN SELECT * FROM v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 15 1 SIMPLE t1 index NULL PRIMARY 4 NULL 15
CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a; CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a;
SHOW CREATE VIEW v2; SHOW CREATE VIEW v2;
View Create View View Create View character_set_client collation_connection
v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` USE INDEX () order by `t1`.`a` v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` USE INDEX () order by `t1`.`a` latin1 latin1_swedish_ci
EXPLAIN SELECT * FROM v2; EXPLAIN SELECT * FROM v2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort
CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a; CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a;
SHOW CREATE VIEW v3; SHOW CREATE VIEW v3;
View Create View View Create View character_set_client collation_connection
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` IGNORE INDEX (`b`) order by `t1`.`a` v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` IGNORE INDEX (`b`) order by `t1`.`a` latin1 latin1_swedish_ci
EXPLAIN SELECT * FROM v3; EXPLAIN SELECT * FROM v3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort
......
...@@ -1108,6 +1108,7 @@ class Item_func_case :public Item_func ...@@ -1108,6 +1108,7 @@ class Item_func_case :public Item_func
uint ncases; uint ncases;
Item_result cmp_type; Item_result cmp_type;
DTCollation cmp_collation; DTCollation cmp_collation;
enum_field_types cached_field_type;
cmp_item *cmp_items[5]; /* For all result types */ cmp_item *cmp_items[5]; /* For all result types */
cmp_item *case_item; cmp_item *case_item;
public: public:
...@@ -1138,6 +1139,7 @@ public: ...@@ -1138,6 +1139,7 @@ public:
uint decimal_precision() const; uint decimal_precision() const;
table_map not_null_tables() const { return 0; } table_map not_null_tables() const { return 0; }
enum Item_result result_type () const { return cached_result_type; } enum Item_result result_type () const { return cached_result_type; }
enum_field_types field_type() const { return cached_field_type; }
const char *func_name() const { return "case"; } const char *func_name() const { return "case"; }
void print(String *str); void print(String *str);
Item *find_item(String *str); Item *find_item(String *str);
......
...@@ -3315,7 +3315,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, ...@@ -3315,7 +3315,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
if (item->result_type() != STRING_RESULT) if (item->result_type() != STRING_RESULT)
field= item->tmp_table_field(&tmp_table); field= item->tmp_table_field(&tmp_table);
else else
field= item->tmp_table_field_from_field_type(&tmp_table); field= item->tmp_table_field_from_field_type(&tmp_table, 0);
else else
field= create_tmp_field(thd, &tmp_table, item, item->type(), field= create_tmp_field(thd, &tmp_table, item, item->type(),
(Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0, (Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0,
......
...@@ -259,6 +259,8 @@ public: ...@@ -259,6 +259,8 @@ public:
key_name.str= str; key_name.str= str;
key_name.length= length; key_name.length= length;
} }
void print(THD *thd, String *str);
}; };
/* /*
......
...@@ -16044,9 +16044,9 @@ static void print_join(THD *thd, String *str, List<TABLE_LIST> *tables) ...@@ -16044,9 +16044,9 @@ static void print_join(THD *thd, String *str, List<TABLE_LIST> *tables)
/** /**
@brief Print an index hint for a table @brief Print an index hint
@details Prints out the USE|FORCE|IGNORE index hints for a table. @details Prints out the USE|FORCE|IGNORE index hint.
@param thd the current thread @param thd the current thread
@param[out] str appends the index hint here @param[out] str appends the index hint here
...@@ -16057,28 +16057,24 @@ static void print_join(THD *thd, String *str, List<TABLE_LIST> *tables) ...@@ -16057,28 +16057,24 @@ static void print_join(THD *thd, String *str, List<TABLE_LIST> *tables)
*/ */
void void
TABLE_LIST::print_index_hint(THD *thd, String *str, Index_hint::print(THD *thd, String *str)
const char *hint, uint32 hint_length,
List<String> indexes)
{ {
List_iterator_fast<String> li(indexes); switch (type)
String *idx; {
bool first= 1; case INDEX_HINT_IGNORE: str->append(STRING_WITH_LEN("IGNORE INDEX")); break;
case INDEX_HINT_USE: str->append(STRING_WITH_LEN("USE INDEX")); break;
str->append (' '); case INDEX_HINT_FORCE: str->append(STRING_WITH_LEN("FORCE INDEX")); break;
str->append (hint, hint_length); }
str->append (STRING_WITH_LEN(" (")); str->append (STRING_WITH_LEN(" ("));
while ((idx = li++)) if (key_name.length)
{ {
if (first) if (thd && !my_strnncoll(system_charset_info,
first= 0; (const uchar *)key_name.str, key_name.length,
else (const uchar *)primary_key_name,
str->append(','); strlen(primary_key_name)))
if (!my_strcasecmp (system_charset_info, idx->c_ptr_safe(),
primary_key_name))
str->append(primary_key_name); str->append(primary_key_name);
else else
append_identifier (thd, str, idx->ptr(), idx->length()); append_identifier(thd, str, key_name.str, key_name.length);
} }
str->append(')'); str->append(')');
} }
...@@ -16152,16 +16148,17 @@ void TABLE_LIST::print(THD *thd, String *str) ...@@ -16152,16 +16148,17 @@ void TABLE_LIST::print(THD *thd, String *str)
append_identifier(thd, str, alias, strlen(alias)); append_identifier(thd, str, alias, strlen(alias));
} }
if (use_index) if (index_hints)
{ {
if (force_index) List_iterator<Index_hint> it(*index_hints);
print_index_hint(thd, str, STRING_WITH_LEN("FORCE INDEX"), *use_index); Index_hint *hint;
else
print_index_hint(thd, str, STRING_WITH_LEN("USE INDEX"), *use_index);
}
if (ignore_index)
print_index_hint (thd, str, STRING_WITH_LEN("IGNORE INDEX"), *ignore_index);
while ((hint= it++))
{
str->append (STRING_WITH_LEN(" "));
hint->print (thd, str);
}
}
} }
} }
......
...@@ -1161,8 +1161,6 @@ struct TABLE_LIST ...@@ -1161,8 +1161,6 @@ struct TABLE_LIST
private: private:
bool prep_check_option(THD *thd, uint8 check_opt_type); bool prep_check_option(THD *thd, uint8 check_opt_type);
bool prep_where(THD *thd, Item **conds, bool no_where_clause); bool prep_where(THD *thd, Item **conds, bool no_where_clause);
void print_index_hint(THD *thd, String *str, const char *hint,
uint32 hint_length, List<String>);
/* /*
Cleanup for re-execution in a prepared statement or a stored Cleanup for re-execution in a prepared statement or a stored
procedure. procedure.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment