Commit 53bfeb48 authored by unknown's avatar unknown

Fix for Bug#5615 and merge from 4.1



mysql-test/r/func_group.result:
  Added some tests and fix for Bug#5615.
mysql-test/r/show_check.result:
  Fix for Bug#5615.
mysql-test/t/func_group.test:
  Added some tests.
sql/item_sum.cc:
  Fix for Bug#5615.
sql/item_sum.h:
  Fix for Bug#5615.
sql/sql_select.cc:
  Fix for Bug#5615.
sql/sql_select.h:
  Fix for Bug#5615.
parent 42557374
......@@ -669,12 +669,24 @@ select charset(max(a)), coercibility(max(a)),
charset(min(a)), coercibility(min(a)) from t1;
charset(max(a)) coercibility(max(a)) charset(min(a)) coercibility(min(a))
latin2 2 latin2 2
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(1) character set latin2 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
create table t2 select max(a),min(a) from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`max(a)` varchar(1) character set latin2 default NULL,
`min(a)` varchar(1) character set latin2 default NULL
`max(a)` char(1) character set latin2 default NULL,
`min(a)` char(1) character set latin2 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t2;
create table t2 select concat(a) from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`concat(a)` varchar(1) character set latin2 default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t2,t1;
create table t1 (a int);
......
......@@ -252,11 +252,9 @@ type_bool type_tiny type_short type_mediumint type_bigint type_decimal type_nume
drop table t1;
create table t1 (a int not null);
create table t2 select max(a) from t1;
Warnings:
Warning 1263 Data truncated; NULL supplied to NOT NULL column 'max(a)' at row 1
show columns from t2;
Field Type Null Key Default Extra
max(a) int(11) 0
max(a) int(11) YES NULL
drop table t1,t2;
create table t1 (c decimal, d double, f float, r real);
show columns from t1;
......
......@@ -395,8 +395,12 @@ create table t1 (a char character set latin2);
insert into t1 values ('a'),('b');
select charset(max(a)), coercibility(max(a)),
charset(min(a)), coercibility(min(a)) from t1;
show create table t1;
create table t2 select max(a),min(a) from t1;
show create table t2;
drop table t2;
create table t2 select concat(a) from t1;
show create table t2;
drop table t2,t1;
#
......
......@@ -22,6 +22,7 @@
#endif
#include "mysql_priv.h"
#include "sql_select.h"
Item_sum::Item_sum(List<Item> &list)
:arg_count(list.elements)
......@@ -303,6 +304,21 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return FALSE;
}
Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table,
uint convert_blob_length)
{
if (args[0]->type() == Item::FIELD_ITEM)
{
Field *field= ((Item_field*) args[0])->field;
if ((field= create_tmp_field_from_field(current_thd, field, this, table,
0, convert_blob_length)))
field->flags&= ~NOT_NULL_FLAG;
return field;
}
return Item_sum::create_tmp_field(group, table, convert_blob_length);
}
/***********************************************************************
** reset and add of sum_func
......@@ -2075,8 +2091,6 @@ my_decimal *Item_variance_field::val_decimal(my_decimal *dec_buf)
** COUNT(DISTINCT ...)
****************************************************************************/
#include "sql_select.h"
int simple_str_key_cmp(void* arg, byte* key1, byte* key2)
{
Item_sum_count_distinct* item = (Item_sum_count_distinct*)arg;
......
......@@ -94,7 +94,6 @@ class Item_sum :public Item_result_field
Item *get_tmp_table_item(THD *thd);
virtual Field *create_tmp_field(bool group, TABLE *table,
uint convert_blob_length);
bool walk (Item_processor processor, byte *argument);
};
......@@ -525,6 +524,8 @@ class Item_sum_hybrid :public Item_sum
void cleanup();
bool any_value() { return was_values; }
void no_rows_in_result();
Field *create_tmp_field(bool group, TABLE *table,
uint convert_blob_length);
};
......
......@@ -7593,10 +7593,10 @@ const_expression_in_where(COND *cond, Item *comp_item, Item **const_item)
new_created field
*/
static Field* create_tmp_field_from_field(THD *thd, Field* org_field,
Item *item, TABLE *table,
bool modify_item,
uint convert_blob_length)
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
Item *item, TABLE *table,
bool modify_item,
uint convert_blob_length)
{
Field *new_field;
......
......@@ -399,6 +399,10 @@ void copy_funcs(Item **func_ptr);
bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
int error, bool ignore_last_dupp_error);
uint find_shortest_key(TABLE *table, const key_map *usable_keys);
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
Item *item, TABLE *table,
bool modify_item,
uint convert_blob_length);
/* functions from opt_sum.cc */
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
......
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