From d9b55b6ed97586afbc24d5c446c219bf98f4453d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Feb 2004 21:20:10 +0200 Subject: [PATCH 1/4] sql_table.cc: Fix for a bug #2557 which caused that MySQL 4.1.2 does not replicate CREATE TABLE ... LIKE .. sql/sql_table.cc: Fix for a bug #2557 which caused that MySQL 4.1.2 does not replicate CREATE TABLE ... LIKE .. --- sql/sql_table.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 60da32fceca..03272c8bc16 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1845,6 +1845,20 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table, table_name); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */ } + else + { + // Must be written before unlock + mysql_update_log.write(thd,thd->query, thd->query_length); + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + Query_log_event qinfo(thd, thd->query, thd->query_length, + test(create_info->options & + HA_LEX_CREATE_TMP_TABLE)); + mysql_bin_log.write(&qinfo); + } + } + DBUG_RETURN(0); table_exists: From 2d06a32a577874c2ce0f2e3893a00b121ede639d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Feb 2004 21:34:04 +0200 Subject: [PATCH 2/4] rpl_log.result: a result file for a fix for bug #2557 rpl_log.test: A test case for a fix for bug #2557 mysql-test/t/rpl_log.test: A test case for a fix for bug #2557 mysql-test/r/rpl_log.result: a result file for a fix for bug #2557 --- mysql-test/r/rpl_log.result | 22 +++++++++++++++------- mysql-test/t/rpl_log.test | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/rpl_log.result b/mysql-test/r/rpl_log.result index 2f8a54369c9..34d41c5dfac 100644 --- a/mysql-test/r/rpl_log.result +++ b/mysql-test/r/rpl_log.result @@ -16,6 +16,7 @@ load data infile '../../std_data/words.dat' into table t1 ignore 1 lines; select count(*) from t1; count(*) 69 +create table t2 like t1; drop table t1; show binlog events; Log_name Pos Event_type Server_id Orig_log_pos Info @@ -27,7 +28,8 @@ master-bin.000001 263 Query 1 263 use `test`; drop table t1 master-bin.000001 311 Query 1 311 use `test`; create table t1 (word char(20) not null) master-bin.000001 386 Create_file 1 386 db=test;table=t1;file_id=1;block_len=581 master-bin.000001 1056 Exec_load 1 1056 ;file_id=1 -master-bin.000001 1079 Query 1 1079 use `test`; drop table t1 +master-bin.000001 1079 Query 1 1079 use `test`; create table t2 like t1 +master-bin.000001 1137 Query 1 1137 use `test`; drop table t1 show binlog events from 79 limit 1; Log_name Pos Event_type Server_id Orig_log_pos Info master-bin.000001 79 Query 1 79 use `test`; create table t1(n int not null auto_increment primary key) @@ -38,6 +40,10 @@ master-bin.000001 172 Intvar 1 172 INSERT_ID=1 show binlog events from 79 limit 2,1; Log_name Pos Event_type Server_id Orig_log_pos Info master-bin.000001 200 Query 1 200 use `test`; insert into t1 values (NULL) +show binlog events from 79 limit 2,2; +Log_name Pos Event_type Server_id Orig_log_pos Info +master-bin.000001 200 Query 1 200 use `test`; insert into t1 values (NULL) +master-bin.000001 263 Query 1 263 use `test`; drop table t1 flush logs; create table t5 (a int); drop table t5; @@ -57,8 +63,9 @@ master-bin.000001 263 Query 1 263 use `test`; drop table t1 master-bin.000001 311 Query 1 311 use `test`; create table t1 (word char(20) not null) master-bin.000001 386 Create_file 1 386 db=test;table=t1;file_id=1;block_len=581 master-bin.000001 1056 Exec_load 1 1056 ;file_id=1 -master-bin.000001 1079 Query 1 1079 use `test`; drop table t1 -master-bin.000001 1127 Rotate 1 1127 master-bin.000002;pos=4 +master-bin.000001 1079 Query 1 1079 use `test`; create table t2 like t1 +master-bin.000001 1137 Query 1 1137 use `test`; drop table t1 +master-bin.000001 1185 Rotate 1 1185 master-bin.000002;pos=4 show binlog events in 'master-bin.000002'; Log_name Pos Event_type Server_id Orig_log_pos Info master-bin.000002 4 Query 1 4 use `test`; create table t5 (a int) @@ -85,10 +92,11 @@ slave-bin.000001 263 Query 1 263 use `test`; drop table t1 slave-bin.000001 311 Query 1 311 use `test`; create table t1 (word char(20) not null) slave-bin.000001 386 Create_file 1 386 db=test;table=t1;file_id=1;block_len=581 slave-bin.000001 1065 Exec_load 1 1065 ;file_id=1 -slave-bin.000001 1088 Query 1 1088 use `test`; drop table t1 -slave-bin.000001 1136 Query 1 1136 use `test`; create table t5 (a int) -slave-bin.000001 1194 Query 1 1194 use `test`; drop table t5 -slave-bin.000001 1242 Rotate 2 1242 slave-bin.000002;pos=4 +slave-bin.000001 1088 Query 1 1088 use `test`; create table t2 like t1 +slave-bin.000001 1146 Query 1 1146 use `test`; drop table t1 +slave-bin.000001 1194 Query 1 1194 use `test`; create table t5 (a int) +slave-bin.000001 1252 Query 1 1252 use `test`; drop table t5 +slave-bin.000001 1300 Rotate 2 1300 slave-bin.000002;pos=4 show binlog events in 'slave-bin.000002' from 4; Log_name Pos Event_type Server_id Orig_log_pos Info slave-bin.000002 4 Query 1 4 use `test`; create table t1 (n int) diff --git a/mysql-test/t/rpl_log.test b/mysql-test/t/rpl_log.test index 7ae0a4dc3c2..5f59b1034dc 100644 --- a/mysql-test/t/rpl_log.test +++ b/mysql-test/t/rpl_log.test @@ -35,12 +35,14 @@ drop table t1; create table t1 (word char(20) not null); load data infile '../../std_data/words.dat' into table t1 ignore 1 lines; select count(*) from t1; +create table t2 like t1; drop table t1; --replace_result $VERSION VERSION show binlog events; show binlog events from 79 limit 1; show binlog events from 79 limit 2; show binlog events from 79 limit 2,1; +show binlog events from 79 limit 2,2; flush logs; # We need an extra update before doing save_master_pos. From 538e6e8cbd057333650af356896cef44b7786f92 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Feb 2004 22:54:59 +0200 Subject: [PATCH 3/4] sql_acl.cc: Fix for a bug #2546 in 4.1.2 that prevented table / column privileges from being loaded on startup. sql/sql_acl.cc: Fix for a bug #2546 in 4.1.2 that prevented table / column privileges from being loaded on startup. --- sql/sql_acl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 282a9afa038..0a0b3feeadf 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2543,7 +2543,7 @@ my_bool grant_init(THD *org_thd) do { GRANT_TABLE *mem_check; - if (!(mem_check=new GRANT_TABLE(t_table,c_table)) || mem_check->ok()) + if (!(mem_check=new GRANT_TABLE(t_table,c_table))) { /* This could only happen if we are out memory */ grant_option= FALSE; /* purecov: deadcode */ @@ -2562,7 +2562,7 @@ my_bool grant_init(THD *org_thd) } } - if (my_hash_insert(&column_priv_hash,(byte*) mem_check)) + if (mem_check->ok() && my_hash_insert(&column_priv_hash,(byte*) mem_check)) { grant_option= FALSE; goto end_unlock; From 425ae9185d10c61b2b2b22e551dd9f96927b8efb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Feb 2004 21:34:25 +0200 Subject: [PATCH 4/4] Fixes for bugs #2508 and #2552 mysql-test/r/union.result: Test cases for bugs #2508 and #2552 mysql-test/t/union.test: Test cases for bugs #2508 and #2552 sql/sql_class.h: A fix for a bug #2508 sql/sql_select.cc: A fix for a bug #2508 sql/sql_union.cc: a fix for a bug #2552 --- mysql-test/r/union.result | 36 ++++++++++++++++++++++++++++++------ mysql-test/t/union.test | 9 +++++++++ sql/sql_class.h | 4 ++-- sql/sql_select.cc | 4 ++++ sql/sql_union.cc | 4 ++++ 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 4a514e3dd18..bdcfee97d48 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -539,7 +539,7 @@ aa show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` char(2) NOT NULL default '' + `a` char(2) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT 12 as a UNION select "aa" as a; @@ -550,7 +550,7 @@ aa show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` char(2) NOT NULL default '' + `a` char(2) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT 12 as a UNION select 12.2 as a; @@ -561,7 +561,7 @@ a show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` double(4,1) NOT NULL default '0.0' + `a` double(4,1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t2 (it1 tinyint, it2 tinyint not null, i int not null, ib bigint, f float, d double, y year, da date, dt datetime, sc char(10), sv varchar(10), b blob, tx text); @@ -585,7 +585,7 @@ it2 show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `it2` int(11) NOT NULL default '0' + `it2` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 SELECT i from t2 UNION select f from t2; @@ -799,7 +799,7 @@ select * from t1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `1` bigint(1) NOT NULL default '0' + `1` bigint(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 select _latin1"test" union select _latin2"testt" ; @@ -808,7 +808,7 @@ create table t1 select _latin2"test" union select _latin2"testt" ; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `test` char(5) character set latin2 NOT NULL default '' + `test` char(5) character set latin2 default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 (s char(200)); @@ -869,3 +869,27 @@ show status like 'Slow_queries'; Variable_name Value Slow_queries 3 drop table t1; +create table t1 ( RID int(11) not null default '0', IID int(11) not null default '0', nada varchar(50) not null,NAME varchar(50) not null,PHONE varchar(50) not null) engine=MyISAM; +insert into t1 ( RID,IID,nada,NAME,PHONE) values (1, 1, 'main', 'a', '111'), (2, 1, 'main', 'b', '222'), (3, 1, 'main', 'c', '333'), (4, 1, 'main', 'd', '444'), (5, 1, 'main', 'e', '555'), (6, 2, 'main', 'c', '333'), (7, 2, 'main', 'd', '454'), (8, 2, 'main', 'e', '555'), (9, 2, 'main', 'f', '666'), (10, 2, 'main', 'g', '777'); +select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 A left join t1 B on A.NAME = B.NAME and B.IID = 2 where A.IID = 1 and (A.PHONE <> B.PHONE or B.NAME is null) union select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 B left join t1 A on B.NAME = A.NAME and A.IID = 1 where B.IID = 2 and (A.PHONE <> B.PHONE or A.NAME is null); +NAME PHONE NAME PHONE +a 111 NULL NULL +b 222 NULL NULL +d 444 d 454 +NULL NULL f 666 +NULL NULL g 777 +drop table t1; +create table t1 ( id int, name char(10) not null, name2 char(10) not null ) engine=innodb; +insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt'); +select name2 from t1 union all select name from t1 union all select id from t1; +name2 +fff +sss +ttt +first +second +third +1 +2 +3 +drop table t1; diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index 8ce4aa997fc..2ea2741a621 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -465,3 +465,12 @@ show status like 'Slow_queries'; select count(*) from t1 where a=7 union select count(*) from t1 where b=13; show status like 'Slow_queries'; drop table t1; +create table t1 ( RID int(11) not null default '0', IID int(11) not null default '0', nada varchar(50) not null,NAME varchar(50) not null,PHONE varchar(50) not null) engine=MyISAM; +insert into t1 ( RID,IID,nada,NAME,PHONE) values (1, 1, 'main', 'a', '111'), (2, 1, 'main', 'b', '222'), (3, 1, 'main', 'c', '333'), (4, 1, 'main', 'd', '444'), (5, 1, 'main', 'e', '555'), (6, 2, 'main', 'c', '333'), (7, 2, 'main', 'd', '454'), (8, 2, 'main', 'e', '555'), (9, 2, 'main', 'f', '666'), (10, 2, 'main', 'g', '777'); +select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 A left join t1 B on A.NAME = B.NAME and B.IID = 2 where A.IID = 1 and (A.PHONE <> B.PHONE or B.NAME is null) union select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 B left join t1 A on B.NAME = A.NAME and A.IID = 1 where B.IID = 2 and (A.PHONE <> B.PHONE or A.NAME is null); +drop table t1; +create table t1 ( id int, name char(10) not null, name2 char(10) not null ) engine=innodb; +insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt'); +select name2 from t1 union all select name from t1 union all select id from t1; +drop table t1; + diff --git a/sql/sql_class.h b/sql/sql_class.h index 7971137d848..b41dc578539 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1075,11 +1075,11 @@ public: uint hidden_field_count; uint group_parts,group_length,group_null_parts; uint quick_group; - bool using_indirect_summary_function; + bool using_indirect_summary_function, all_nulls; TMP_TABLE_PARAM() :copy_funcs_it(copy_funcs), copy_field(0), group_parts(0), - group_length(0), group_null_parts(0) + group_length(0), group_null_parts(0), all_nulls(0) {} ~TMP_TABLE_PARAM() { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e4f7214ad00..3f590ba23fc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4946,6 +4946,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, tmp_from_field, group != 0,not_all_columns); if (!new_field) goto err; // Should be OOM + if (param->all_nulls) + new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join tmp_from_field++; *(reg_field++)= new_field; reclength+=new_field->pack_length(); @@ -4981,6 +4983,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, goto err; // Got OOM continue; // Some kindf of const item } + if (param->all_nulls) + new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join if (type == Item::SUM_FUNC_ITEM) ((Item_sum *) item)->result_field= new_field; tmp_from_field++; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 1cb01c6b3ef..bfaccc93906 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -206,6 +206,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, if (first_select->next_select()) { union_result->tmp_table_param.field_count= types.elements; + union_result->tmp_table_param.all_nulls= true; if (!(table= create_tmp_table(thd_arg, &union_result->tmp_table_param, types, (ORDER*) 0, !union_option, 1, @@ -315,6 +316,7 @@ int st_select_lex_unit::exec() if it use same tables */ uint tablenr=0; + ulong query_id= thd->query_id; for (TABLE_LIST *table_list= (TABLE_LIST*) sl->table_list.first; table_list; table_list= table_list->next, tablenr++) @@ -329,6 +331,8 @@ int st_select_lex_unit::exec() */ setup_table_map(table_list->table, table_list, tablenr); } + for (unsigned int i=0; i < table_list->table->fields; i++) + table_list->table->field[i]->query_id= query_id; } res= sl->join->optimize(); }