Commit 802705f9 authored by unknown's avatar unknown

adding mandatory aliases for derived tables as per SQL-99

doing it in sql_yacc.yy does not work
this commit contains fixes for other tests
there are fixes in subselect test which will have to be changed
once fix_fields is fixed to work with aliased derived tables

parent 3284c39a
...@@ -262,4 +262,5 @@ ...@@ -262,4 +262,5 @@
#define ER_CYCLIC_REFERENCE 1243 #define ER_CYCLIC_REFERENCE 1243
#define ER_AUTO_CONVERT 1244 #define ER_AUTO_CONVERT 1244
#define ER_ILLEGAL_REFERENCE 1245 #define ER_ILLEGAL_REFERENCE 1245
#define ER_ERROR_MESSAGES 246 #define ER_DERIVED_MUST_HAVE_ALIAS 1246
#define ER_ERROR_MESSAGES 247
...@@ -17,32 +17,32 @@ select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3 ...@@ -17,32 +17,32 @@ select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3
a y a y
3 3 3 3
3 3 3 3
SELECT a FROM (SELECT 1 FROM (SELECT 1) HAVING a=1); SELECT a FROM (SELECT 1 FROM (SELECT 1) a HAVING a=1) b;
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
SELECT a,b as a FROM (SELECT '1' as a,'2' as b) HAVING a=1; SELECT a,b as a FROM (SELECT '1' as a,'2' as b) b HAVING a=1;
Column: 'a' in having clause is ambiguous Column: 'a' in having clause is ambiguous
SELECT a,2 as a FROM (SELECT '1' as a) HAVING a=2; SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=2;
a a a a
1 2 1 2
SELECT a,2 as a FROM (SELECT '1' as a) HAVING a=1; SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1;
a a a a
SELECT 1 FROM (SELECT 1) WHERE a=2; SELECT 1 FROM (SELECT 1) a WHERE a=2;
Unknown column 'a' in 'where clause' Unknown column 'a' in 'where clause'
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) as a;
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
drop table if exists t1.t2,t3; drop table if exists t1.t2,t3;
select * from (select 1); select * from (select 1) as a;
1 1
1 1
select a from (select 1 as a); select a from (select 1 as a) as b;
a a
1 1
select 1 from (select 1); select 1 from (select 1) as a;
1 1
1 1
drop table if exists t1; drop table if exists t1;
create table t1(a int not null, t char(8), index(a)); create table t1(a int not null, t char(8), index(a));
SELECT * FROM (SELECT * FROM t1) ORDER BY a ASC LIMIT 0,20; SELECT * FROM (SELECT * FROM t1) as b ORDER BY a ASC LIMIT 0,20;
a t a t
1 1 1 1
2 2 2 2
...@@ -65,6 +65,6 @@ a t ...@@ -65,6 +65,6 @@ a t
19 19 19 19
20 20 20 20
drop table if exists t1; drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a))); SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
(SELECT * FROM (SELECT 1 as a)) (SELECT * FROM (SELECT 1 as a) as a )
1 1
SELECT 1 FROM (SELECT 1) GROUP BY SUM(1); SELECT 1 FROM (SELECT 1) as a GROUP BY SUM(1);
Invalid use of group function Invalid use of group function
drop table if exists t1,t2,t3; drop table if exists t1,t2,t3;
CREATE TABLE t1 ( CREATE TABLE t1 (
......
...@@ -168,7 +168,7 @@ test2 2 2 ...@@ -168,7 +168,7 @@ test2 2 2
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
FOUND_ROWS() FOUND_ROWS()
2 2
SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) LIMIT 0; SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) as a LIMIT 0;
1 1
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
FOUND_ROWS() FOUND_ROWS()
......
...@@ -8,29 +8,29 @@ SELECT (SELECT 1) UNION SELECT (SELECT 2); ...@@ -8,29 +8,29 @@ SELECT (SELECT 1) UNION SELECT (SELECT 2);
SELECT (SELECT (SELECT 0 UNION SELECT 0)); SELECT (SELECT (SELECT 0 UNION SELECT 0));
(SELECT (SELECT 0 UNION SELECT 0)) (SELECT (SELECT 0 UNION SELECT 0))
0 0
SELECT (SELECT 1 FROM (SELECT 1) HAVING a=1) as a; SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
Reference 'a' not supported (forward reference in item list) Reference 'a' not supported (forward reference in item list)
SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVING a=1) as b; SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
Reference 'b' not supported (forward reference in item list) Reference 'b' not supported (forward reference in item list)
SELECT (SELECT 1),MAX(1) FROM (SELECT 1); SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
(SELECT 1) MAX(1) (SELECT 1) MAX(1)
1 1 1 1
SELECT (SELECT a) as a; SELECT (SELECT a) as a;
Reference 'a' not supported (forward reference in item list) Reference 'a' not supported (forward reference in item list)
EXPLAIN SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1; EXPLAIN SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1 1 PRIMARY <derived2> system NULL NULL NULL NULL 1
3 DEPENDENT SUBSELECT No tables used 3 DEPENDENT SUBSELECT No tables used
2 DERIVED No tables used 2 DERIVED No tables used
SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1; SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 1 a
1 1 1
SELECT (SELECT 1), a; SELECT (SELECT 1), a;
Unknown column 'a' in 'field list' Unknown column 'a' in 'field list'
SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1; SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
a a
1 1
SELECT 1 FROM (SELECT (SELECT a)); SELECT 1 FROM (SELECT (SELECT a) b) c;
Unknown column 'a' in 'field list' Unknown column 'a' in 'field list'
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
create table t1 (a int); create table t1 (a int);
...@@ -308,7 +308,7 @@ SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='j ...@@ -308,7 +308,7 @@ SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='j
numeropost maxnumrep numeropost maxnumrep
43506 2 43506 2
40143 1 40143 1
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b;
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
SELECT 1 IN (SELECT 1 FROM t2 HAVING a); SELECT 1 IN (SELECT 1 FROM t2 HAVING a);
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
...@@ -357,7 +357,7 @@ Subselect returns more than 1 record ...@@ -357,7 +357,7 @@ Subselect returns more than 1 record
drop table t1; drop table t1;
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b'); CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
INSERT INTO t1 VALUES (); INSERT INTO t1 VALUES ();
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b'); SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
Subselect returns more than 1 record Subselect returns more than 1 record
drop table t1; drop table t1;
CREATE TABLE `t1` ( CREATE TABLE `t1` (
...@@ -387,9 +387,9 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -387,9 +387,9 @@ id select_type table type possible_keys key key_len ref rows Extra
drop table t1; drop table t1;
CREATE TABLE t1 (a int(1)); CREATE TABLE t1 (a int(1));
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
SELECT 1 FROM (SELECT a FROM t1) HAVING (SELECT a)=1; SELECT 1,a FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
1 1 a
1 1 1
drop table t1; drop table t1;
create table t1 (a int NOT NULL, b int, primary key (a)); create table t1 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a)); create table t2 (a int NOT NULL, b int, primary key (a));
......
...@@ -9,19 +9,19 @@ CREATE TABLE t3 (a int not null, b char (10) not null); ...@@ -9,19 +9,19 @@ CREATE TABLE t3 (a int not null, b char (10) not null);
insert into t3 values (3,'f'),(4,'y'),(5,'z'),(6,'c'); insert into t3 values (3,'f'),(4,'y'),(5,'z'),(6,'c');
select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3.a>3) as t5 where t2.b=t5.b) as t4 where t1.a = t4.y; select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3.a>3) as t5 where t2.b=t5.b) as t4 where t1.a = t4.y;
--error 1054 --error 1054
SELECT a FROM (SELECT 1 FROM (SELECT 1) HAVING a=1); SELECT a FROM (SELECT 1 FROM (SELECT 1) a HAVING a=1) b;
--error 1052 --error 1052
SELECT a,b as a FROM (SELECT '1' as a,'2' as b) HAVING a=1; SELECT a,b as a FROM (SELECT '1' as a,'2' as b) b HAVING a=1;
SELECT a,2 as a FROM (SELECT '1' as a) HAVING a=2; SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=2;
SELECT a,2 as a FROM (SELECT '1' as a) HAVING a=1; SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1;
--error 1054 --error 1054
SELECT 1 FROM (SELECT 1) WHERE a=2; SELECT 1 FROM (SELECT 1) a WHERE a=2;
--error 1054 --error 1054
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) as a;
drop table if exists t1.t2,t3; drop table if exists t1.t2,t3;
select * from (select 1); select * from (select 1) as a;
select a from (select 1 as a); select a from (select 1 as a) as b;
select 1 from (select 1); select 1 from (select 1) as a;
drop table if exists t1; drop table if exists t1;
create table t1(a int not null, t char(8), index(a)); create table t1(a int not null, t char(8), index(a));
disable_query_log; disable_query_log;
...@@ -32,6 +32,6 @@ while ($1) ...@@ -32,6 +32,6 @@ while ($1)
dec $1; dec $1;
} }
enable_query_log; enable_query_log;
SELECT * FROM (SELECT * FROM t1) ORDER BY a ASC LIMIT 0,20; SELECT * FROM (SELECT * FROM t1) as b ORDER BY a ASC LIMIT 0,20;
drop table if exists t1; drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a))); SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
-- error 1111 -- error 1111
SELECT 1 FROM (SELECT 1) GROUP BY SUM(1); SELECT 1 FROM (SELECT 1) as a GROUP BY SUM(1);
# #
# Test of group (Failed for Lars Hoss <lh@pbm.de>) # Test of group (Failed for Lars Hoss <lh@pbm.de>)
# #
......
...@@ -84,7 +84,7 @@ INSERT INTO t1 (titre,maxnumrep) VALUES ...@@ -84,7 +84,7 @@ INSERT INTO t1 (titre,maxnumrep) VALUES
('test1','1'),('test2','2'),('test3','3'); ('test1','1'),('test2','2'),('test3','3');
SELECT SQL_CALC_FOUND_ROWS titre,numeropost,maxnumrep FROM t1 WHERE numeropost IN (1,2) ORDER BY maxnumrep DESC LIMIT 0, 1; SELECT SQL_CALC_FOUND_ROWS titre,numeropost,maxnumrep FROM t1 WHERE numeropost IN (1,2) ORDER BY maxnumrep DESC LIMIT 0, 1;
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) LIMIT 0; SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) as a LIMIT 0;
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE numeropost > 1 LIMIT 0; SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE numeropost > 1 LIMIT 0;
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
......
...@@ -2,19 +2,19 @@ select (select 2); ...@@ -2,19 +2,19 @@ select (select 2);
SELECT (SELECT 1) UNION SELECT (SELECT 2); SELECT (SELECT 1) UNION SELECT (SELECT 2);
SELECT (SELECT (SELECT 0 UNION SELECT 0)); SELECT (SELECT (SELECT 0 UNION SELECT 0));
-- error 1245 -- error 1245
SELECT (SELECT 1 FROM (SELECT 1) HAVING a=1) as a; SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
-- error 1245 -- error 1245
SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVING a=1) as b; SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
SELECT (SELECT 1),MAX(1) FROM (SELECT 1); SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
-- error 1245 -- error 1245
SELECT (SELECT a) as a; SELECT (SELECT a) as a;
EXPLAIN SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1; EXPLAIN SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1; SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
-- error 1054 -- error 1054
SELECT (SELECT 1), a; SELECT (SELECT 1), a;
SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1; SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
-- error 1054 -- error 1054
SELECT 1 FROM (SELECT (SELECT a)); SELECT 1 FROM (SELECT (SELECT a) b) c;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
create table t1 (a int); create table t1 (a int);
create table t2 (a int, b int); create table t2 (a int, b int);
...@@ -170,7 +170,7 @@ INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce ...@@ -170,7 +170,7 @@ INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1); select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20; SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
-- error 1054 -- error 1054
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b;
-- error 1054 -- error 1054
SELECT 1 IN (SELECT 1 FROM t2 HAVING a); SELECT 1 IN (SELECT 1 FROM t2 HAVING a);
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY date); SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY date);
...@@ -204,7 +204,7 @@ drop table t1; ...@@ -204,7 +204,7 @@ drop table t1;
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b'); CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
INSERT INTO t1 VALUES (); INSERT INTO t1 VALUES ();
-- error 1240 -- error 1240
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b'); SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
drop table t1; drop table t1;
# threadhardwarefr7 # threadhardwarefr7
...@@ -230,7 +230,7 @@ drop table t1; ...@@ -230,7 +230,7 @@ drop table t1;
CREATE TABLE t1 (a int(1)); CREATE TABLE t1 (a int(1));
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
SELECT 1 FROM (SELECT a FROM t1) HAVING (SELECT a)=1; SELECT 1,a FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
drop table t1; drop table t1;
#update with subselects #update with subselects
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -247,3 +247,4 @@ ...@@ -247,3 +247,4 @@
"Cyclic reference on subqueries", "Cyclic reference on subqueries",
"Converting column '%s' from %s to %s", "Converting column '%s' from %s to %s",
"Reference '%-.64s' not supported (%s)", "Reference '%-.64s' not supported (%s)",
"Every derived table must have it's own alias"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -108,7 +108,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) ...@@ -108,7 +108,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
table->tmp_table=TMP_TABLE; table->tmp_table=TMP_TABLE;
if (!lex->describe) if (!lex->describe)
sl->exclude(); sl->exclude();
t->db=(char *)""; t->db=(tables && tables->db) ? tables->db : (char *)"";
t->derived=(SELECT_LEX *)0; // just in case ... t->derived=(SELECT_LEX *)0; // just in case ...
} }
} }
......
...@@ -3404,8 +3404,15 @@ TABLE_LIST *st_select_lex::add_table_to_list(Table_ident *table, ...@@ -3404,8 +3404,15 @@ TABLE_LIST *st_select_lex::add_table_to_list(Table_ident *table,
} }
if (!alias) /* Alias is case sensitive */ if (!alias) /* Alias is case sensitive */
{
if (table->sel)
{
net_printf(thd,ER_DERIVED_MUST_HAVE_ALIAS);
DBUG_RETURN(0);
}
if (!(alias_str=thd->memdup(alias_str,table->table.length+1))) if (!(alias_str=thd->memdup(alias_str,table->table.length+1)))
DBUG_RETURN(0); DBUG_RETURN(0);
}
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
DBUG_RETURN(0); /* purecov: inspected */ DBUG_RETURN(0); /* purecov: inspected */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment