diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 1b428954030..f91cacd2f6d 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -285,46 +285,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL topic 3 NULL 2 Using index 2 SUBSELECT No tables used 3 UNION No tables used -SELECT 1 IN (SELECT 1 FROM t1 HAVING a); -Unknown column 'a' in 'having clause' -SELECT * from t1 where topic IN (SELECT topic FROM t1 GROUP BY date); -topic date pseudo -40143 2002-08-03 joce -43506 2002-10-02 joce -SELECT * from t1 where topic IN (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -topic date pseudo -43506 2002-10-02 joce -SELECT * from t1 where topic IN (SELECT SUM(topic) FROM t1); -topic date pseudo -SELECT * from t1 where topic = any (SELECT topic FROM st1 GROUP BY date); -topic date pseudo -40143 2002-08-03 joce -43506 2002-10-02 joce -SELECT * from t1 where topic = any (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -topic date pseudo -43506 2002-10-02 joce -SELECT * from t1 where topic = any (SELECT SUM(topic) FROM t1); -topic date pseudo -SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY date); -topic date pseudo -SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -topic date pseudo -40143 2002-08-03 joce -SELECT * from t1 where topic = all (SELECT SUM(topic) FROM t1); -topic date pseudo -SELECT * from t1 where topic <> any (SELECT SUM(topic) FROM t1); -topic date pseudo -40143 2002-08-03 joce -43506 2002-10-02 joce -CREATE TABLE `t2` ( -`numeropost` mediumint(8) unsigned NOT NULL auto_increment, -`maxnumrep` int(10) unsigned NOT NULL default '0', -PRIMARY KEY (`numeropost`), -UNIQUE KEY `maxnumrep` (`maxnumrep`)) TYPE=MyISAM ROW_FORMAT=FIXED; -INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); -SELECT SQL_CALC_FOUND_ROWS numeropost,maxnumrep FROM t2 WHERE numeropost IN (SELECT topic FROM t1 WHERE pseudo='joce' AND date >= '2002-10-06') ORDER BY maxnumrep DESC LIMIT 0,20; -numeropost maxnumrep -drop table t1,t2; +drop table t1; CREATE TABLE `t1` ( `numeropost` mediumint(8) unsigned NOT NULL auto_increment, `maxnumrep` int(10) unsigned NOT NULL default '0', @@ -349,8 +310,39 @@ numeropost maxnumrep 40143 1 SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); Unknown column 'a' in 'having clause' -drop table t1, t2; -drop table if exists t1; +SELECT 1 IN (SELECT 1 FROM t2 HAVING a); +Unknown column 'a' in 'having clause' +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY date); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY date HAVING topic < 4100); +mot topic date pseudo +joce 43506 2002-10-22 joce +SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1); +mot topic date pseudo +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY date); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY date HAVING topic < 4100); +mot topic date pseudo +joce 43506 2002-10-22 joce +SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1); +mot topic date pseudo +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY date); +mot topic date pseudo +joce 40143 2002-10-22 joce +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY date HAVING topic < 4100); +mot topic date pseudo +joce 40143 2002-10-22 joce +SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); +mot topic date pseudo +SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +drop table t1,t2; CREATE TABLE `t1` ( `numeropost` mediumint(8) unsigned NOT NULL auto_increment, `maxnumrep` int(10) unsigned NOT NULL default '0', diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index eeac0bbb81e..3888584900d 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -171,10 +171,21 @@ 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; -- error 1054 SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1); -drop table t1, t2; +-- error 1054 +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 HAVING topic < 4100); +SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1); +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY date); +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY date HAVING topic < 4100); +SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1); +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY date); +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY date HAVING topic < 4100); +SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); +SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2); +drop table t1,t2; #forumconthardwarefr7 -drop table if exists t1; CREATE TABLE `t1` ( `numeropost` mediumint(8) unsigned NOT NULL auto_increment, `maxnumrep` int(10) unsigned NOT NULL default '0', @@ -215,26 +226,7 @@ INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),( EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); -SELECT 1 IN (SELECT 1 FROM t1 HAVING a); -SELECT * from t1 where topic IN (SELECT topic FROM t1 GROUP BY date); -SELECT * from t1 where topic IN (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -SELECT * from t1 where topic IN (SELECT SUM(topic) FROM t1); -SELECT * from t1 where topic = any (SELECT topic FROM t1 GROUP BY date); -SELECT * from t1 where topic = any (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -SELECT * from t1 where topic = any (SELECT SUM(topic) FROM t1); -SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY date); -SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY date HAVING topic < 4100); -SELECT * from t1 where topic = all (SELECT SUM(topic) FROM t1); -SELECT * from t1 where topic <> any (SELECT SUM(topic) FROM t1); -CREATE TABLE `t2` ( - `numeropost` mediumint(8) unsigned NOT NULL auto_increment, - `maxnumrep` int(10) unsigned NOT NULL default '0', - PRIMARY KEY (`numeropost`), - UNIQUE KEY `maxnumrep` (`maxnumrep`)) TYPE=MyISAM ROW_FORMAT=FIXED; - -INSERT INTO t2 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); -SELECT SQL_CALC_FOUND_ROWS numeropost,maxnumrep FROM t2 WHERE numeropost IN (SELECT topic FROM t1 WHERE pseudo='joce' AND date >= '2002-10-06') ORDER BY maxnumrep DESC LIMIT 0,20; -drop table t1,t2; +drop table t1; CREATE TABLE t1 (a int(1)); INSERT INTO t1 VALUES (1); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 501d54958f1..8f406efc030 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2988,6 +2988,7 @@ join_free(JOIN *join) else { for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++) + { delete tab->select; delete tab->quick; x_free(tab->cache.buff); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index af5d6690133..cbe72313b93 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -654,7 +654,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); table_to_table_list table_to_table opt_table_list opt_as handler_rkey_function handler_read_or_scan single_multi table_wild_list table_wild_one opt_wild - union union_option + union union_list union_option precision opt_on_delete_item subselect_start opt_and subselect_end select_var_list select_var_list_init help opt_len END_OF_INPUT @@ -1254,8 +1254,8 @@ opt_binary: opt_primary: /* empty */ - | PRIMARY_SYM - + | PRIMARY_SYM; + references: REFERENCES table_ident { @@ -4316,7 +4316,11 @@ rollback: union: /* empty */ {} - |UNION_SYM union_option + | union_list + ; + +union_list: + UNION_SYM union_option { LEX *lex=Lex; if (lex->exchange)