Commit bd3a0ce1 authored by gkodinov/kgeorge@magare.gmz's avatar gkodinov/kgeorge@magare.gmz

Merge magare.gmz:/home/kgeorge/mysql/work/WL3527-5.0-opt

into  magare.gmz:/home/kgeorge/mysql/work/WL3527-5.1-opt
parents 188c558a a65bc60d
...@@ -214,3 +214,12 @@ select count(*) from t1; ...@@ -214,3 +214,12 @@ select count(*) from t1;
count(*) count(*)
0 0
drop table t1; drop table t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
DELETE FROM t1 ORDER BY x;
ERROR 42S22: Unknown column 'x' in 'order clause'
DELETE FROM t1 ORDER BY t2.x;
ERROR 42S22: Unknown column 't2.x' in 'order clause'
DELETE FROM t1 ORDER BY (SELECT x);
ERROR 42S22: Unknown column 'x' in 'field list'
DROP TABLE t1;
...@@ -730,6 +730,12 @@ point(b, b) IS NULL linestring(b) IS NULL polygon(b) IS NULL multipoint(b) IS NU ...@@ -730,6 +730,12 @@ point(b, b) IS NULL linestring(b) IS NULL polygon(b) IS NULL multipoint(b) IS NU
1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 0 1 1 1 1 1 1
drop table t1; drop table t1;
CREATE TABLE t1(a POINT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (NULL);
SELECT * FROM t1;
a
NULL
DROP TABLE t1;
End of 4.1 tests End of 4.1 tests
create table t1 (s1 geometry not null,s2 char(100)); create table t1 (s1 geometry not null,s2 char(100));
create trigger t1_bu before update on t1 for each row set new.s1 = null; create trigger t1_bu before update on t1 for each row set new.s1 = null;
......
...@@ -3905,6 +3905,25 @@ COUNT(*) a ...@@ -3905,6 +3905,25 @@ COUNT(*) a
2 2 2 2
3 3 3 3
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (a int, b int);
CREATE TABLE t2 (m int, n int);
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
SELECT COUNT(*) c, a,
(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
FROM t1 GROUP BY a;
c a (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
2 2 2
3 3 3
1 4 1,1
SELECT COUNT(*) c, a,
(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
FROM t1 GROUP BY a;
c a (SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
2 2 3
3 3 4
1 4 2,2
DROP table t1,t2;
CREATE TABLE t1 (s1 char(1)); CREATE TABLE t1 (s1 char(1));
INSERT INTO t1 VALUES ('a'); INSERT INTO t1 VALUES ('a');
SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1); SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1);
......
...@@ -203,3 +203,21 @@ select * from t1 where a is null; ...@@ -203,3 +203,21 @@ select * from t1 where a is null;
delete from t1 where a is null; delete from t1 where a is null;
select count(*) from t1; select count(*) from t1;
drop table t1; drop table t1;
#
# Bug #26186: delete order by, sometimes accept unknown column
#
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY x;
# even columns from a table not used in query (and not even existing)
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY t2.x;
# subquery (as long as the subquery from is valid or DUAL)
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY (SELECT x);
DROP TABLE t1;
...@@ -424,6 +424,14 @@ from t1; ...@@ -424,6 +424,14 @@ from t1;
drop table t1; drop table t1;
#
# Bug #27164: Crash when mixing InnoDB and MyISAM Geospatial tables
#
CREATE TABLE t1(a POINT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (NULL);
SELECT * FROM t1;
DROP TABLE t1;
--echo End of 4.1 tests --echo End of 4.1 tests
# #
......
...@@ -2764,6 +2764,25 @@ SELECT COUNT(*), a ...@@ -2764,6 +2764,25 @@ SELECT COUNT(*), a
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument
#
CREATE TABLE t1 (a int, b int);
CREATE TABLE t2 (m int, n int);
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
SELECT COUNT(*) c, a,
(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
FROM t1 GROUP BY a;
SELECT COUNT(*) c, a,
(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
FROM t1 GROUP BY a;
DROP table t1,t2;
# #
# Bug#20835 (literal string with =any values) # Bug#20835 (literal string with =any values)
# #
......
...@@ -1353,7 +1353,7 @@ class Field_geom :public Field_blob { ...@@ -1353,7 +1353,7 @@ class Field_geom :public Field_blob {
int store_decimal(const my_decimal *); int store_decimal(const my_decimal *);
void get_key_image(char *buff,uint length,imagetype type); void get_key_image(char *buff,uint length,imagetype type);
uint size_of() const { return sizeof(*this); } uint size_of() const { return sizeof(*this); }
int reset(void) { return !maybe_null(); } int reset(void) { return !maybe_null() || Field_blob::reset(); }
}; };
#endif /*HAVE_SPATIAL*/ #endif /*HAVE_SPATIAL*/
......
...@@ -1291,15 +1291,18 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array, ...@@ -1291,15 +1291,18 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
Exception is Item_direct_view_ref which we need to convert to Exception is Item_direct_view_ref which we need to convert to
Item_ref to allow fields from view being stored in tmp table. Item_ref to allow fields from view being stored in tmp table.
*/ */
Item_aggregate_ref *item_ref;
uint el= fields.elements; uint el= fields.elements;
Item *new_item, *real_itm= real_item(); Item *real_itm= real_item();
ref_pointer_array[el]= real_itm; ref_pointer_array[el]= real_itm;
if (!(new_item= new Item_aggregate_ref(&thd->lex->current_select->context, if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
ref_pointer_array + el, 0, name))) ref_pointer_array + el, 0, name)))
return; // fatal_error is set return; // fatal_error is set
if (type() == SUM_FUNC_ITEM)
item_ref->depended_from= ((Item_sum *) this)->depended_from();
fields.push_front(real_itm); fields.push_front(real_itm);
thd->change_item_tree(ref, new_item); thd->change_item_tree(ref, item_ref);
} }
} }
......
...@@ -61,9 +61,9 @@ bool Item_sum::init_sum_func_check(THD *thd) ...@@ -61,9 +61,9 @@ bool Item_sum::init_sum_func_check(THD *thd)
/* Save a pointer to object to be used in items for nested set functions */ /* Save a pointer to object to be used in items for nested set functions */
thd->lex->in_sum_func= this; thd->lex->in_sum_func= this;
nest_level= thd->lex->current_select->nest_level; nest_level= thd->lex->current_select->nest_level;
nest_level_tables_count= thd->lex->current_select->join->tables;
ref_by= 0; ref_by= 0;
aggr_level= -1; aggr_level= -1;
aggr_sel= NULL;
max_arg_level= -1; max_arg_level= -1;
max_sum_func_level= -1; max_sum_func_level= -1;
return FALSE; return FALSE;
...@@ -151,7 +151,10 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) ...@@ -151,7 +151,10 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
invalid= aggr_level < 0 && !(allow_sum_func & (1 << nest_level)); invalid= aggr_level < 0 && !(allow_sum_func & (1 << nest_level));
} }
if (!invalid && aggr_level < 0) if (!invalid && aggr_level < 0)
{
aggr_level= nest_level; aggr_level= nest_level;
aggr_sel= thd->lex->current_select;
}
/* /*
By this moment we either found a subquery where the set function is By this moment we either found a subquery where the set function is
to be aggregated and assigned a value that is >= 0 to aggr_level, to be aggregated and assigned a value that is >= 0 to aggr_level,
...@@ -212,7 +215,6 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) ...@@ -212,7 +215,6 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
bool Item_sum::register_sum_func(THD *thd, Item **ref) bool Item_sum::register_sum_func(THD *thd, Item **ref)
{ {
SELECT_LEX *sl; SELECT_LEX *sl;
SELECT_LEX *aggr_sl= NULL;
nesting_map allow_sum_func= thd->lex->allow_sum_func; nesting_map allow_sum_func= thd->lex->allow_sum_func;
for (sl= thd->lex->current_select->master_unit()->outer_select() ; for (sl= thd->lex->current_select->master_unit()->outer_select() ;
sl && sl->nest_level > max_arg_level; sl && sl->nest_level > max_arg_level;
...@@ -222,7 +224,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) ...@@ -222,7 +224,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
{ {
/* Found the most nested subquery where the function can be aggregated */ /* Found the most nested subquery where the function can be aggregated */
aggr_level= sl->nest_level; aggr_level= sl->nest_level;
aggr_sl= sl; aggr_sel= sl;
} }
} }
if (sl && (allow_sum_func & (1 << sl->nest_level))) if (sl && (allow_sum_func & (1 << sl->nest_level)))
...@@ -233,21 +235,22 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) ...@@ -233,21 +235,22 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
The set function will be aggregated in this subquery. The set function will be aggregated in this subquery.
*/ */
aggr_level= sl->nest_level; aggr_level= sl->nest_level;
aggr_sl= sl; aggr_sel= sl;
} }
if (aggr_level >= 0) if (aggr_level >= 0)
{ {
ref_by= ref; ref_by= ref;
/* Add the object to the list of registered objects assigned to aggr_sl */ /* Add the object to the list of registered objects assigned to aggr_sel */
if (!aggr_sl->inner_sum_func_list) if (!aggr_sel->inner_sum_func_list)
next= this; next= this;
else else
{ {
next= aggr_sl->inner_sum_func_list->next; next= aggr_sel->inner_sum_func_list->next;
aggr_sl->inner_sum_func_list->next= this; aggr_sel->inner_sum_func_list->next= this;
} }
aggr_sl->inner_sum_func_list= this; aggr_sel->inner_sum_func_list= this;
aggr_sl->with_sum_func= 1; aggr_sel->with_sum_func= 1;
/* /*
Mark Item_subselect(s) as containing aggregate function all the way up Mark Item_subselect(s) as containing aggregate function all the way up
...@@ -265,11 +268,11 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) ...@@ -265,11 +268,11 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
has aggregate functions directly referenced (i.e. not through a sub-select). has aggregate functions directly referenced (i.e. not through a sub-select).
*/ */
for (sl= thd->lex->current_select; for (sl= thd->lex->current_select;
sl && sl != aggr_sl && sl->master_unit()->item; sl && sl != aggr_sel && sl->master_unit()->item;
sl= sl->master_unit()->outer_select() ) sl= sl->master_unit()->outer_select() )
sl->master_unit()->item->with_sum_func= 1; sl->master_unit()->item->with_sum_func= 1;
} }
thd->lex->current_select->mark_as_dependent(aggr_sl); thd->lex->current_select->mark_as_dependent(aggr_sel);
return FALSE; return FALSE;
} }
...@@ -299,10 +302,10 @@ Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements), ...@@ -299,10 +302,10 @@ Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements),
Item_sum::Item_sum(THD *thd, Item_sum *item): Item_sum::Item_sum(THD *thd, Item_sum *item):
Item_result_field(thd, item), arg_count(item->arg_count), Item_result_field(thd, item), arg_count(item->arg_count),
aggr_sel(item->aggr_sel),
nest_level(item->nest_level), aggr_level(item->aggr_level), nest_level(item->nest_level), aggr_level(item->aggr_level),
quick_group(item->quick_group), used_tables_cache(item->used_tables_cache), quick_group(item->quick_group), used_tables_cache(item->used_tables_cache),
forced_const(item->forced_const), forced_const(item->forced_const)
nest_level_tables_count(item->nest_level_tables_count)
{ {
if (arg_count <= 2) if (arg_count <= 2)
args=tmp_args; args=tmp_args;
...@@ -449,8 +452,7 @@ void Item_sum::update_used_tables () ...@@ -449,8 +452,7 @@ void Item_sum::update_used_tables ()
used_tables_cache&= PSEUDO_TABLE_BITS; used_tables_cache&= PSEUDO_TABLE_BITS;
/* the aggregate function is aggregated into its local context */ /* the aggregate function is aggregated into its local context */
if (aggr_level == nest_level) used_tables_cache |= (1 << aggr_sel->join->tables) - 1;
used_tables_cache |= (1 << nest_level_tables_count) - 1;
} }
} }
......
...@@ -233,6 +233,7 @@ class Item_sum :public Item_result_field ...@@ -233,6 +233,7 @@ class Item_sum :public Item_result_field
Item_sum *next; /* next in the circular chain of registered objects */ Item_sum *next; /* next in the circular chain of registered objects */
uint arg_count; uint arg_count;
Item_sum *in_sum_func; /* embedding set function if any */ Item_sum *in_sum_func; /* embedding set function if any */
st_select_lex * aggr_sel; /* select where the function is aggregated */
int8 nest_level; /* number of the nesting level of the set function */ int8 nest_level; /* number of the nesting level of the set function */
int8 aggr_level; /* nesting level of the aggregating subquery */ int8 aggr_level; /* nesting level of the aggregating subquery */
int8 max_arg_level; /* max level of unbound column references */ int8 max_arg_level; /* max level of unbound column references */
...@@ -242,7 +243,6 @@ class Item_sum :public Item_result_field ...@@ -242,7 +243,6 @@ class Item_sum :public Item_result_field
protected: protected:
table_map used_tables_cache; table_map used_tables_cache;
bool forced_const; bool forced_const;
byte nest_level_tables_count;
public: public:
...@@ -365,6 +365,8 @@ class Item_sum :public Item_result_field ...@@ -365,6 +365,8 @@ class Item_sum :public Item_result_field
bool init_sum_func_check(THD *thd); bool init_sum_func_check(THD *thd);
bool check_sum_func(THD *thd, Item **ref); bool check_sum_func(THD *thd, Item **ref);
bool register_sum_func(THD *thd, Item **ref); bool register_sum_func(THD *thd, Item **ref);
st_select_lex *depended_from()
{ return (nest_level == aggr_level ? 0 : aggr_sel); }
}; };
......
...@@ -1412,9 +1412,6 @@ class THD :public Statement, ...@@ -1412,9 +1412,6 @@ class THD :public Statement,
partition_info *work_part_info; partition_info *work_part_info;
#endif #endif
/* pass up the count of "leaf" tables in a JOIN out of setup_tables() */
byte leaf_count;
THD(); THD();
~THD(); ~THD();
......
...@@ -54,6 +54,27 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ...@@ -54,6 +54,27 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
if (mysql_prepare_delete(thd, table_list, &conds)) if (mysql_prepare_delete(thd, table_list, &conds))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* check ORDER BY even if it can be ignored */
if (order && order->elements)
{
TABLE_LIST tables;
List<Item> fields;
List<Item> all_fields;
bzero((char*) &tables,sizeof(tables));
tables.table = table;
tables.alias = table_list->alias;
if (select_lex->setup_ref_array(thd, order->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables,
fields, all_fields, (ORDER*) order->first))
{
delete select;
free_underlaid_joins(thd, &thd->lex->select_lex);
DBUG_RETURN(TRUE);
}
}
const_cond= (!conds || conds->const_item()); const_cond= (!conds || conds->const_item());
safe_update=test(thd->options & OPTION_SAFE_UPDATES); safe_update=test(thd->options & OPTION_SAFE_UPDATES);
if (safe_update && const_cond) if (safe_update && const_cond)
...@@ -155,23 +176,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ...@@ -155,23 +176,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
{ {
uint length= 0; uint length= 0;
SORT_FIELD *sortorder; SORT_FIELD *sortorder;
TABLE_LIST tables;
List<Item> fields;
List<Item> all_fields;
ha_rows examined_rows; ha_rows examined_rows;
bzero((char*) &tables,sizeof(tables));
tables.table = table;
tables.alias = table_list->alias;
if (select_lex->setup_ref_array(thd, order->elements) ||
setup_order(thd, select_lex->ref_pointer_array, &tables,
fields, all_fields, (ORDER*) order->first))
{
delete select;
free_underlaid_joins(thd, &thd->lex->select_lex);
DBUG_RETURN(TRUE);
}
if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR) if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR)
usable_index= get_index_for_order(table, (ORDER*)(order->first), limit); usable_index= get_index_for_order(table, (ORDER*)(order->first), limit);
......
...@@ -2466,14 +2466,12 @@ bool mysql_insert_select_prepare(THD *thd) ...@@ -2466,14 +2466,12 @@ bool mysql_insert_select_prepare(THD *thd)
DBUG_ASSERT(select_lex->leaf_tables != 0); DBUG_ASSERT(select_lex->leaf_tables != 0);
lex->leaf_tables_insert= select_lex->leaf_tables; lex->leaf_tables_insert= select_lex->leaf_tables;
/* skip all leaf tables belonged to view where we are insert */ /* skip all leaf tables belonged to view where we are insert */
for (first_select_leaf_table= select_lex->leaf_tables->next_leaf, for (first_select_leaf_table= select_lex->leaf_tables->next_leaf;
thd->leaf_count --;
first_select_leaf_table && first_select_leaf_table &&
first_select_leaf_table->belong_to_view && first_select_leaf_table->belong_to_view &&
first_select_leaf_table->belong_to_view == first_select_leaf_table->belong_to_view ==
lex->leaf_tables_insert->belong_to_view; lex->leaf_tables_insert->belong_to_view;
first_select_leaf_table= first_select_leaf_table->next_leaf, first_select_leaf_table= first_select_leaf_table->next_leaf)
thd->leaf_count --)
{} {}
select_lex->leaf_tables= first_select_leaf_table; select_lex->leaf_tables= first_select_leaf_table;
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -413,7 +413,12 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -413,7 +413,12 @@ JOIN::prepare(Item ***rref_pointer_array,
tables_list, &select_lex->leaf_tables, tables_list, &select_lex->leaf_tables,
FALSE, SELECT_ACL, SELECT_ACL)) FALSE, SELECT_ACL, SELECT_ACL))
DBUG_RETURN(-1); DBUG_RETURN(-1);
tables= thd->leaf_count;
TABLE_LIST *table_ptr;
for (table_ptr= select_lex->leaf_tables;
table_ptr;
table_ptr= table_ptr->next_leaf)
tables++;
if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) || if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) ||
select_lex->setup_ref_array(thd, og_num) || select_lex->setup_ref_array(thd, og_num) ||
...@@ -9417,13 +9422,19 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9417,13 +9422,19 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
{ {
if (item->with_sum_func && type != Item::SUM_FUNC_ITEM) if (item->with_sum_func && type != Item::SUM_FUNC_ITEM)
{ {
/* if (item->used_tables() & OUTER_REF_TABLE_BIT)
Mark that the we have ignored an item that refers to a summary item->update_used_tables();
function. We need to know this if someone is going to use if (type == Item::SUBSELECT_ITEM ||
DISTINCT on the result. (item->used_tables() & ~OUTER_REF_TABLE_BIT))
*/ {
param->using_indirect_summary_function=1; /*
continue; Mark that the we have ignored an item that refers to a summary
function. We need to know this if someone is going to use
DISTINCT on the result.
*/
param->using_indirect_summary_function=1;
continue;
}
} }
if (item->const_item() && (int) hidden_field_count <= 0) if (item->const_item() && (int) hidden_field_count <= 0)
continue; // We don't have to store this continue; // We don't have to store this
...@@ -9608,6 +9619,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ...@@ -9608,6 +9619,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
share->default_values= table->record[1]+alloc_length; share->default_values= table->record[1]+alloc_length;
} }
copy_func[0]=0; // End marker copy_func[0]=0; // End marker
param->func_count= copy_func - param->items_to_copy;
setup_tmp_table_column_bitmaps(table, bitmaps); setup_tmp_table_column_bitmaps(table, bitmaps);
...@@ -13824,6 +13836,7 @@ count_field_types(TMP_TABLE_PARAM *param, List<Item> &fields, ...@@ -13824,6 +13836,7 @@ count_field_types(TMP_TABLE_PARAM *param, List<Item> &fields,
if (!sum_item->quick_group) if (!sum_item->quick_group)
param->quick_group=0; // UDF SUM function param->quick_group=0; // UDF SUM function
param->sum_func_count++; param->sum_func_count++;
param->func_count++;
for (uint i=0 ; i < sum_item->arg_count ; i++) for (uint i=0 ; i < sum_item->arg_count ; i++)
{ {
......
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