Merge epotemkin@bk-internal.mysql.com:/home/bk/mysql-5.0
into moonbone.local:/work/tmp_merge-5.0-opt-mysql mysql-test/r/rpl_insert_id.result: Auto merged mysql-test/t/rpl_insert_id.test: Auto merged sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_insert.cc: Auto merged sql/sql_select.cc: Auto merged
This commit is contained in:
commit
805c33a5e1
@ -1038,6 +1038,21 @@ select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
|
||||
f1 f2
|
||||
test a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (a varchar(10));
|
||||
INSERT INTO t1 VALUES ('abc'), ('xyz');
|
||||
SELECT a, CONCAT(a,' ',a) AS c FROM t1
|
||||
HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
|
||||
a c
|
||||
abc abc abc
|
||||
xyz xyz xyz
|
||||
SELECT a, CONCAT(a,' ',a) AS c FROM t1
|
||||
HAVING LEFT(CONCAT(a,' ',a),
|
||||
LENGTH(CONCAT(a,' ',a))-
|
||||
INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
|
||||
a c
|
||||
abc abc abc
|
||||
xyz xyz xyz
|
||||
DROP TABLE t1;
|
||||
End of 4.1 tests
|
||||
create table t1 (d decimal default null);
|
||||
insert into t1 values (null);
|
||||
|
@ -14,3 +14,14 @@ explain select * from t1 where b is null;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
|
||||
INSERT INTO t1 VALUES (NULL);
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1 WHERE a IS NULL;
|
||||
a last_insert_id()
|
||||
1 1
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1 WHERE a IS NULL;
|
||||
a last_insert_id()
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1;
|
||||
a last_insert_id()
|
||||
1 1
|
||||
DROP TABLE t1;
|
||||
|
@ -74,6 +74,19 @@ SET FOREIGN_KEY_CHECKS=0;
|
||||
INSERT INTO t1 VALUES (1),(1);
|
||||
ERROR 23000: Duplicate entry '1' for key 1
|
||||
drop table t1;
|
||||
create table t1(a int auto_increment, key(a));
|
||||
create table t2(a int);
|
||||
insert into t1 (a) values (null);
|
||||
insert into t2 (a) select a from t1 where a is null;
|
||||
insert into t2 (a) select a from t1 where a is null;
|
||||
select * from t2;
|
||||
a
|
||||
1
|
||||
select * from t2;
|
||||
a
|
||||
1
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop function if exists bug15728;
|
||||
drop function if exists bug15728_insert;
|
||||
drop table if exists t1, t2;
|
||||
|
@ -3395,3 +3395,6 @@ a t1.b + 0 t1.c + 0 a t2.b + 0 c d
|
||||
1 0 1 1 0 1 NULL
|
||||
2 0 1 NULL NULL NULL NULL
|
||||
drop table t1,t2;
|
||||
SELECT 0.9888889889 * 1.011111411911;
|
||||
0.9888889889 * 1.011111411911
|
||||
0.9998769417899202067879
|
||||
|
@ -2735,4 +2735,31 @@ m e
|
||||
4 a
|
||||
1 b
|
||||
DROP VIEW v1;
|
||||
DROP TABLE IF EXISTS t1,t2;
|
||||
DROP TABLE t1,t2;
|
||||
CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
|
||||
CREATE VIEW v1 AS SELECT a, b FROM t1;
|
||||
INSERT INTO v1 (b) VALUES (2);
|
||||
Warnings:
|
||||
Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value
|
||||
SET SQL_MODE = STRICT_ALL_TABLES;
|
||||
INSERT INTO v1 (b) VALUES (4);
|
||||
ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value
|
||||
SET SQL_MODE = '';
|
||||
SELECT * FROM t1;
|
||||
a b
|
||||
0 2
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (firstname text, surname text);
|
||||
INSERT INTO t1 VALUES
|
||||
("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns");
|
||||
CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1;
|
||||
SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")),
|
||||
LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1
|
||||
FROM v1;
|
||||
f1
|
||||
BartBart
|
||||
Milhouse vanMilhouse van
|
||||
MontgomeryMontgomery
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
@ -685,6 +685,23 @@ select * from t1 where f1='test' and (f2= sha("test") or f2= sha("TEST"));
|
||||
select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug#18243: REVERSE changes its argument
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (a varchar(10));
|
||||
INSERT INTO t1 VALUES ('abc'), ('xyz');
|
||||
|
||||
SELECT a, CONCAT(a,' ',a) AS c FROM t1
|
||||
HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
|
||||
|
||||
SELECT a, CONCAT(a,' ',a) AS c FROM t1
|
||||
HAVING LEFT(CONCAT(a,' ',a),
|
||||
LENGTH(CONCAT(a,' ',a))-
|
||||
INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 4.1 tests
|
||||
|
||||
#
|
||||
|
@ -21,4 +21,14 @@ select * from t1 where a is null;
|
||||
explain select * from t1 where b is null;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug #14553: NULL in WHERE resets LAST_INSERT_ID
|
||||
#
|
||||
CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
|
||||
INSERT INTO t1 VALUES (NULL);
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1 WHERE a IS NULL;
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1 WHERE a IS NULL;
|
||||
SELECT sql_no_cache a, last_insert_id() FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
# End of 4.1 tests
|
||||
|
@ -77,6 +77,24 @@ sync_slave_with_master;
|
||||
connection master;
|
||||
drop table t1;
|
||||
sync_slave_with_master;
|
||||
|
||||
#
|
||||
# Bug#14553: NULL in WHERE resets LAST_INSERT_ID
|
||||
#
|
||||
connection master;
|
||||
create table t1(a int auto_increment, key(a));
|
||||
create table t2(a int);
|
||||
insert into t1 (a) values (null);
|
||||
insert into t2 (a) select a from t1 where a is null;
|
||||
insert into t2 (a) select a from t1 where a is null;
|
||||
select * from t2;
|
||||
sync_slave_with_master;
|
||||
connection slave;
|
||||
select * from t2;
|
||||
connection master;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
sync_slave_with_master;
|
||||
# End of 4.1 tests
|
||||
|
||||
|
||||
|
@ -2901,3 +2901,8 @@ from t1 left outer join t2 on t1.a = t2.c and t2.b <> 1
|
||||
where t1.b <> 1 order by t1.a;
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
#
|
||||
# Bug #20569: Garbage in DECIMAL results from some mathematical functions
|
||||
#
|
||||
SELECT 0.9888889889 * 1.011111411911;
|
||||
|
@ -2595,4 +2595,38 @@ CREATE TABLE t2 SELECT * FROM v1;
|
||||
SELECT * FROM t2;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE IF EXISTS t1,t2;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
#
|
||||
# Bug#16110: insert permitted into view col w/o default value
|
||||
#
|
||||
CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
|
||||
CREATE VIEW v1 AS SELECT a, b FROM t1;
|
||||
|
||||
INSERT INTO v1 (b) VALUES (2);
|
||||
|
||||
SET SQL_MODE = STRICT_ALL_TABLES;
|
||||
--error 1423
|
||||
INSERT INTO v1 (b) VALUES (4);
|
||||
SET SQL_MODE = '';
|
||||
|
||||
SELECT * FROM t1;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug #18243: expression over a view column that with the REVERSE function
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (firstname text, surname text);
|
||||
INSERT INTO t1 VALUES
|
||||
("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns");
|
||||
|
||||
CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1;
|
||||
SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")),
|
||||
LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1
|
||||
FROM v1;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
11
sql/item.h
11
sql/item.h
@ -697,9 +697,16 @@ public:
|
||||
Any new item which can be NULL must implement this call.
|
||||
*/
|
||||
virtual bool is_null() { return 0; }
|
||||
|
||||
/*
|
||||
it is "top level" item of WHERE clause and we do not need correct NULL
|
||||
handling
|
||||
Inform the item that there will be no distinction between its result
|
||||
being FALSE or NULL.
|
||||
|
||||
NOTE
|
||||
This function will be called for eg. Items that are top-level AND-parts
|
||||
of the WHERE clause. Items implementing this function (currently
|
||||
Item_cond_and and subquery-related item) enable special optimizations
|
||||
when they are "top level".
|
||||
*/
|
||||
virtual void top_level_item() {}
|
||||
/*
|
||||
|
@ -752,44 +752,47 @@ String *Item_func_reverse::val_str(String *str)
|
||||
{
|
||||
DBUG_ASSERT(fixed == 1);
|
||||
String *res = args[0]->val_str(str);
|
||||
char *ptr,*end;
|
||||
char *ptr, *end, *tmp;
|
||||
|
||||
if ((null_value=args[0]->null_value))
|
||||
return 0;
|
||||
/* An empty string is a special case as the string pointer may be null */
|
||||
if (!res->length())
|
||||
return &my_empty_string;
|
||||
res=copy_if_not_alloced(str,res,res->length());
|
||||
ptr = (char *) res->ptr();
|
||||
end=ptr+res->length();
|
||||
if (tmp_value.alloced_length() < res->length() &&
|
||||
tmp_value.realloc(res->length()))
|
||||
{
|
||||
null_value= 1;
|
||||
return 0;
|
||||
}
|
||||
tmp_value.length(res->length());
|
||||
tmp_value.set_charset(res->charset());
|
||||
ptr= (char *) res->ptr();
|
||||
end= ptr + res->length();
|
||||
tmp= (char *) tmp_value.ptr() + tmp_value.length();
|
||||
#ifdef USE_MB
|
||||
if (use_mb(res->charset()))
|
||||
{
|
||||
String tmpstr;
|
||||
tmpstr.copy(*res);
|
||||
char *tmp = (char *) tmpstr.ptr() + tmpstr.length();
|
||||
register uint32 l;
|
||||
while (ptr < end)
|
||||
{
|
||||
if ((l=my_ismbchar(res->charset(), ptr,end)))
|
||||
tmp-=l, memcpy(tmp,ptr,l), ptr+=l;
|
||||
if ((l= my_ismbchar(res->charset(),ptr,end)))
|
||||
{
|
||||
tmp-= l;
|
||||
memcpy(tmp,ptr,l);
|
||||
ptr+= l;
|
||||
}
|
||||
else
|
||||
*--tmp=*ptr++;
|
||||
*--tmp= *ptr++;
|
||||
}
|
||||
memcpy((char *) res->ptr(),(char *) tmpstr.ptr(), res->length());
|
||||
}
|
||||
else
|
||||
#endif /* USE_MB */
|
||||
{
|
||||
char tmp;
|
||||
while (ptr < end)
|
||||
{
|
||||
tmp=*ptr;
|
||||
*ptr++=*--end;
|
||||
*end=tmp;
|
||||
}
|
||||
*--tmp= *ptr++;
|
||||
}
|
||||
return res;
|
||||
return &tmp_value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,6 +102,7 @@ public:
|
||||
|
||||
class Item_func_reverse :public Item_str_func
|
||||
{
|
||||
String tmp_value;
|
||||
public:
|
||||
Item_func_reverse(Item *a) :Item_str_func(a) {}
|
||||
String *val_str(String *);
|
||||
|
@ -269,6 +269,7 @@ THD::THD()
|
||||
tablespace_op=FALSE;
|
||||
ulong tmp=sql_rnd_with_mutex();
|
||||
randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id);
|
||||
substitute_null_with_insert_id = FALSE;
|
||||
thr_lock_info_init(&lock_info); /* safety: will be reset after start */
|
||||
thr_lock_owner_init(&main_lock_id, &lock_info);
|
||||
}
|
||||
|
@ -1324,6 +1324,8 @@ public:
|
||||
bool no_errors, password, is_fatal_error;
|
||||
bool query_start_used, rand_used, time_zone_used;
|
||||
bool last_insert_id_used,insert_id_used, clear_next_insert_id;
|
||||
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
|
||||
bool substitute_null_with_insert_id;
|
||||
bool in_lock_tables;
|
||||
bool query_error, bootstrap, cleanup_done;
|
||||
bool tmp_table_used;
|
||||
@ -1455,6 +1457,7 @@ public:
|
||||
{
|
||||
last_insert_id= id_arg;
|
||||
insert_id_used=1;
|
||||
substitute_null_with_insert_id= TRUE;
|
||||
}
|
||||
inline ulonglong insert_id(void)
|
||||
{
|
||||
|
@ -755,6 +755,7 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
|
||||
uint used_fields_buff_size= (table->s->fields + 7) / 8;
|
||||
uchar *used_fields_buff= (uchar*)thd->alloc(used_fields_buff_size);
|
||||
MY_BITMAP used_fields;
|
||||
bool save_set_query_id= thd->set_query_id;
|
||||
DBUG_ENTER("check_key_in_view");
|
||||
|
||||
if (!used_fields_buff)
|
||||
@ -767,15 +768,26 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
|
||||
bitmap_clear_all(&used_fields);
|
||||
|
||||
view->contain_auto_increment= 0;
|
||||
/*
|
||||
we must not set query_id for fields as they're not
|
||||
really used in this context
|
||||
*/
|
||||
thd->set_query_id= 0;
|
||||
/* check simplicity and prepare unique test of view */
|
||||
for (trans= trans_start; trans != trans_end; trans++)
|
||||
{
|
||||
if (!trans->item->fixed && trans->item->fix_fields(thd, &trans->item))
|
||||
return TRUE;
|
||||
{
|
||||
thd->set_query_id= save_set_query_id;
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
Item_field *field;
|
||||
/* simple SELECT list entry (field without expression) */
|
||||
if (!(field= trans->item->filed_for_view_update()))
|
||||
{
|
||||
thd->set_query_id= save_set_query_id;
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (field->field->unireg_check == Field::NEXT_NUMBER)
|
||||
view->contain_auto_increment= 1;
|
||||
/* prepare unique test */
|
||||
@ -785,6 +797,7 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
|
||||
*/
|
||||
trans->item= field;
|
||||
}
|
||||
thd->set_query_id= save_set_query_id;
|
||||
/* unique test */
|
||||
for (trans= trans_start; trans != trans_end; trans++)
|
||||
{
|
||||
|
@ -7854,7 +7854,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
|
||||
Field *field=((Item_field*) args[0])->field;
|
||||
if (field->flags & AUTO_INCREMENT_FLAG && !field->table->maybe_null &&
|
||||
(thd->options & OPTION_AUTO_IS_NULL) &&
|
||||
thd->insert_id())
|
||||
thd->insert_id() && thd->substitute_null_with_insert_id)
|
||||
{
|
||||
#ifdef HAVE_QUERY_CACHE
|
||||
query_cache_abort(&thd->net);
|
||||
@ -7873,7 +7873,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
|
||||
*/
|
||||
cond->fix_fields(thd, &cond);
|
||||
}
|
||||
thd->insert_id(0); // Clear for next request
|
||||
thd->substitute_null_with_insert_id= FALSE; // Clear for next request
|
||||
}
|
||||
/* fix to replace 'NULL' dates with '0' (shreeve@uci.edu) */
|
||||
else if (((field->type() == FIELD_TYPE_DATE) ||
|
||||
|
@ -171,6 +171,7 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={
|
||||
do \
|
||||
{ \
|
||||
dec1 a=(from1)+(from2)+(carry); \
|
||||
DBUG_ASSERT((carry) <= 1); \
|
||||
if (((carry)= a >= DIG_BASE)) /* no division here! */ \
|
||||
a-=DIG_BASE; \
|
||||
(to)=a; \
|
||||
@ -179,7 +180,7 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={
|
||||
#define ADD2(to, from1, from2, carry) \
|
||||
do \
|
||||
{ \
|
||||
dec1 a=(from1)+(from2)+(carry); \
|
||||
dec2 a=((dec2)(from1))+(from2)+(carry); \
|
||||
if (((carry)= a >= DIG_BASE)) \
|
||||
a-=DIG_BASE; \
|
||||
if (unlikely(a >= DIG_BASE)) \
|
||||
@ -187,7 +188,7 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={
|
||||
a-=DIG_BASE; \
|
||||
carry++; \
|
||||
} \
|
||||
(to)=a; \
|
||||
(to)=(dec1) a; \
|
||||
} while(0)
|
||||
|
||||
#define SUB(to, from1, from2, carry) /* to=from1-from2 */ \
|
||||
@ -1998,7 +1999,13 @@ int decimal_mul(decimal_t *from1, decimal_t *from2, decimal_t *to)
|
||||
ADD2(*buf0, *buf0, lo, carry);
|
||||
carry+=hi;
|
||||
}
|
||||
for (; carry; buf0--)
|
||||
if (carry)
|
||||
{
|
||||
if (buf0 < to->buf)
|
||||
return E_DEC_OVERFLOW;
|
||||
ADD2(*buf0, *buf0, 0, carry);
|
||||
}
|
||||
for (buf0--; carry; buf0--)
|
||||
{
|
||||
if (buf0 < to->buf)
|
||||
return E_DEC_OVERFLOW;
|
||||
|
Loading…
x
Reference in New Issue
Block a user