From 91f3301c0330984a4aacac3a97cf84cfd741b88a Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Tue, 19 Jun 2007 13:19:20 +0300 Subject: [PATCH 1/8] Bug #29116: Test "rpl_change_master" returns different counters from relay Updated the test to return columns vertically. --- mysql-test/r/rpl_change_master.result | 70 +++++++++++++++++++++++++-- mysql-test/t/rpl_change_master.test | 4 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/rpl_change_master.result b/mysql-test/r/rpl_change_master.result index 16e14f5da2e..ec7d3042551 100644 --- a/mysql-test/r/rpl_change_master.result +++ b/mysql-test/r/rpl_change_master.result @@ -15,12 +15,74 @@ select * from t1; n 1 show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 273 slave-relay-bin.000002 258 master-bin.000001 No No 0 0 214 317 None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 273 +Relay_Log_File slave-relay-bin.000002 +Relay_Log_Pos 258 +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 214 +Relay_Log_Space 317 +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # change master to master_user='root'; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 214 # # master-bin.000001 No No 0 0 214 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 214 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 214 +Relay_Log_Space # +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # select release_lock("a"); release_lock("a") 1 diff --git a/mysql-test/t/rpl_change_master.test b/mysql-test/t/rpl_change_master.test index e7ae798b1a7..acb34b31ea2 100644 --- a/mysql-test/t/rpl_change_master.test +++ b/mysql-test/t/rpl_change_master.test @@ -14,11 +14,11 @@ select * from t1; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # --replace_column 1 # 33 # -show slave status; +query_vertical show slave status; change master to master_user='root'; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # -show slave status; +query_vertical show slave status; # Will restart from after the values(2), which is bug select release_lock("a"); start slave; From 2379f9778deabf14da0f0beaa97e543ce808bcbd Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Wed, 20 Jun 2007 12:25:07 +0500 Subject: [PATCH 2/8] Fixed bug #28898. For a join query with GROUP BY and/or ORDER BY and a view reference in the FROM list the metadata erroneously showed empty table aliases and database names for the view columns. --- mysql-test/r/metadata.result | 41 ++++++++++++++++++++++++++++++++++++ mysql-test/t/metadata.test | 21 ++++++++++++++++++ sql/item.cc | 15 +++++++++++++ sql/item.h | 6 +----- sql/sql_select.cc | 7 ++++++ 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index d33fb038b79..283dc8a02ae 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -140,4 +140,45 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def a v_small v_small 3 9 9 N 32769 0 63 v_small 214748364 +CREATE TABLE t1 (c1 CHAR(1)); +CREATE TABLE t2 (c2 CHAR(1)); +CREATE VIEW v1 AS SELECT t1.c1 FROM t1; +CREATE VIEW v2 AS SELECT t2.c2 FROM t2; +INSERT INTO t1 VALUES ('1'), ('2'), ('3'); +INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2'); +SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 0 0 8 +c1 +1 +2 +2 +3 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 0 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +2 2 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 32768 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 32768 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +DROP VIEW v1; +DROP TABLE t1,t2; End of 5.0 tests diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index df4acec2021..ed510bc2c89 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -90,5 +90,26 @@ select a.* from (select 2147483648 as v_large) a; select a.* from (select 214748364 as v_small) a; --disable_metadata +# +# Bug #28898: table alias and database name of VIEW columns is empty in the +# metadata of # SELECT statement where join is executed via temporary table. +# + +CREATE TABLE t1 (c1 CHAR(1)); +CREATE TABLE t2 (c2 CHAR(1)); +CREATE VIEW v1 AS SELECT t1.c1 FROM t1; +CREATE VIEW v2 AS SELECT t2.c2 FROM t2; +INSERT INTO t1 VALUES ('1'), ('2'), ('3'); +INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2'); + +--enable_metadata +SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; +--disable_metadata + +DROP VIEW v1; +DROP TABLE t1,t2; --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index 32c43eaa865..b1b85ba8b41 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5501,6 +5501,21 @@ void Item_ref::make_field(Send_field *field) } +Item *Item_ref::get_tmp_table_item(THD *thd) +{ + if (!result_field) + return (*ref)->get_tmp_table_item(thd); + + Item_field *item= new Item_field(result_field); + if (item) + { + item->table_name= table_name; + item->db_name= db_name; + } + return item; +} + + void Item_ref_null_helper::print(String *str) { str->append(STRING_WITH_LEN("(")); diff --git a/sql/item.h b/sql/item.h index 9268afaba0c..3478095351a 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1904,11 +1904,7 @@ public: enum_field_types field_type() const { return (*ref)->field_type(); } Field *get_tmp_table_field() { return result_field ? result_field : (*ref)->get_tmp_table_field(); } - Item *get_tmp_table_item(THD *thd) - { - return (result_field ? new Item_field(result_field) : - (*ref)->get_tmp_table_item(thd)); - } + Item *get_tmp_table_item(THD *thd); table_map used_tables() const { return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6bff302f7f8..d962518495f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14241,6 +14241,13 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, if (!item_field) DBUG_RETURN(TRUE); // Fatal error item_field->name= item->name; + if (item->type() == Item::REF_ITEM) + { + Item_field *ifield= (Item_field *) item_field; + Item_ref *iref= (Item_ref *) item; + ifield->table_name= iref->table_name; + ifield->db_name= iref->db_name; + } #ifndef DBUG_OFF if (_db_on_ && !item_field->name) { From 0bd3dd9a37ff64083b3c2eb8681ee36817108e5b Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Wed, 20 Jun 2007 14:21:48 +0500 Subject: [PATCH 3/8] metadata.test, metadata.result: Updated test case for bug #28898. Additional cleanup. --- mysql-test/r/metadata.result | 2 +- mysql-test/t/metadata.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index 283dc8a02ae..4a776b6a253 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -179,6 +179,6 @@ c1 c2 1 1 2 2 3 3 -DROP VIEW v1; +DROP VIEW v1,v2; DROP TABLE t1,t2; End of 5.0 tests diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index ed510bc2c89..65c062399b7 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -109,7 +109,7 @@ SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; --disable_metadata -DROP VIEW v1; +DROP VIEW v1,v2; DROP TABLE t1,t2; --echo End of 5.0 tests From 49e3ed9ffaebcd21049881ca3547818f5c2013cd Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Wed, 20 Jun 2007 13:15:46 +0300 Subject: [PATCH 4/8] port of the fix for bug 19116 4.1-opt -> 5.0-opt --- mysql-test/r/rpl_change_master.result | 70 +++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/rpl_change_master.result b/mysql-test/r/rpl_change_master.result index 7f2ba568fb3..98c42069470 100644 --- a/mysql-test/r/rpl_change_master.result +++ b/mysql-test/r/rpl_change_master.result @@ -12,12 +12,74 @@ insert into t1 values(1); insert into t1 values(2); stop slave; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 357 # # master-bin.000001 No No 0 0 183 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 357 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 183 +Relay_Log_Space # +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # change master to master_user='root'; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 183 # # master-bin.000001 No No 0 0 183 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 183 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 183 +Relay_Log_Space # +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # start slave; select * from t1; n From c6cc50960ba0dfe4ef5cb6cfaccff77480d73ef7 Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Wed, 20 Jun 2007 12:43:14 -0700 Subject: [PATCH 5/8] Fixed bug #29104: assertion abort for grouping queries using views. The abort happened when a query contained a conjunctive predicate of the form 'view column = constant' in the WHERE condition and the grouping list also contained a reference to a view column yet a different one. Removed the failing assertion as invalid in a general case. Also fixed a bug that prevented applying some optimization for grouping queries using views. If the WHERE condition of such a query contains a conjunctive condition of the form 'view column = constant' and this view column is used in the grouping list then grouping by this column can be eliminated. The bug blocked performing this elimination. --- mysql-test/r/view.result | 24 ++++++++++++++++++++++++ mysql-test/t/view.test | 24 ++++++++++++++++++++++++ sql/item.cc | 10 ++++------ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 043057f64f7..9adb3f96142 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3476,4 +3476,28 @@ a1 c 2 0 DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); +CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; +SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +b SUM(a) +3 4 +EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +a SUM(b) +1 6 +2 3 +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort +SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +a SUM(b) +1 10 +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 3c370da4139..f670ac8a49d 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3324,4 +3324,28 @@ SELECT * FROM t1; DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +# +# Bug #29104: assertion abort for a query with a view column reference +# in the GROUP BY list and a condition requiring the value +# of another view column to be equal to a constant +# + +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); + +CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; + + +SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; + +SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; + +SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/item.cc b/sql/item.cc index 32c43eaa865..0e75d018b98 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1938,10 +1938,11 @@ bool Item_field::val_bool_result() bool Item_field::eq(const Item *item, bool binary_cmp) const { - if (item->type() != FIELD_ITEM) + Item *real_item= ((Item *) item)->real_item(); + if (real_item->type() != FIELD_ITEM) return 0; - Item_field *item_field= (Item_field*) item; + Item_field *item_field= (Item_field*) real_item; if (item_field->field && field) return item_field->field == field; /* @@ -5627,8 +5628,7 @@ bool Item_outer_ref::fix_fields(THD *thd, Item **reference) DESCRIPTION A view column reference is considered equal to another column reference if the second one is a view column and if both column - references resolve to the same item. It is assumed that both - items are of the same type. + references resolve to the same item. RETURN TRUE Referenced item is equal to given item @@ -5644,8 +5644,6 @@ bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const if (item_ref->ref_type() == VIEW_REF) { Item *item_ref_ref= *(item_ref->ref); - DBUG_ASSERT((*ref)->real_item()->type() == - item_ref_ref->real_item()->type()); return ((*ref)->real_item() == item_ref_ref->real_item()); } } From 1b5d893122ca966b1e6246a7586877ef69497ceb Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Thu, 21 Jun 2007 02:11:28 +0500 Subject: [PATCH 6/8] Fixed bug #28293. Occasionally mysqlbinlog --hexdump failed with error: ERROR 1064 (42000) at line ...: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Query thread_id=... exec_time=... error_code=... When the length of hexadecimal dump of binlog header was divisible by 16, commentary sign '#' after header was lost. The Log_event::print_header function has been modified to always finish hexadecimal binlog header with "\n# ". --- mysql-test/r/mysqlbinlog.result | 6 ++++++ mysql-test/t/mysqlbinlog.test | 13 +++++++++++++ sql/log_event.cc | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index a50d131cca8..1ba198dfd75 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -312,4 +312,10 @@ DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +CREATE TABLE t1 (c1 CHAR(10)); +flush logs; +INSERT INTO t1 VALUES ('0123456789'); +flush logs; +DROP TABLE t1; +# Query thread_id=REMOVED exec_time=REMOVED error_code=REMOVED End of 5.0 tests diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index ba161ddbb89..bd90dcfb930 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -203,4 +203,17 @@ flush logs; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000009 +# +# Bug#28293 missed '#' sign in the hex dump when the dump length +# is divisible by 16. +# + +CREATE TABLE t1 (c1 CHAR(10)); +# we need this for getting fixed timestamps inside of this test +flush logs; +INSERT INTO t1 VALUES ('0123456789'); +flush logs; +DROP TABLE t1; +--exec $MYSQL_BINLOG --hexdump --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000011 | grep 'Query' | sed 's/[0-9]\{1,\}/REMOVED/g' + --echo End of 5.0 tests diff --git a/sql/log_event.cc b/sql/log_event.cc index 6eb247488b0..0f150eeaf2d 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1001,11 +1001,15 @@ void Log_event::print_header(FILE* file, PRINT_EVENT_INFO* print_event_info) } *c= '\0'; - /* Non-full last line */ if (hex_string[0]) + { + /* Non-full last line */ fprintf(file, "# %8.8lx %-48.48s |%s|\n# ", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); + } + else + fprintf(file, "# "); } } From f45601ce584acb22b26c367d4658197a7d19c933 Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Fri, 22 Jun 2007 15:34:28 +0300 Subject: [PATCH 7/8] Bug #27383: Crash in test "mysql_client_test" The C optimizer may decide that data access operations through pointer of different type are not related to the original data (strict aliasing). This is what happens in fetch_long_with_conversion(), when called as part of mysql_stmt_fetch() : it tries to check for truncation errors by first storing float (and other types of data) into a char * buffer and then accesses them through a float pointer. This is done to prevent the effects of excess precision when using FPU registers. However the doublestore() macro converts a double pointer to an union pointer. This violates the strict aliasing rule. Fixed by making the intermediary variables volatile ( to not re-introduce the excess precision bug) and using the intermediary value instead of the char * buffer. Note that there can be loss of precision for both signed and unsigned 64 bit integers converted to double and back, so the check must stay there (even for compatibility reasons). Based on the excellent analysis in bug 28400. --- libmysql/libmysql.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index e426d2c549e..cb60fb20863 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3663,33 +3663,38 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, case MYSQL_TYPE_FLOAT: { /* - We need to store data in the buffer before the truncation check to + We need to mark the local variable volatile to workaround Intel FPU executive precision feature. (See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 for details) - AFAIU it does not guarantee to work. */ - float data; + volatile float data; if (is_unsigned) + { data= (float) ulonglong2double(value); + *param->error= ((ulonglong) value) != ((ulonglong) data); + } else - data= (float) value; + { + data= (float)value; + *param->error= value != ((longlong) data); + } floatstore(buffer, data); - *param->error= is_unsigned ? - ((ulonglong) value) != ((ulonglong) (*(float*) buffer)) : - ((longlong) value) != ((longlong) (*(float*) buffer)); break; } case MYSQL_TYPE_DOUBLE: { - double data; + volatile double data; if (is_unsigned) + { data= ulonglong2double(value); + *param->error= ((ulonglong) value) != ((ulonglong) data); + } else + { data= (double)value; + *param->error= value != ((longlong) data); + } doublestore(buffer, data); - *param->error= is_unsigned ? - ((ulonglong) value) != ((ulonglong) (*(double*) buffer)) : - ((longlong) value) != ((longlong) (*(double*) buffer)); break; } case MYSQL_TYPE_TIME: From fbbb30a6228d84b02b941021c3356fb837977a81 Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Sun, 24 Jun 2007 01:20:14 +0500 Subject: [PATCH 8/8] Fixed bug #29095. INSERT into table from SELECT from the same table with ORDER BY and LIMIT was inserting other data than sole SELECT ... ORDER BY ... LIMIT returns. One part of the patch for bug #9676 improperly pushed LIMIT to temporary table in the presence of the ORDER BY clause. That part has been removed. --- mysql-test/r/insert_select.result | 31 +++++++++++++++++++++++++++++++ mysql-test/t/insert_select.test | 25 +++++++++++++++++++++++++ sql/sql_select.cc | 3 +-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result index 08a865e0b94..8cb94072818 100644 --- a/mysql-test/r/insert_select.result +++ b/mysql-test/r/insert_select.result @@ -688,7 +688,16 @@ ERROR 42S22: Unknown column 't2.x' in 'field list' drop table t1,t2; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 values (1), (2); +flush status; INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; +show status like 'Handler_read%'; +Variable_name Value +Handler_read_first 1 +Handler_read_key 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 1 DROP TABLE t1; CREATE TABLE t1 (x int, y int); CREATE TABLE t2 (z int, y int); @@ -773,3 +782,25 @@ d 20 20 DROP TABLE t1,t2; +CREATE TABLE t1 ( +id INT AUTO_INCREMENT PRIMARY KEY, +prev_id INT, +join_id INT DEFAULT 0); +INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2); +SELECT * FROM t1; +id prev_id join_id +1 NULL 0 +2 1 0 +3 2 0 +CREATE TABLE t2 (join_id INT); +INSERT INTO t2 (join_id) VALUES (0); +INSERT INTO t1 (prev_id) SELECT id +FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id +ORDER BY id DESC LIMIT 1; +SELECT * FROM t1; +id prev_id join_id +1 NULL 0 +2 1 0 +3 2 0 +4 3 0 +DROP TABLE t1,t2; diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index bbc51be6dc9..bf6dae96847 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -233,7 +233,9 @@ drop table t1,t2; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 values (1), (2); +flush status; INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; +show status like 'Handler_read%'; DROP TABLE t1; @@ -332,3 +334,26 @@ INSERT INTO t2 (d) SELECT * FROM t2; DROP TABLE t1,t2; + +# +# Bug #29095: incorrect pushing of LIMIT into the temporary +# table ignoring ORDER BY clause +# + +CREATE TABLE t1 ( + id INT AUTO_INCREMENT PRIMARY KEY, + prev_id INT, + join_id INT DEFAULT 0); + +INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2); +SELECT * FROM t1; + +CREATE TABLE t2 (join_id INT); +INSERT INTO t2 (join_id) VALUES (0); + +INSERT INTO t1 (prev_id) SELECT id + FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id + ORDER BY id DESC LIMIT 1; +SELECT * FROM t1; + +DROP TABLE t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f4450bf393f..85df73bb31a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1347,8 +1347,7 @@ JOIN::optimize() there are aggregate functions, because in all these cases we need all result rows. */ - ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order || - test(select_options & OPTION_BUFFER_RESULT)) && + ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order) && !tmp_group && !thd->lex->current_select->with_sum_func) ? select_limit : HA_POS_ERROR;