Commit 83e25bbc authored by unknown's avatar unknown

fixed removed by previos patch thd->allow_sum_func "side effect" of setup_conds

renamed tables to prevent droping real tables


mysql-test/r/group_by.result:
  test of error message
mysql-test/r/subselect.result:
  renamed tables to prevent droping real tables
mysql-test/t/group_by.test:
  test of error message
mysql-test/t/subselect.test:
  renamed tables to prevent droping real tables
sql/sql_base.cc:
  moved thd->allow_sum_func assignment to upper level
sql/sql_select.cc:
  fixed removed by previos patch thd->allow_sum_func "side effect" of setup_conds
parent 4587ddda
SELECT 1 FROM (SELECT 1) GROUP BY SUM(1);
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 (
spID int(10) unsigned, spID int(10) unsigned,
......
...@@ -17,7 +17,7 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 1); ...@@ -17,7 +17,7 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 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)
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit; 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);
create table t3 (a int); create table t3 (a int);
...@@ -140,11 +140,11 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -140,11 +140,11 @@ id select_type table type possible_keys key key_len ref rows Extra
3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 Using where
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
Subselect returns more than 1 record Subselect returns more than 1 record
create table attend (patient_uq int, clinic_uq int, index i1 (clinic_uq)); create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
create table clinic( uq int primary key, name char(25)); create table t7( uq int primary key, name char(25));
insert into clinic values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta"); insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
insert into attend values (1,1),(1,2),(2,2),(1,3); insert into t6 values (1,1),(1,2),(2,2),(1,3);
select * from attend where exists (select * from clinic where uq = clinic_uq); select * from t6 where exists (select * from t7 where uq = clinic_uq);
patient_uq clinic_uq patient_uq clinic_uq
1 1 1 1
1 2 1 2
...@@ -167,117 +167,113 @@ W 1 ...@@ -167,117 +167,113 @@ W 1
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
a b a b
W a W a
drop table if exists inscrit; drop table if exists t8;
CREATE TABLE `inscrit` ( CREATE TABLE `t8` (
`pseudo` varchar(35) character set latin1 NOT NULL default '', `pseudo` varchar(35) character set latin1 NOT NULL default '',
`email` varchar(60) character set latin1 NOT NULL default '', `email` varchar(60) character set latin1 NOT NULL default '',
PRIMARY KEY (`pseudo`), PRIMARY KEY (`pseudo`),
UNIQUE KEY `email` (`email`) UNIQUE KEY `email` (`email`)
) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test'); INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN SELECT pseudo,(SELECT email FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce')) FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce'); EXPLAIN SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
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 inscrit const PRIMARY PRIMARY 35 const 1 1 PRIMARY t8 const PRIMARY PRIMARY 35 const 1
4 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1 4 SUBSELECT t8 const PRIMARY PRIMARY 35 const 1
2 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1 2 SUBSELECT t8 const PRIMARY PRIMARY 35 const 1
3 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1 3 SUBSELECT t8 const PRIMARY PRIMARY 35 const 1
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
inscrit WHERE pseudo='joce'); t8 WHERE pseudo='joce');
Subselect returns more than 1 field Subselect returns more than 1 field
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT * FROM inscrit WHERE SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE
pseudo='joce'); pseudo='joce');
Subselect returns more than 1 field Subselect returns more than 1 field
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce'); SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
pseudo pseudo
joce joce
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%'); SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
Subselect returns more than 1 record Subselect returns more than 1 record
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
drop table if exists searchconthardwarefr3; CREATE TABLE `t1` (
CREATE TABLE `searchconthardwarefr3` (
`topic` mediumint(8) unsigned NOT NULL default '0', `topic` mediumint(8) unsigned NOT NULL default '0',
`date` date NOT NULL default '0000-00-00', `date` date NOT NULL default '0000-00-00',
`pseudo` varchar(35) character set latin1 NOT NULL default '', `pseudo` varchar(35) character set latin1 NOT NULL default '',
PRIMARY KEY (`pseudo`,`date`,`topic`), PRIMARY KEY (`pseudo`,`date`,`topic`),
KEY `topic` (`topic`) KEY `topic` (`topic`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
INSERT INTO searchconthardwarefr3 (topic,date,pseudo) VALUES INSERT INTO t1 (topic,date,pseudo) VALUES
('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); ('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'; EXPLAIN SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
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 SIMPLE searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 Using where; Using index 1 SIMPLE t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'); EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
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 No tables used 1 PRIMARY No tables used
2 SUBSELECT searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 Using where; Using index 2 SUBSELECT t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'; SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
date date
2002-08-03 2002-08-03
SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'); SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
(SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03') (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')
2002-08-03 2002-08-03
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1; SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
1 1
1 1
1 1
1 1
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1; SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
Subselect returns more than 1 record Subselect returns more than 1 record
EXPLAIN SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1); EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 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 searchconthardwarefr3 index NULL topic 3 NULL 2 Using index 1 PRIMARY t1 index NULL topic 3 NULL 2 Using index
2 SUBSELECT No tables used 2 SUBSELECT No tables used
3 UNION No tables used 3 UNION No tables used
drop table searchconthardwarefr3; drop table t1;
drop table if exists forumconthardwarefr7, searchconthardwarefr7; CREATE TABLE `t1` (
CREATE TABLE `forumconthardwarefr7` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0', `maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`), PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`) UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED; ) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
CREATE TABLE `searchconthardwarefr7` ( CREATE TABLE `t2` (
`mot` varchar(30) NOT NULL default '', `mot` varchar(30) NOT NULL default '',
`topic` mediumint(8) unsigned NOT NULL default '0', `topic` mediumint(8) unsigned NOT NULL default '0',
`date` date NOT NULL default '0000-00-00', `date` date NOT NULL default '0000-00-00',
`pseudo` varchar(35) NOT NULL default '', `pseudo` varchar(35) NOT NULL default '',
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`) PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
INSERT INTO searchconthardwarefr7 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce'); INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
a a
40143 40143
SELECT numeropost,maxnumrep FROM forumconthardwarefr7 WHERE exists (SELECT 1 FROM searchconthardwarefr7 WHERE (mot='joce') AND date >= '2002-10-21' AND forumconthardwarefr7.numeropost = searchconthardwarefr7.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;
numeropost maxnumrep numeropost maxnumrep
43506 2 43506 2
40143 1 40143 1
SELECT (SELECT 1) as a FROM (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1);
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
drop table forumconthardwarefr7, searchconthardwarefr7; drop table t1, t2;
drop table if exists forumconthardwarefr7; drop table if exists t1;
CREATE TABLE `forumconthardwarefr7` ( CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0', `maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`), PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`) UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED; ) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (1,0),(2,1); INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
Subselect returns more than 1 record Subselect returns more than 1 record
select numeropost as a FROM forumconthardwarefr7 ORDER BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
Subselect returns more than 1 record Subselect returns more than 1 record
drop table if exists forumconthardwarefr7; drop table t1;
drop table if exists iftest; CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
CREATE TABLE iftest (field char(1) NOT NULL DEFAULT 'b'); INSERT INTO t1 VALUES ();
INSERT INTO iftest VALUES (); SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b');
SELECT field FROM iftest WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b');
Subselect returns more than 1 record Subselect returns more than 1 record
drop table iftest; drop table t1;
drop table if exists threadhardwarefr7; CREATE TABLE `t1` (
CREATE TABLE `threadhardwarefr7` (
`numeropost` mediumint(8) unsigned NOT NULL default '0', `numeropost` mediumint(8) unsigned NOT NULL default '0',
`numreponse` int(10) unsigned NOT NULL auto_increment, `numreponse` int(10) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) NOT NULL default '', `pseudo` varchar(35) NOT NULL default '',
...@@ -285,20 +281,20 @@ PRIMARY KEY (`numeropost`,`numreponse`), ...@@ -285,20 +281,20 @@ PRIMARY KEY (`numeropost`,`numreponse`),
UNIQUE KEY `numreponse` (`numreponse`), UNIQUE KEY `numreponse` (`numreponse`),
KEY `pseudo` (`pseudo`,`numeropost`) KEY `pseudo` (`pseudo`,`numeropost`)
) TYPE=MyISAM; ) TYPE=MyISAM;
SELECT (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a),numreponse FROM (SELECT * FROM threadhardwarefr7) as a; SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
Reference 'numreponse' not supported (forward reference in item list) Reference 'numreponse' not supported (forward reference in item list)
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a) FROM (SELECT * FROM threadhardwarefr7) as a; SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
Unknown column 'a' in 'having clause' Unknown column 'a' in 'having clause'
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=1) FROM (SELECT * FROM threadhardwarefr7) as a; SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
numreponse (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=1) numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO threadhardwarefr7 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM threadhardwarefr7 WHERE numeropost='1'); EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
Subselect returns more than 1 record Subselect returns more than 1 record
EXPLAIN SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1'; EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='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 SIMPLE Select tables optimized away 1 SIMPLE Select tables optimized away
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1'); EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='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 threadhardwarefr7 const PRIMARY,numreponse PRIMARY 7 const,const 1 1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1
2 SUBSELECT Select tables optimized away 2 SUBSELECT Select tables optimized away
drop table if exists threadhardwarefrtest7; drop table t1;
-- error 1111
SELECT 1 FROM (SELECT 1) GROUP BY SUM(1);
# #
# Test of group (Failed for Lars Hoss <lh@pbm.de>) # Test of group (Failed for Lars Hoss <lh@pbm.de>)
# #
......
...@@ -8,7 +8,7 @@ SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVI ...@@ -8,7 +8,7 @@ SELECT (SELECT 1 FROM (SELECT 1) HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) HAVI
SELECT (SELECT 1),MAX(1) FROM (SELECT 1); SELECT (SELECT 1),MAX(1) FROM (SELECT 1);
-- error 1245 -- error 1245
SELECT (SELECT a) as a; SELECT (SELECT a) as a;
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit; 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);
create table t3 (a int); create table t3 (a int);
...@@ -57,11 +57,11 @@ select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) ...@@ -57,11 +57,11 @@ select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)
explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
-- error 1240 -- error 1240
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
create table attend (patient_uq int, clinic_uq int, index i1 (clinic_uq)); create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
create table clinic( uq int primary key, name char(25)); create table t7( uq int primary key, name char(25));
insert into clinic values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta"); insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
insert into attend values (1,1),(1,2),(2,2),(1,3); insert into t6 values (1,1),(1,2),(2,2),(1,3);
select * from attend where exists (select * from clinic where uq = clinic_uq); select * from t6 where exists (select * from t7 where uq = clinic_uq);
# not unique fields # not unique fields
-- error 1052 -- error 1052
...@@ -80,62 +80,62 @@ SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1); ...@@ -80,62 +80,62 @@ SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2); SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
drop table if exists inscrit; drop table if exists t8;
CREATE TABLE `inscrit` ( CREATE TABLE `t8` (
`pseudo` varchar(35) character set latin1 NOT NULL default '', `pseudo` varchar(35) character set latin1 NOT NULL default '',
`email` varchar(60) character set latin1 NOT NULL default '', `email` varchar(60) character set latin1 NOT NULL default '',
PRIMARY KEY (`pseudo`), PRIMARY KEY (`pseudo`),
UNIQUE KEY `email` (`email`) UNIQUE KEY `email` (`email`)
) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test'); INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1'); INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN SELECT pseudo,(SELECT email FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce')) FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce'); EXPLAIN SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
-- error 1239 -- error 1239
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
inscrit WHERE pseudo='joce'); t8 WHERE pseudo='joce');
-- error 1239 -- error 1239
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT * FROM inscrit WHERE SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE
pseudo='joce'); pseudo='joce');
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce'); SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
-- error 1240 -- error 1240
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%'); SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
drop table if exists searchconthardwarefr3; #searchconthardwarefr3
CREATE TABLE `searchconthardwarefr3` ( CREATE TABLE `t1` (
`topic` mediumint(8) unsigned NOT NULL default '0', `topic` mediumint(8) unsigned NOT NULL default '0',
`date` date NOT NULL default '0000-00-00', `date` date NOT NULL default '0000-00-00',
`pseudo` varchar(35) character set latin1 NOT NULL default '', `pseudo` varchar(35) character set latin1 NOT NULL default '',
PRIMARY KEY (`pseudo`,`date`,`topic`), PRIMARY KEY (`pseudo`,`date`,`topic`),
KEY `topic` (`topic`) KEY `topic` (`topic`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
INSERT INTO searchconthardwarefr3 (topic,date,pseudo) VALUES INSERT INTO t1 (topic,date,pseudo) VALUES
('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); ('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'; EXPLAIN SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'); EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'; SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03'); SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1; SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
-- error 1240 -- error 1240
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1; SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
EXPLAIN SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1); EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
drop table searchconthardwarefr3; drop table t1;
drop table if exists forumconthardwarefr7, searchconthardwarefr7; #forumconthardwarefr7 searchconthardwarefr7
CREATE TABLE `forumconthardwarefr7` ( CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0', `maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`), PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`) UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED; ) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
CREATE TABLE `searchconthardwarefr7` ( CREATE TABLE `t2` (
`mot` varchar(30) NOT NULL default '', `mot` varchar(30) NOT NULL default '',
`topic` mediumint(8) unsigned NOT NULL default '0', `topic` mediumint(8) unsigned NOT NULL default '0',
`date` date NOT NULL default '0000-00-00', `date` date NOT NULL default '0000-00-00',
...@@ -143,37 +143,38 @@ CREATE TABLE `searchconthardwarefr7` ( ...@@ -143,37 +143,38 @@ CREATE TABLE `searchconthardwarefr7` (
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`) PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC; ) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
INSERT INTO searchconthardwarefr7 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce'); INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
SELECT numeropost,maxnumrep FROM forumconthardwarefr7 WHERE exists (SELECT 1 FROM searchconthardwarefr7 WHERE (mot='joce') AND date >= '2002-10-21' AND forumconthardwarefr7.numeropost = searchconthardwarefr7.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 forumconthardwarefr7 HAVING a=1); SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1);
drop table forumconthardwarefr7, searchconthardwarefr7; drop table t1, t2;
drop table if exists forumconthardwarefr7; #forumconthardwarefr7
CREATE TABLE `forumconthardwarefr7` ( drop table if exists t1;
CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, `numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0', `maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`), PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`) UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED; ) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (1,0),(2,1); INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
-- error 1240 -- error 1240
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
-- error 1240 -- error 1240
select numeropost as a FROM forumconthardwarefr7 ORDER BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1); select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
drop table if exists forumconthardwarefr7; drop table t1;
drop table if exists iftest; #iftest
CREATE TABLE iftest (field char(1) NOT NULL DEFAULT 'b'); CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
INSERT INTO iftest VALUES (); INSERT INTO t1 VALUES ();
-- error 1240 -- error 1240
SELECT field FROM iftest 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) HAVING field='b');
drop table iftest; drop table t1;
drop table if exists threadhardwarefr7; # threadhardwarefr7
CREATE TABLE `threadhardwarefr7` ( CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL default '0', `numeropost` mediumint(8) unsigned NOT NULL default '0',
`numreponse` int(10) unsigned NOT NULL auto_increment, `numreponse` int(10) unsigned NOT NULL auto_increment,
`pseudo` varchar(35) NOT NULL default '', `pseudo` varchar(35) NOT NULL default '',
...@@ -182,13 +183,13 @@ CREATE TABLE `threadhardwarefr7` ( ...@@ -182,13 +183,13 @@ CREATE TABLE `threadhardwarefr7` (
KEY `pseudo` (`pseudo`,`numeropost`) KEY `pseudo` (`pseudo`,`numeropost`)
) TYPE=MyISAM; ) TYPE=MyISAM;
-- error 1245 -- error 1245
SELECT (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a),numreponse FROM (SELECT * FROM threadhardwarefr7) as a; SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
-- error 1054 -- error 1054
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a) FROM (SELECT * FROM threadhardwarefr7) as a; SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=1) FROM (SELECT * FROM threadhardwarefr7) as a; SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
INSERT INTO threadhardwarefr7 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
-- error 1240 -- error 1240
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM threadhardwarefr7 WHERE numeropost='1'); EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
EXPLAIN SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1'; EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1'); EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
drop table if exists threadhardwarefrtest7; drop table t1;
...@@ -2227,8 +2227,6 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) ...@@ -2227,8 +2227,6 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
thd->set_query_id=1; thd->set_query_id=1;
thd->cond_count= 0; thd->cond_count= 0;
bool save_allow_sum_func= thd->allow_sum_func;
thd->allow_sum_func= 0;
if (*conds) if (*conds)
{ {
thd->where="where clause"; thd->where="where clause";
...@@ -2301,7 +2299,6 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) ...@@ -2301,7 +2299,6 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
table->on_expr=and_conds(table->on_expr,cond_and); table->on_expr=and_conds(table->on_expr,cond_and);
} }
} }
thd->allow_sum_func= save_allow_sum_func;
DBUG_RETURN(test(thd->fatal_error)); DBUG_RETURN(test(thd->fatal_error));
} }
......
...@@ -199,6 +199,26 @@ void fix_tables_pointers(SELECT_LEX *select_lex) ...@@ -199,6 +199,26 @@ void fix_tables_pointers(SELECT_LEX *select_lex)
} }
} }
/*
Inline function to setup clauses without sum functions
*/
inline int setup_without_group(THD *thd, TABLE_LIST *tables,
List<Item> &fields,
List<Item> &all_fields,
COND **conds,
ORDER *order,
ORDER *group, bool *hidden_group_fields)
{
bool save_allow_sum_func= thd->allow_sum_func;
thd->allow_sum_func= 0;
int res= (setup_conds(thd,tables, conds) ||
setup_order(thd,tables, fields, all_fields, order) ||
setup_group(thd,tables, fields, all_fields, group,
hidden_group_fields));
thd->allow_sum_func= save_allow_sum_func;
return res;
}
/***************************************************************************** /*****************************************************************************
Check fields, find best join, do the select and output fields. Check fields, find best join, do the select and output fields.
mysql_select assumes that all tables are already opened mysql_select assumes that all tables are already opened
...@@ -233,10 +253,8 @@ JOIN::prepare(TABLE_LIST *tables_init, ...@@ -233,10 +253,8 @@ JOIN::prepare(TABLE_LIST *tables_init,
if (setup_tables(tables_list) || if (setup_tables(tables_list) ||
setup_fields(thd,tables_list,fields_list,1,&all_fields,1) || setup_fields(thd,tables_list,fields_list,1,&all_fields,1) ||
setup_conds(thd,tables_list,&conds) || setup_without_group(thd, tables_list, fields_list, all_fields,
setup_order(thd,tables_list,fields_list,all_fields,order) || &conds, order, group_list, &hidden_group_fields))
setup_group(thd,tables_list,fields_list,all_fields,group_list,
&hidden_group_fields))
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(-1); /* purecov: inspected */
if (having) if (having)
......
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