From 6fc17dab1ec371ca2849a6df8661b5420d1cb255 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Jan 2007 00:27:11 -0800 Subject: Fixed bug #25427. In the method Item_field::fix_fields we try to resolve the name of the field against the names of the aliases that occur in the select list. This is done by a call of the function find_item_in_list. When this function finds several occurrences of the field name it sends an error message to the error queue and returns 0. Yet the code did not take into account that find_item_in_list could return 0 and tried to dereference the returned value. mysql-test/r/order_by.result: Added a test case for bug #25427. mysql-test/t/order_by.test: Added a test case for bug #25427. sql/item.cc: Fixed bug #25427. In the method Item_field::fix_fields we try to resolve the name of the field against the names of the aliases that occur in the select list. This is done by a call of the function find_item_in_list. When this function finds several occurrences of the field name it sends an error message to the error queue and returns 0. Yet the code did not take into account that find_item_in_list could return 0 and tried to dereference the returned value. --- mysql-test/r/order_by.result | 8 ++++++++ mysql-test/t/order_by.test | 15 +++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 320bb89b62e..ec6032be882 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -847,3 +847,11 @@ num (select num + 2 FROM t1 LIMIT 1) SELECT a.a + 1 AS num FROM t1 a JOIN t1 b ON num = b.a; ERROR 42S22: Unknown column 'num' in 'on clause' DROP TABLE t1; +CREATE TABLE t1 (a int); +SELECT p.a AS val, q.a AS val1 FROM t1 p, t1 q ORDER BY val > 1; +val val1 +SELECT p.a AS val, q.a AS val FROM t1 p, t1 q ORDER BY val; +ERROR 23000: Column 'val' in order clause is ambiguous +SELECT p.a AS val, q.a AS val FROM t1 p, t1 q ORDER BY val > 1; +ERROR 23000: Column 'val' in order clause is ambiguous +DROP TABLE t1; diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index a8024be7032..3c23ea76d99 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -575,4 +575,19 @@ SELECT a + 1 AS num, (select num + 2 FROM t1 LIMIT 1) FROM t1; SELECT a.a + 1 AS num FROM t1 a JOIN t1 b ON num = b.a; DROP TABLE t1; +# +# Bug #25427: crash when order by expression contains a name +# that cannot be resolved unambiguously +# + +CREATE TABLE t1 (a int); + +SELECT p.a AS val, q.a AS val1 FROM t1 p, t1 q ORDER BY val > 1; +--error 1052 +SELECT p.a AS val, q.a AS val FROM t1 p, t1 q ORDER BY val; +--error 1052 +SELECT p.a AS val, q.a AS val FROM t1 p, t1 q ORDER BY val > 1; + +DROP TABLE t1; + # End of 4.1 tests -- cgit v1.2.1 From 6c41a043a490d5e80dc5367d6d24d2c65064888c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Jan 2007 19:10:01 +0200 Subject: BUG#25106: A USING clause in combination with a VIEW results in column aliases ignored When a column reference to a column in JOIN USING is resolved and a new Item is created for this column the user defined name was lost. This fix preserves the alias by setting the name of the new Item to the original alias. mysql-test/r/join.result: BUG#25106: A USING clause in combination with a VIEW results in column aliases ignored - test case mysql-test/t/join.test: BUG#25106: A USING clause in combination with a VIEW results in column aliases ignored - test case sql/sql_base.cc: BUG#25106: A USING clause in combination with a VIEW results in column aliases ignored - take the alias of the Item to be replaced and set it into the newly allocated Item. --- mysql-test/r/join.result | 16 ++++++++++++++++ mysql-test/t/join.test | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'mysql-test') diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index 8ad6f344c4f..f3114dc55dd 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -764,3 +764,19 @@ natural join t5; y c b a z 1 3 2 1 4 drop table t1, t2, t3, t4, t5; +CREATE TABLE t1 (ID INTEGER, Name VARCHAR(50)); +CREATE TABLE t2 (Test_ID INTEGER); +CREATE VIEW v1 (Test_ID, Description) AS SELECT ID, Name FROM t1; +CREATE TABLE tv1 SELECT Description AS Name FROM v1 JOIN t2 +USING (Test_ID); +DESCRIBE tv1; +Field Type Null Key Default Extra +Name varchar(50) YES NULL +CREATE TABLE tv2 SELECT Description AS Name FROM v1 JOIN t2 +ON v1.Test_ID = t2.Test_ID; +DESCRIBE tv2; +Field Type Null Key Default Extra +Name varchar(50) YES NULL +DROP VIEW v1; +DROP TABLE t1,t2,tv1,tv2; +End of 5.0 tests. diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test index ab85cc5bed2..99dd21e8ee2 100644 --- a/mysql-test/t/join.test +++ b/mysql-test/t/join.test @@ -591,3 +591,23 @@ select * from ((t3 natural join (t1 natural join t2)) natural join t4) drop table t1, t2, t3, t4, t5; # End of tests for WL#2486 - natural/using join + +# +# BUG#25106: A USING clause in combination with a VIEW results in column +# aliases ignored +# +CREATE TABLE t1 (ID INTEGER, Name VARCHAR(50)); +CREATE TABLE t2 (Test_ID INTEGER); +CREATE VIEW v1 (Test_ID, Description) AS SELECT ID, Name FROM t1; + +CREATE TABLE tv1 SELECT Description AS Name FROM v1 JOIN t2 + USING (Test_ID); +DESCRIBE tv1; +CREATE TABLE tv2 SELECT Description AS Name FROM v1 JOIN t2 + ON v1.Test_ID = t2.Test_ID; +DESCRIBE tv2; + +DROP VIEW v1; +DROP TABLE t1,t2,tv1,tv2; + +--echo End of 5.0 tests. -- cgit v1.2.1