From 4d070fd92b9398c55d7ca7ba5654b783bc5a30ea Mon Sep 17 00:00:00 2001 From: "timour@mysql.com" <> Date: Mon, 30 Aug 2004 15:26:27 +0300 Subject: [PATCH 1/8] Fix for Bug#3759 The cause of the bug is that Item_func_in::fix_fields did not fully update its used_table_cache. This was the cause for not_null_tables in setup_conds() to be still 0 after the call not_null_tables= (*conds)->not_null_tables(); As a result the condition in setup_conds() if ( ... (table->table->map & not_null_tables) ...) failed, which was the cause for the ON expression not to be added to conds, and later the optimizer couldn't detect that it could apply the OUTER JOIN ==> JOIN optimization. --- BitKeeper/etc/logging_ok | 1 + sql/item_cmpfunc.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 698f7655b6e..ce1b4d16eb9 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -136,6 +136,7 @@ tim@sand.box tim@threads.polyesthetic.msg tim@white.box tim@work.mysql.com +timour@mysql.com tom@basil-firewall.home.com tonu@hundin.mysql.fi tonu@volk.internalnet diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 236ebb8d28b..a4f8118f21d 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -431,6 +431,9 @@ class Item_func_in :public Item_int_func { bool res= (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist)); with_sum_func= with_sum_func || item->with_sum_func; + used_tables_cache|= item->used_tables(); + not_null_tables_cache|= item->not_null_tables(); + const_item_cache&= item->const_item(); return res; } void fix_length_and_dec(); From 61eff52d23113d45ae9bd35812eacd2a264a1a85 Mon Sep 17 00:00:00 2001 From: "timour@mysql.com" <> Date: Mon, 30 Aug 2004 18:14:29 +0300 Subject: [PATCH 2/8] added test for BUG#3759 --- mysql-test/r/select.result | 21 +++++++++++++++++++++ mysql-test/t/select.test | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 206fa507615..99041701cb8 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2327,3 +2327,24 @@ select * from t2,t3 where t2.s = t3.s; s s two two drop table t1, t2, t3; +create table t1 (a integer, b integer, index(a), index(b)); +create table t2 (c integer, d integer, index(c), index(d)); +insert into t1 values (1,2), (2,2), (3,2), (4,2); +insert into t2 values (1,3), (2,3), (3,4), (4,4); +explain select * from t1 left join t2 on a=c where d in (4); +table type possible_keys key key_len ref rows Extra +t2 ref c,d d 5 const 2 Using where +t1 ALL a NULL NULL NULL 3 Using where +select * from t1 left join t2 on a=c where d in (4); +a b c d +3 2 3 4 +4 2 4 4 +explain select * from t1 left join t2 on a=c where d = 4; +table type possible_keys key key_len ref rows Extra +t2 ref c,d d 5 const 2 Using where +t1 ALL a NULL NULL NULL 3 Using where +select * from t1 left join t2 on a=c where d = 4; +a b c d +3 2 3 4 +4 2 4 4 +drop table t1, t2; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 7cb157f194e..11b3ae6aed1 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1874,3 +1874,17 @@ select * from t3 where s = 'one'; select * from t1,t2 where t1.s = t2.s; select * from t2,t3 where t2.s = t3.s; drop table t1, t2, t3; + +# +# Bug #3759 +# Both queries should produce identical plans and results. +# +create table t1 (a integer, b integer, index(a), index(b)); +create table t2 (c integer, d integer, index(c), index(d)); +insert into t1 values (1,2), (2,2), (3,2), (4,2); +insert into t2 values (1,3), (2,3), (3,4), (4,4); +explain select * from t1 left join t2 on a=c where d in (4); +select * from t1 left join t2 on a=c where d in (4); +explain select * from t1 left join t2 on a=c where d = 4; +select * from t1 left join t2 on a=c where d = 4; +drop table t1, t2; \ No newline at end of file From eb304bd49f3228352a328d158db37c61f4cccd93 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 26 Nov 2004 02:31:22 +0200 Subject: [PATCH 3/8] Fixes while reviewing code (Cleanups and better bug fixes) --- mysql-test/r/select.result | 32 +++++++++++++-------------- mysql-test/t/select.test | 2 +- scripts/mysql_fix_privilege_tables.sh | 2 +- sql/item_cmpfunc.cc | 7 +++--- sql/item_cmpfunc.h | 3 --- sql/item_func.h | 2 +- sql/slave.cc | 3 ++- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 3dd0603ed09..cc90547722f 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2327,22 +2327,6 @@ select * from t2,t3 where t2.s = t3.s; s s two two drop table t1, t2, t3; -CREATE TABLE t1 ( -i int(11) NOT NULL default '0', -c char(10) NOT NULL default '', -PRIMARY KEY (i), -UNIQUE KEY c (c) -) TYPE=MyISAM; -INSERT INTO t1 VALUES (1,'a'); -INSERT INTO t1 VALUES (2,'b'); -INSERT INTO t1 VALUES (3,'c'); -EXPLAIN SELECT i FROM t1 WHERE i=1; -table type possible_keys key key_len ref rows Extra -t1 const PRIMARY PRIMARY 4 const 1 Using index -EXPLAIN SELECT i FROM t1 WHERE i=1; -table type possible_keys key key_len ref rows Extra -t1 const PRIMARY PRIMARY 4 const 1 Using index -DROP TABLE t1; create table t1 (a integer, b integer, index(a), index(b)); create table t2 (c integer, d integer, index(c), index(d)); insert into t1 values (1,2), (2,2), (3,2), (4,2); @@ -2364,3 +2348,19 @@ a b c d 3 2 3 4 4 2 4 4 drop table t1, t2; +CREATE TABLE t1 ( +i int(11) NOT NULL default '0', +c char(10) NOT NULL default '', +PRIMARY KEY (i), +UNIQUE KEY c (c) +) TYPE=MyISAM; +INSERT INTO t1 VALUES (1,'a'); +INSERT INTO t1 VALUES (2,'b'); +INSERT INTO t1 VALUES (3,'c'); +EXPLAIN SELECT i FROM t1 WHERE i=1; +table type possible_keys key key_len ref rows Extra +t1 const PRIMARY PRIMARY 4 const 1 Using index +EXPLAIN SELECT i FROM t1 WHERE i=1; +table type possible_keys key key_len ref rows Extra +t1 const PRIMARY PRIMARY 4 const 1 Using index +DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index f897703789b..e6b1ffbe8d7 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1887,7 +1887,7 @@ explain select * from t1 left join t2 on a=c where d in (4); select * from t1 left join t2 on a=c where d in (4); explain select * from t1 left join t2 on a=c where d = 4; select * from t1 left join t2 on a=c where d = 4; -drop table t1, t2;R +drop table t1, t2; # # Covering index is mentioned in EXPLAIN output for const tables (bug #5333) diff --git a/scripts/mysql_fix_privilege_tables.sh b/scripts/mysql_fix_privilege_tables.sh index 2fbcd76c318..381cf599e32 100644 --- a/scripts/mysql_fix_privilege_tables.sh +++ b/scripts/mysql_fix_privilege_tables.sh @@ -74,7 +74,7 @@ parse_arguments() parse_arguments "$@" if test -z "$cmd"; then - cmd="$bindir/mysql -f --user=$user --host=$host" + cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host" if test ! -z "$root_password"; then cmd="$cmd --password=$root_password" fi diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fbc1ad97e76..107a17815ae 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -293,9 +293,9 @@ void Item_func_interval::fix_length_and_dec() } maybe_null=0; max_length=2; used_tables_cache|= item->used_tables(); - not_null_tables_cache&= item->not_null_tables(); + not_null_tables_cache= item->not_null_tables(); with_sum_func= with_sum_func || item->with_sum_func; - const_item_cache&=item->const_item(); + const_item_cache&= item->const_item(); } @@ -1087,7 +1087,8 @@ void Item_func_in::fix_length_and_dec() maybe_null= item->maybe_null; max_length=2; used_tables_cache|= item->used_tables(); - not_null_tables_cache&= item->not_null_tables(); + /* not_null_tables_cache is only dependent on the argument to in */ + not_null_tables_cache= item->not_null_tables(); const_item_cache&= item->const_item(); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index d36429ab61e..8f1aa525190 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -432,9 +432,6 @@ class Item_func_in :public Item_int_func { bool res= (item->fix_fields(thd,tlist) || Item_func::fix_fields(thd,tlist)); with_sum_func= with_sum_func || item->with_sum_func; - used_tables_cache|= item->used_tables(); - not_null_tables_cache|= item->not_null_tables(); - const_item_cache&= item->const_item(); return res; } void fix_length_and_dec(); diff --git a/sql/item_func.h b/sql/item_func.h index 8a013f42c05..3627af4ebb1 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -600,7 +600,7 @@ public: { maybe_null=0; max_length=3; used_tables_cache|= item->used_tables(); - not_null_tables_cache&= item->not_null_tables(); + not_null_tables_cache= item->not_null_tables(); const_item_cache&= item->const_item(); with_sum_func= with_sum_func || item->with_sum_func; } diff --git a/sql/slave.cc b/sql/slave.cc index 7e544572755..b0f911e7013 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1637,7 +1637,8 @@ int init_master_info(MASTER_INFO* mi, const char* master_info_fname, position is at the beginning of the file, and will read the "signature" and then fast-forward to the last position read. */ - if (thread_mask & SLAVE_SQL) { + if (thread_mask & SLAVE_SQL) + { my_b_seek(mi->rli.cur_log, (my_off_t) 0); } DBUG_RETURN(0); From d58c186759bf264bc57a79882bc724d0485d3796 Mon Sep 17 00:00:00 2001 From: "marko@hundin.mysql.fi" <> Date: Fri, 26 Nov 2004 13:16:37 +0200 Subject: [PATCH 4/8] srv0srv.c: srv_lock_timeout_and_monitor_thread(): write to srv_monitor_file only if --innodb_status_file=1 --- innobase/srv/srv0srv.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c index 0a814268a36..99a2db57d79 100644 --- a/innobase/srv/srv0srv.c +++ b/innobase/srv/srv0srv.c @@ -1617,11 +1617,13 @@ loop: srv_printf_innodb_monitor(stderr); } - mutex_enter(&srv_monitor_file_mutex); - rewind(srv_monitor_file); - srv_printf_innodb_monitor(srv_monitor_file); - os_file_set_eof(srv_monitor_file); - mutex_exit(&srv_monitor_file_mutex); + if (srv_innodb_status) { + mutex_enter(&srv_monitor_file_mutex); + rewind(srv_monitor_file); + srv_printf_innodb_monitor(srv_monitor_file); + os_file_set_eof(srv_monitor_file); + mutex_exit(&srv_monitor_file_mutex); + } if (srv_print_innodb_tablespace_monitor && difftime(current_time, last_table_monitor_time) > 60) { From 77c32ac1739d78e39a51a1f6689858d4d193eb66 Mon Sep 17 00:00:00 2001 From: "kent@mysql.com" <> Date: Sun, 28 Nov 2004 15:45:12 +0100 Subject: [PATCH 5/8] configure.in: A work-around for SCO, disable use of clock_gettime --- configure.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 1fcba6b8f5f..0d6e797f571 100644 --- a/configure.in +++ b/configure.in @@ -1931,9 +1931,11 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bzero chsize cuserid fchmod fcntl \ # # case "$target" in - *-*-aix4*) + *-*-aix4* | *-*-sco*) # (grr) aix 4.3 has a stub for clock_gettime, (returning ENOSYS) # and using AC_TRY_RUN is hard when cross-compiling + # We also disable for SCO for the time being, the headers for the + # thread library we use conflicts with other headers. ;; *) AC_CHECK_FUNCS(clock_gettime) ;; From 7eccc3107fd65c1f066f93f33867799333a439ee Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 28 Nov 2004 16:31:14 +0100 Subject: [PATCH 6/8] skip last compress test if we're short of RAM --- mysql-test/r/func_compress.result | 4 ++-- mysql-test/t/func_compress.test | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index 11dbcca9431..9bc8e417e19 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -69,6 +69,6 @@ Error 1259 ZLIB: Input data corrupted Error 1256 Uncompressed data size too large; the maximum size is 1048576 (probably, length of uncompressed data was corrupted) drop table t1; set @@max_allowed_packet=1048576*100; -select compress(repeat('aaaaaaaaaa', 10000000)) is null; -compress(repeat('aaaaaaaaaa', 10000000)) is null +select compress(repeat('aaaaaaaaaa', IF(XXX, 10, 10000000))) is null; +compress(repeat('aaaaaaaaaa', IF(XXX, 10, 10000000))) is null 0 diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index 7b70289d2c0..f46589e9e0e 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -38,7 +38,10 @@ drop table t1; # # Bug #5497: a problem with large strings +# note that when LOW_MEMORY is set the "test" below is meaningless # set @@max_allowed_packet=1048576*100; -select compress(repeat('aaaaaaaaaa', 10000000)) is null; +--replace_result "''" XXX "'1'" XXX +eval select compress(repeat('aaaaaaaaaa', IF('$LOW_MEMORY', 10, 10000000))) is null; + From 989721d12f6c2a6b724c9010912be4b6d04a1ccb Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 28 Nov 2004 17:06:40 +0100 Subject: [PATCH 7/8] bad merge fixed --- mysql-test/r/rpl_start_stop_slave.result | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_start_stop_slave.result b/mysql-test/r/rpl_start_stop_slave.result index 1b4d87124d1..1fcb586d1fb 100644 --- a/mysql-test/r/rpl_start_stop_slave.result +++ b/mysql-test/r/rpl_start_stop_slave.result @@ -1,9 +1,9 @@ -slave stop; +stop slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -slave start; +start slave; stop slave; create table t1(n int); start slave; From cb538e45f5f18c71c22daed3acd983ec9ff97176 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 28 Nov 2004 19:48:41 +0100 Subject: [PATCH 8/8] post-merge fix --- mysql-test/r/select.result | 62 +++++++++++++------------------------- mysql-test/t/select.test | 2 -- 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 79af86777dc..a05b379ed88 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2353,6 +2353,27 @@ select * from t2,t3 where t2.s = t3.s; s s two two drop table t1, t2, t3; +create table t1 (a integer, b integer, index(a), index(b)); +create table t2 (c integer, d integer, index(c), index(d)); +insert into t1 values (1,2), (2,2), (3,2), (4,2); +insert into t2 values (1,3), (2,3), (3,4), (4,4); +explain select * from t1 left join t2 on a=c where d in (4); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref c,d d 5 const 2 Using where +1 SIMPLE t1 ALL a NULL NULL NULL 3 Using where +select * from t1 left join t2 on a=c where d in (4); +a b c d +3 2 3 4 +4 2 4 4 +explain select * from t1 left join t2 on a=c where d = 4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref c,d d 5 const 2 Using where +1 SIMPLE t1 ALL a NULL NULL NULL 3 Using where +select * from t1 left join t2 on a=c where d = 4; +a b c d +3 2 3 4 +4 2 4 4 +drop table t1, t2; CREATE TABLE t1 ( i int(11) NOT NULL default '0', c char(10) NOT NULL default '', @@ -2365,45 +2386,4 @@ INSERT INTO t1 VALUES (3,'c'); EXPLAIN SELECT i FROM t1 WHERE i=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index -EXPLAIN SELECT i FROM t1 WHERE i=1; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index -DROP TABLE t1; -create table t1 (a integer, b integer, index(a), index(b)); -create table t2 (c integer, d integer, index(c), index(d)); -insert into t1 values (1,2), (2,2), (3,2), (4,2); -insert into t2 values (1,3), (2,3), (3,4), (4,4); -explain select * from t1 left join t2 on a=c where d in (4); -table type possible_keys key key_len ref rows Extra -t2 ref c,d d 5 const 2 Using where -t1 ALL a NULL NULL NULL 3 Using where -select * from t1 left join t2 on a=c where d in (4); -a b c d -3 2 3 4 -4 2 4 4 -explain select * from t1 left join t2 on a=c where d = 4; -table type possible_keys key key_len ref rows Extra -t2 ref c,d d 5 const 2 Using where -t1 ALL a NULL NULL NULL 3 Using where -select * from t1 left join t2 on a=c where d = 4; -a b c d -3 2 3 4 -4 2 4 4 -drop table t1, t2; -CREATE TABLE t1 ( -i int(11) NOT NULL default '0', -c char(10) NOT NULL default '', -PRIMARY KEY (i), -UNIQUE KEY c (c) -) TYPE=MyISAM; -INSERT INTO t1 VALUES (1,'a'); -INSERT INTO t1 VALUES (2,'b'); -INSERT INTO t1 VALUES (3,'c'); -EXPLAIN SELECT i FROM t1 WHERE i=1; -table type possible_keys key key_len ref rows Extra -t1 const PRIMARY PRIMARY 4 const 1 Using index -EXPLAIN SELECT i FROM t1 WHERE i=1; -table type possible_keys key key_len ref rows Extra -t1 const PRIMARY PRIMARY 4 const 1 Using index ->>>>>>> DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 84aab132503..9bbd26a9c1c 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1929,6 +1929,4 @@ INSERT INTO t1 VALUES (3,'c'); EXPLAIN SELECT i FROM t1 WHERE i=1; -EXPLAIN SELECT i FROM t1 WHERE i=1; - DROP TABLE t1;