Commit 40609c75 authored by unknown's avatar unknown

Merge bk@192.168.21.1:mysql-5.0-opt

into  mysql.com:/home/hf/work/mrg/mysql-5.0-opt
parents f8b24de4 a6bf4308
......@@ -447,8 +447,8 @@ t2 CREATE TABLE `t2` (
`ifnull(c,c)` mediumint(8) default NULL,
`ifnull(d,d)` int(11) default NULL,
`ifnull(e,e)` bigint(20) default NULL,
`ifnull(f,f)` float(24,2) default NULL,
`ifnull(g,g)` double(53,3) default NULL,
`ifnull(f,f)` float(3,2) default NULL,
`ifnull(g,g)` double(4,3) default NULL,
`ifnull(h,h)` decimal(5,4) default NULL,
`ifnull(i,i)` year(4) default NULL,
`ifnull(j,j)` date default NULL,
......
......@@ -744,3 +744,32 @@ f1 f2
2 2
10 10
DROP TABLE t1, t2;
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
CREATE TABLE t2 (d VARCHAR(10));
INSERT INTO t1 (c) VALUES ('7_chars'), ('13_characters');
EXPLAIN
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY t1 ref ix_c ix_c 13 const 1 Using where
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
(SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters')
13
13
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='7_chars') FROM t1;
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1))
FROM t1;
SELECT * FROM t2;
d
13
13
7
7
20
20
DROP TABLE t1,t2;
......@@ -152,3 +152,24 @@ SELECT * FROM t1;
i
DROP TABLE t1;
End of 4.1 tests.
CREATE TABLE t1 ( c FLOAT( 20, 14 ) );
INSERT INTO t1 VALUES( 12139 );
CREATE TABLE t2 ( c FLOAT(30,18) );
INSERT INTO t2 VALUES( 123456 );
SELECT AVG( c ) FROM t1 UNION SELECT 1;
AVG( c )
12139
1
SELECT 1 UNION SELECT AVG( c ) FROM t1;
1
1
12139
SELECT 1 UNION SELECT * FROM t2 UNION SELECT 1;
1
1
123456
SELECT c/1 FROM t1 UNION SELECT 1;
c/1
12139
1
DROP TABLE t1, t2;
......@@ -92,7 +92,7 @@ show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`col1` double default NULL,
`col2` double(53,5) default NULL,
`col2` double(22,5) default NULL,
`col3` double default NULL,
`col4` double default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
......@@ -232,12 +232,12 @@ insert into t2 values ("1.23456780");
create table t3 select * from t2 union select * from t1;
select * from t3;
d
1.234567800
100000000.000000000
1.2345678
100000000
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`d` double(22,9) default NULL
`d` double default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3;
create table t1 select 105213674794682365.00 + 0.0 x;
......
......@@ -554,7 +554,7 @@ aa
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` varbinary(20) NOT NULL default ''
`a` varbinary(2) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT 12 as a UNION select 12.2 as a;
......@@ -655,7 +655,7 @@ f
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f` varbinary(24) default NULL
`f` varbinary(12) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT y from t2 UNION select da from t2;
......
......@@ -306,4 +306,29 @@ INSERT INTO t2 (f1, f2)
SELECT * FROM t2;
DROP TABLE t1, t2;
#
# Bug #26207: inserts don't work with shortened index
#
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
CREATE TABLE t2 (d VARCHAR(10));
INSERT INTO t1 (c) VALUES ('7_chars'), ('13_characters');
EXPLAIN
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='7_chars') FROM t1;
INSERT INTO t2 (d)
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1))
FROM t1;
SELECT * FROM t2;
DROP TABLE t1,t2;
......@@ -163,3 +163,19 @@ DROP TABLE t1;
--echo End of 4.1 tests.
#
# Bug #24791: Union with AVG-groups generates wrong results
#
CREATE TABLE t1 ( c FLOAT( 20, 14 ) );
INSERT INTO t1 VALUES( 12139 );
CREATE TABLE t2 ( c FLOAT(30,18) );
INSERT INTO t2 VALUES( 123456 );
SELECT AVG( c ) FROM t1 UNION SELECT 1;
SELECT 1 UNION SELECT AVG( c ) FROM t1;
SELECT 1 UNION SELECT * FROM t2 UNION SELECT 1;
SELECT c/1 FROM t1 UNION SELECT 1;
DROP TABLE t1, t2;
......@@ -432,6 +432,7 @@ class Field_real :public Field_num {
int store_decimal(const my_decimal *);
my_decimal *val_decimal(my_decimal *);
uint32 max_display_length() { return field_length; }
};
......@@ -461,7 +462,6 @@ class Field_decimal :public Field_real {
void overflow(bool negative);
bool zero_pack() const { return 0; }
void sql_type(String &str) const;
uint32 max_display_length() { return field_length; }
};
......@@ -719,7 +719,6 @@ class Field_float :public Field_real {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(float); }
void sql_type(String &str) const;
uint32 max_display_length() { return 24; }
};
......@@ -762,7 +761,6 @@ class Field_double :public Field_real {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(double); }
void sql_type(String &str) const;
uint32 max_display_length() { return 53; }
uint size_of() const { return sizeof(*this); }
};
......
......@@ -6348,8 +6348,6 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item)
:Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
{
DBUG_ASSERT(item->fixed);
max_length= display_length(item);
maybe_null= item->maybe_null;
collation.set(item->collation);
get_full_info(item);
......@@ -6521,11 +6519,17 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
{
int delta1= max_length_orig - decimals_orig;
int delta2= item->max_length - item->decimals;
if (fld_type == MYSQL_TYPE_DECIMAL)
max_length= max(delta1, delta2) + decimals;
else
max_length= min(max(delta1, delta2) + decimals,
(fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7);
max_length= max(delta1, delta2) + decimals;
if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
{
max_length= FLT_DIG + 6;
decimals= NOT_FIXED_DEC;
}
if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
{
max_length= DBL_DIG + 7;
decimals= NOT_FIXED_DEC;
}
}
else
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
......
......@@ -1121,8 +1121,10 @@ void Item_sum_avg::fix_length_and_dec()
f_scale= args[0]->decimals;
dec_bin_size= my_decimal_get_binary_size(f_precision, f_scale);
}
else
else {
decimals= min(args[0]->decimals + prec_increment, NOT_FIXED_DEC);
max_length= args[0]->max_length + prec_increment;
}
}
......
......@@ -488,15 +488,11 @@ extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
class store_key :public Sql_alloc
{
protected:
Field *to_field; // Store data here
char *null_ptr;
char err;
public:
bool null_key; /* TRUE <=> the value of the key has a null part */
enum store_key_result { STORE_KEY_OK, STORE_KEY_FATAL, STORE_KEY_CONV };
store_key(THD *thd, Field *field_arg, char *ptr, char *null, uint length)
:null_ptr(null), err(0), null_key(0)
:null_key(0), null_ptr(null), err(0)
{
if (field_arg->type() == FIELD_TYPE_BLOB)
{
......@@ -510,8 +506,35 @@ class store_key :public Sql_alloc
ptr, (uchar*) null, 1);
}
virtual ~store_key() {} /* Not actually needed */
virtual enum store_key_result copy()=0;
virtual const char *name() const=0;
/**
@brief sets ignore truncation warnings mode and calls the real copy method
@details this function makes sure truncation warnings when preparing the
key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
*/
enum store_key_result copy()
{
enum store_key_result result;
enum_check_fields saved_count_cuted_fields=
to_field->table->in_use->count_cuted_fields;
to_field->table->in_use->count_cuted_fields= CHECK_FIELD_IGNORE;
result= copy_inner();
to_field->table->in_use->count_cuted_fields= saved_count_cuted_fields;
return result;
}
protected:
Field *to_field; // Store data here
char *null_ptr;
char err;
virtual enum store_key_result copy_inner()=0;
};
......@@ -531,13 +554,15 @@ class store_key_field: public store_key
copy_field.set(to_field,from_field,0);
}
}
enum store_key_result copy()
const char *name() const { return field_name; }
protected:
enum store_key_result copy_inner()
{
copy_field.do_copy(&copy_field);
null_key= to_field->is_null();
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
}
const char *name() const { return field_name; }
};
......@@ -552,13 +577,15 @@ class store_key_item :public store_key
null_ptr_arg ? null_ptr_arg : item_arg->maybe_null ?
&err : NullS, length), item(item_arg)
{}
enum store_key_result copy()
const char *name() const { return "func"; }
protected:
enum store_key_result copy_inner()
{
int res= item->save_in_field(to_field, 1);
null_key= to_field->is_null() || item->null_value;
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
}
const char *name() const { return "func"; }
};
......@@ -574,7 +601,10 @@ class store_key_const_item :public store_key_item
&err : NullS, length, item_arg), inited(0)
{
}
enum store_key_result copy()
const char *name() const { return "const"; }
protected:
enum store_key_result copy_inner()
{
int res;
if (!inited)
......@@ -589,7 +619,6 @@ class store_key_const_item :public store_key_item
null_key= to_field->is_null() || item->null_value;
return (err > 2 ? STORE_KEY_FATAL : (store_key_result) err);
}
const char *name() const { return "const"; }
};
bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
......
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