From e08ff11534c4ca13eea46590841fc38ec72b3462 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Jul 2006 12:10:12 +0300 Subject: [PATCH 1/8] Bug #16110: insert permitted into view col w/o default value When compiling INSERT statements the check whether columns are provided values depends on the flag whether a field is used in that query (Field::query_id). However the check for updatability of VIEW columns (check_view_insertability()) was calling fix_fields() and thus setting the Field::query_id even for the view fields that are not referenced in the current INSERT statement. So the correct check for columns without default values ( check_that_all_fields_are_given_values() ) is assuming that all the VIEW columns were mentioned in the INSERT field list and was issuing no warnings or errors. Fixed check_view_insertability() to turn off the flag whether or not to set Field::query_id (THREAD::set_query_id) before calling fix fields and restore it when it's done. mysql-test/r/view.result: Bug #16110: insert permitted into view col w/o default value * test case mysql-test/t/view.test: Bug #16110: insert permitted into view col w/o default value * test case sql/sql_insert.cc: Bug #16110: insert permitted into view col w/o default value * avoid setting the "field used" flag for fields when checking view columns for updatability. * a missing DBUG_RETURN added. --- mysql-test/r/view.result | 16 +++++++++++++++- mysql-test/t/view.test | 20 +++++++++++++++++++- sql/sql_insert.cc | 15 ++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 5bb407f4256..3cb89a995a1 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2735,4 +2735,18 @@ 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; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index a1c1e9b2ad1..18ba85d3408 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2595,4 +2595,22 @@ 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; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8ffc6f53a43..26521fd65a6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -675,6 +675,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) @@ -687,15 +688,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 */ @@ -705,6 +717,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++) { From 1401c2c71c5a99a6ac8e340138c5569fabd3f42e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Jul 2006 13:28:30 +0400 Subject: [PATCH 2/8] Better comments for void Item::top_level_item() --- sql/item.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sql/item.h b/sql/item.h index eca8ee184a1..3eab695cb5e 100644 --- a/sql/item.h +++ b/sql/item.h @@ -275,9 +275,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() {} /* From 8e354677a81580fc7bd1ba4e3f6c7c426ed08c42 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Jul 2006 13:18:05 +0300 Subject: [PATCH 3/8] Bug #20569 Garbage in DECIMAL results from some mathematical functions Adding decimal "digits" in multiplication resulted in signed overflow and producing wrong results. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed by using large enough buffers and intermediary result types : dec2 (currently longlong) to hold result of adding decimal "digits" (currently int32). mysql-test/r/select.result: Bug #20569 Garbage in DECIMAL results from some mathematical functions * test suite for the bug mysql-test/t/select.test: Bug #20569 Garbage in DECIMAL results from some mathematical functions * test suite for the bug strings/decimal.c: Bug #20569 Garbage in DECIMAL results from some mathematical functions * fixed the overflow in adding decimal "digits" --- mysql-test/r/select.result | 3 +++ mysql-test/t/select.test | 5 +++++ strings/decimal.c | 13 ++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index e6c590489a0..7f01d453906 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -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 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index b75d0dd8bb6..b44f682c02e 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -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; diff --git a/strings/decimal.c b/strings/decimal.c index 8786a513945..ecd92a54cc9 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -170,6 +170,7 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={ #define ADD(to, from1, from2, carry) /* assume carry <= 1 */ \ do \ { \ + DBUG_ASSERT((carry) <= 1); \ dec1 a=(from1)+(from2)+(carry); \ if (((carry)= a >= DIG_BASE)) /* no division here! */ \ a-=DIG_BASE; \ @@ -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; From cf7627bce09928d66129280b7903f6ab42fe2983 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Jul 2006 11:11:49 -0700 Subject: [PATCH 4/8] Fixed bug #18243. The implementation of the method Item_func_reverse::val_str for the REVERSE function modified the argument of the function. This led to wrong results for expressions that contained REVERSE(ref) if ref occurred somewhere else in the expressions. mysql-test/r/func_str.result: Added a test case for bug #18243. mysql-test/t/func_str.test: Added a test case for bug #18243. sql/item_strfunc.cc: Fixed bug #18243. The implementation of the method Item_func_reverse::val_str for the REVERSE function modified the argument of the function. This led to wrong results for expressions that contained REVERSE(ref) if ref occurred somewhere else in the expressions. The implementation of Item_func_reverse::val_str has been changed to make the argument intact. sql/item_strfunc.h: Fixed bug #18243. Added tmp_value to the Item_func_reverse class to store the result of the function. It erroneously replaced the argument before this fix. --- mysql-test/r/func_str.result | 15 ++++++++++++++ mysql-test/t/func_str.test | 17 ++++++++++++++++ sql/item_strfunc.cc | 39 +++++++++++++++++++----------------- sql/item_strfunc.h | 1 + 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 24e6bb6f38a..61a77c211d7 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1021,4 +1021,19 @@ 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 diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index c36e15a08b9..9a1c75a8dc0 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -681,4 +681,21 @@ 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 diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index ee585649f8c..7bc7956283b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -709,44 +709,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; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 89bab4a909c..f800c17182b 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -100,6 +100,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 *); From 41c7aece39b73635339ed8b50360d354858ce1fa Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Jul 2006 14:41:01 -0700 Subject: [PATCH 5/8] Added a test case with views for bug 18243 (see also func_str.test). --- mysql-test/r/view.result | 13 +++++++++++++ mysql-test/t/view.test | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 9486b9900f6..295f9442f13 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2750,3 +2750,16 @@ 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; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 18ba85d3408..623195dd527 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2614,3 +2614,19 @@ 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; From a8fd83d676a5d8a64921f1f13ba4fa4f45221da8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Jul 2006 17:27:11 +0300 Subject: [PATCH 6/8] Bug #20569 Garbage in DECIMAL results from some mathematical functions * portability fix: moved the macro call after the C declaration strings/decimal.c: Bug #20569 Garbage in DECIMAL results from some mathematical functions * moved the macro call after the C declaration --- strings/decimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/decimal.c b/strings/decimal.c index ecd92a54cc9..5a0bc0968b6 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -170,8 +170,8 @@ static const dec1 frac_max[DIG_PER_DEC1-1]={ #define ADD(to, from1, from2, carry) /* assume carry <= 1 */ \ do \ { \ - DBUG_ASSERT((carry) <= 1); \ dec1 a=(from1)+(from2)+(carry); \ + DBUG_ASSERT((carry) <= 1); \ if (((carry)= a >= DIG_BASE)) /* no division here! */ \ a-=DIG_BASE; \ (to)=a; \ From 0806d9a86d73a1f1e089c9c3465c77ca82829b40 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Jul 2006 16:27:03 +0300 Subject: [PATCH 7/8] BUG#14553: NULL in WHERE resets LAST_INSERT_ID To make MySQL compatible with some ODBC applications, you can find the AUTO_INCREMENT value for the last inserted row with the following query: SELECT * FROM tbl_name WHERE auto_col IS NULL. This is done with a special code that replaces 'auto_col IS NULL' with 'auto_col = LAST_INSERT_ID'. However this also resets the LAST_INSERT_ID to 0 as it uses it for a flag so as to ensure that only the first SELECT ... WHERE auto_col IS NULL after an INSERT has this special behaviour. In order to avoid resetting the LAST_INSERT_ID a special flag is introduced in the THD class. This flag is used to restrict the second and subsequent SELECTs instead of LAST_INSERT_ID. mysql-test/r/odbc.result: test suite for the bug mysql-test/r/rpl_insert_id.result: test for the fix in replication mysql-test/t/odbc.test: test suite for the bug mysql-test/t/rpl_insert_id.test: test for the fix in replication sql/sql_class.cc: initialize the flag sql/sql_class.h: flag's declaration and set code when setting the last_insert_id sql/sql_select.cc: the special flag is used instead of last_insert_id --- mysql-test/r/odbc.result | 11 +++++++++++ mysql-test/r/rpl_insert_id.result | 14 ++++++++++++++ mysql-test/t/odbc.test | 10 ++++++++++ mysql-test/t/rpl_insert_id.test | 20 +++++++++++++++++++- sql/sql_class.cc | 1 + sql/sql_class.h | 3 +++ sql/sql_select.cc | 4 ++-- 7 files changed, 60 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/odbc.result b/mysql-test/r/odbc.result index c0b2ada0053..30d839077f3 100644 --- a/mysql-test/r/odbc.result +++ b/mysql-test/r/odbc.result @@ -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 noticed after reading const tables 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; diff --git a/mysql-test/r/rpl_insert_id.result b/mysql-test/r/rpl_insert_id.result index 8482f631553..e683ea2fb39 100644 --- a/mysql-test/r/rpl_insert_id.result +++ b/mysql-test/r/rpl_insert_id.result @@ -73,3 +73,17 @@ CREATE TABLE t1 ( a INT UNIQUE ); 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; diff --git a/mysql-test/t/odbc.test b/mysql-test/t/odbc.test index d4b6fc35e74..6a754bb32a7 100644 --- a/mysql-test/t/odbc.test +++ b/mysql-test/t/odbc.test @@ -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 diff --git a/mysql-test/t/rpl_insert_id.test b/mysql-test/t/rpl_insert_id.test index 49d3a03640c..766afad9e47 100644 --- a/mysql-test/t/rpl_insert_id.test +++ b/mysql-test/t/rpl_insert_id.test @@ -73,5 +73,23 @@ SET FOREIGN_KEY_CHECKS=0; --error 1062 INSERT INTO t1 VALUES (1),(1); sync_slave_with_master; - + +# +# Bug#14553: NULL in WHERE resets LAST_INSERT_ID +# +connection master; +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; +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 diff --git a/sql/sql_class.cc b/sql/sql_class.cc index d278ebe8dfa..0e51edd985b 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -265,6 +265,7 @@ THD::THD() ulong tmp=sql_rnd_with_mutex(); randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id); } + substitute_null_with_insert_id = FALSE; } diff --git a/sql/sql_class.h b/sql/sql_class.h index d482a524934..006136a92f1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -893,6 +893,8 @@ public: bool last_cuted_field; bool no_errors, password, is_fatal_error; bool query_start_used,last_insert_id_used,insert_id_used,rand_used; + /* for IS NULL => = last_insert_id() fix in remove_eq_conds() */ + bool substitute_null_with_insert_id; bool time_zone_used; bool in_lock_tables; bool query_error, bootstrap, cleanup_done; @@ -988,6 +990,7 @@ public: { last_insert_id= id_arg; insert_id_used=1; + substitute_null_with_insert_id= TRUE; } inline ulonglong insert_id(void) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 57fb9738612..b6bd9c8b41b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4719,7 +4719,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); @@ -4733,7 +4733,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) cond=new_cond; cond->fix_fields(thd, 0, &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) || From fbd9103b7839854201b86ceff2cd1c2b5cedd623 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Jul 2006 17:45:09 +0300 Subject: [PATCH 8/8] more 4.1->5.0 merge fixes for bug#14553 mysql-test/r/rpl_insert_id.result: more merge fixes for bug#14553 mysql-test/t/rpl_insert_id.test: more merge fixes for bug#14553 --- mysql-test/r/rpl_insert_id.result | 2 +- mysql-test/t/rpl_insert_id.test | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_insert_id.result b/mysql-test/r/rpl_insert_id.result index 21eade8f9cf..20538c705a0 100644 --- a/mysql-test/r/rpl_insert_id.result +++ b/mysql-test/r/rpl_insert_id.result @@ -73,7 +73,7 @@ CREATE TABLE t1 ( a INT UNIQUE ); SET FOREIGN_KEY_CHECKS=0; INSERT INTO t1 VALUES (1),(1); ERROR 23000: Duplicate entry '1' for key 1 -drop table if exists t1, t2; +drop table t1; create table t1(a int auto_increment, key(a)); create table t2(a int); insert into t1 (a) values (null); diff --git a/mysql-test/t/rpl_insert_id.test b/mysql-test/t/rpl_insert_id.test index 94ce7f95fb4..d2866bca60f 100644 --- a/mysql-test/t/rpl_insert_id.test +++ b/mysql-test/t/rpl_insert_id.test @@ -82,7 +82,6 @@ sync_slave_with_master; # Bug#14553: NULL in WHERE resets LAST_INSERT_ID # connection master; -drop table if exists t1,t2; create table t1(a int auto_increment, key(a)); create table t2(a int); insert into t1 (a) values (null);