From f6a552b1cb3e95251bb5d4b0d447482387382871 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Sep 2005 20:18:59 -0700 Subject: [PATCH 1/3] sql_base.cc, item.cc: Fixed bug #13411. Fixed name resolution for non-qualified reference to a view column in the HAVING clause. view.result, view.test: Added a test case for bug #13411. mysql-test/t/view.test: Added a test case for bug #13411. mysql-test/r/view.result: Added a test case for bug #13411. sql/item.cc: Fixed bug #13411. Fixed name resolution for non-qualified reference to a view column in the HAVING clause. sql/sql_base.cc: Fixed bug #13411. Fixed name resolution for non-qualified reference to a view column in the HAVING clause. --- mysql-test/r/view.result | 13 +++++++++++++ mysql-test/t/view.test | 15 +++++++++++++++ sql/item.cc | 6 +++--- sql/sql_base.cc | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 5ae99e029e7..74005e0aff0 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2262,3 +2262,16 @@ WEEKDAY(date) 1 DROP TABLE t1; DROP VIEW v1, v2, v3; +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1; +a +2 +3 +SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1; +a +2 +3 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index f47418b8e0a..11a318549d4 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2139,3 +2139,18 @@ SELECT * FROM v3; DROP TABLE t1; DROP VIEW v1, v2, v3; + +# +# Bug #13411: crash when using non-qualified view column in HAVING clause +# + +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1; +SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1; + +DROP VIEW v1; +DROP TABLE t1; + + diff --git a/sql/item.cc b/sql/item.cc index 45c12d3840f..012c389b939 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1687,7 +1687,7 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const return 0; Item_field *item_field= (Item_field*) item; - if (item_field->field) + if (item_field->field && field) return item_field->field == field; /* We may come here when we are trying to find a function in a GROUP BY @@ -1701,10 +1701,10 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const */ return (!my_strcasecmp(system_charset_info, item_field->name, field_name) && - (!item_field->table_name || + (!item_field->table_name || !table_name || (!my_strcasecmp(table_alias_charset, item_field->table_name, table_name) && - (!item_field->db_name || + (!item_field->db_name || !db_name || (item_field->db_name && !strcmp(item_field->db_name, db_name)))))); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 16842c4969c..715d38925aa 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3459,7 +3459,7 @@ find_item_in_list(Item *find, List &items, uint *counter, } } } - else if (!table_name && (item->eq(find,0) || + else if (!table_name && (find->eq(item,0) || find->name && item->name && !my_strcasecmp(system_charset_info, item->name,find->name))) From d7e4e1a56173df249ec4c27a332c127752771628 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Sep 2005 23:29:02 -0700 Subject: [PATCH 2/3] item.cc: Fixed bug #13410. Fixed name resolution for qualified reference to a view column in the HAVING clause. view.result, view.test: Added a test case for bug #13410. mysql-test/t/view.test: Added a test case for bug #13410. mysql-test/r/view.result: Added a test case for bug #13410. sql/item.cc: Fixed bug #13410. Fixed name resolution for qualified reference to a view column in the HAVING clause. --- mysql-test/r/view.result | 13 +++++++++++++ mysql-test/t/view.test | 11 +++++++++++ sql/item.cc | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 74005e0aff0..9742c029706 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2275,3 +2275,16 @@ a 3 DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1; +a +2 +3 +SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; +a +2 +3 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 11a318549d4..8d3593162c7 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2153,4 +2153,15 @@ SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1; DROP VIEW v1; DROP TABLE t1; +# +# Bug #13410: failed name resolution for qualified view column in HAVING +# +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +CREATE VIEW v1 AS SELECT a,b FROM t1; +SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1; +SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/item.cc b/sql/item.cc index 012c389b939..92a7330374a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2983,7 +2983,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next) { - if ((*(cur_group->item))->type() == Item::FIELD_ITEM) + if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM) { cur_field= (Item_field*) *cur_group->item; cur_match_degree= 0; From b09b762f860cf08f491e9e0732aec3c8d1db46ff Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Sep 2005 16:55:23 +0200 Subject: [PATCH 3/3] Fix for BUG#13527 "mysql-test-run.pl truncates var/log/*.err several times during one testsuit run" mysql-test/mysql-test-run.pl: .err files of the mysqld servers should be appended to, not reset every time we restart the mysqlds during the testsuite. --- mysql-test/mysql-test-run.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 2dda1b2a6e1..47c0e8f4e41 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2137,7 +2137,8 @@ sub mysqld_start ($$$$) { { if ( $pid= mtr_spawn($exe, $args, "", $master->[$idx]->{'path_myerr'}, - $master->[$idx]->{'path_myerr'}, "") ) + $master->[$idx]->{'path_myerr'}, "", + { append_log_file => 1 }) ) { return sleep_until_file_created($master->[$idx]->{'path_mypid'}, $master->[$idx]->{'start_timeout'}, $pid); @@ -2148,7 +2149,8 @@ sub mysqld_start ($$$$) { { if ( $pid= mtr_spawn($exe, $args, "", $slave->[$idx]->{'path_myerr'}, - $slave->[$idx]->{'path_myerr'}, "") ) + $slave->[$idx]->{'path_myerr'}, "", + { append_log_file => 1 }) ) { return sleep_until_file_created($slave->[$idx]->{'path_mypid'}, $master->[$idx]->{'start_timeout'}, $pid);