Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
4fdb0f48
Commit
4fdb0f48
authored
Mar 30, 2005
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postreview changes
fixed bug in IN/ALL/ANY subqeries with HAVING clause (BUG#9350)
parent
4554b1f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
617 additions
and
15 deletions
+617
-15
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+421
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+176
-0
sql/item_subselect.cc
sql/item_subselect.cc
+20
-15
No files found.
mysql-test/r/subselect.result
View file @
4fdb0f48
...
...
@@ -1873,6 +1873,380 @@ SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
a
1
3
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
a
1
3
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 2 column(s)
SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2);
a
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 2 column(s)
SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
ERROR 21000: Operand should contain 1 column(s)
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
a
1
2
3
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2);
a
2
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2);
a
1
3
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
a
2
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
a
1
3
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
a
2
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a);
a
1
3
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2);
a
1
3
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a;
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-')
0-
0-
1-
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-')
1-
0-
0-
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-')
0-
1-
0-
DROP TABLE t1;
CREATE TABLE t1 ( a double, b double );
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0);
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0);
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0);
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0);
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0);
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0);
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0);
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0);
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
a
1
3
DROP TABLE t1;
CREATE TABLE t1 ( a char(1), b char(1));
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
a
3
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
a
1
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2');
a
2
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2');
a
2
3
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2');
a
1
2
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2');
a
1
3
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2');
a
3
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2');
a
1
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2');
a
2
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2');
a
2
3
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2');
a
1
2
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2');
a
1
3
DROP TABLE t1;
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4);
...
...
@@ -2276,3 +2650,50 @@ SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
1
1
drop table t1;
create table t1 (a int);
create table t2 (a int);
insert into t1 values (1),(2);
insert into t2 values (0),(1),(2),(3);
select a from t2 where a in (select a from t1);
a
1
2
select a from t2 having a in (select a from t1);
a
1
2
prepare stmt1 from "select a from t2 where a in (select a from t1)";
execute stmt1;
a
1
2
execute stmt1;
a
1
2
deallocate prepare stmt1;
prepare stmt1 from "select a from t2 having a in (select a from t1)";
execute stmt1;
a
1
2
execute stmt1;
a
1
2
deallocate prepare stmt1;
drop table t1, t2;
create table t1 (a int, b int);
insert into t1 values (1,2);
select 1 = (select * from t1);
ERROR 21000: Operand should contain 1 column(s)
select (select * from t1) = 1;
ERROR 21000: Operand should contain 2 column(s)
select (1,2) = (select a from t1);
ERROR 21000: Operand should contain 2 column(s)
select (select a from t1) = (1,2);
ERROR 21000: Operand should contain 1 column(s)
select (1,2,3) = (select * from t1);
ERROR 21000: Operand should contain 3 column(s)
select (select * from t1) = (1,2,3);
ERROR 21000: Operand should contain 2 column(s)
mysql-test/t/subselect.test
View file @
4fdb0f48
...
...
@@ -1148,6 +1148,7 @@ SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
# with index
ALTER
TABLE
t1
ADD
INDEX
(
a
);
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
...
...
@@ -1161,8 +1162,145 @@ SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
# having clause test
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
);
# union test
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
FROM
t1
WHERE
b
=
2
);
# union + having test
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
FROM
t1
HAVING
a
=
2
);
# row tests
# < > >= <= and = ALL/ <> ANY do not support row operation
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
>
ANY
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
>
ALL
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
=
ALL
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
<>
ANY
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
# following should be converted to IN
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
=
ANY
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
);
--
error
1241
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
1
,
2
)
<>
ALL
(
SELECT
a
,
2
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
=
ANY
(
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
<>
ALL
(
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
=
ANY
(
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
<>
ALL
(
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
=
ANY
(
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
<>
ALL
(
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
UNION
SELECT
a
,
1
FROM
t1
WHERE
b
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
=
ANY
(
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
(
a
,
1
)
<>
ALL
(
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
UNION
SELECT
a
,
1
FROM
t1
HAVING
a
=
2
);
# without optimisation
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
group
by
a
);
# without optimisation + having
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
group
by
a
HAVING
a
=
2
);
# EXISTS in string contence
SELECT
concat
(
EXISTS
(
SELECT
a
FROM
t1
WHERE
b
=
2
and
a
.
a
>
t1
.
a
),
'-'
)
from
t1
a
;
SELECT
concat
(
EXISTS
(
SELECT
a
FROM
t1
WHERE
b
=
2
and
a
.
a
<
t1
.
a
),
'-'
)
from
t1
a
;
SELECT
concat
(
EXISTS
(
SELECT
a
FROM
t1
WHERE
b
=
2
and
a
.
a
=
t1
.
a
),
'-'
)
from
t1
a
;
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
a
double
,
b
double
);
INSERT
INTO
t1
VALUES
(
1
,
1
),(
2
,
2
),(
3
,
3
);
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
2
e0
);
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
a
char
(
1
),
b
char
(
1
));
INSERT
INTO
t1
VALUES
(
'1'
,
'1'
),(
'2'
,
'2'
),(
'3'
,
'3'
);
SELECT
a
FROM
t1
WHERE
a
>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
>=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<=
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<>
ANY
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
>=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<=
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
SELECT
a
FROM
t1
WHERE
a
<>
ALL
(
SELECT
a
FROM
t1
WHERE
b
=
'2'
);
DROP
TABLE
t1
;
#
# SELECT(EXISTS * ...)optimisation
#
...
...
@@ -1546,3 +1684,41 @@ create table t1 (a int);
insert
into
t1
values
(
1
),
(
2
),
(
3
);
SELECT
1
FROM
t1
WHERE
(
SELECT
1
)
in
(
SELECT
1
);
drop
table
t1
;
#
# subselect into HAVING clause (code covarage improvement)
#
create
table
t1
(
a
int
);
create
table
t2
(
a
int
);
insert
into
t1
values
(
1
),(
2
);
insert
into
t2
values
(
0
),(
1
),(
2
),(
3
);
select
a
from
t2
where
a
in
(
select
a
from
t1
);
select
a
from
t2
having
a
in
(
select
a
from
t1
);
prepare
stmt1
from
"select a from t2 where a in (select a from t1)"
;
execute
stmt1
;
execute
stmt1
;
deallocate
prepare
stmt1
;
prepare
stmt1
from
"select a from t2 having a in (select a from t1)"
;
execute
stmt1
;
execute
stmt1
;
deallocate
prepare
stmt1
;
drop
table
t1
,
t2
;
#
# single row subqueries and row operations (code covarage improvement)
#
create
table
t1
(
a
int
,
b
int
);
insert
into
t1
values
(
1
,
2
);
--
error
1241
select
1
=
(
select
*
from
t1
);
--
error
1241
select
(
select
*
from
t1
)
=
1
;
--
error
1241
select
(
1
,
2
)
=
(
select
a
from
t1
);
--
error
1241
select
(
select
a
from
t1
)
=
(
1
,
2
);
--
error
1241
select
(
1
,
2
,
3
)
=
(
select
*
from
t1
);
--
error
1241
select
(
select
*
from
t1
)
=
(
1
,
2
,
3
);
drop
table
t1
sql/item_subselect.cc
View file @
4fdb0f48
...
...
@@ -369,25 +369,13 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
}
substitution
=
select_lex
->
item_list
.
head
();
/*
as far as we moved content to upper leve
n
, field which depend of
as far as we moved content to upper leve
l
, field which depend of
'upper' select is not really dependent => we remove this dependence
*/
substitution
->
walk
(
&
Item
::
remove_dependence_processor
,
(
byte
*
)
select_lex
->
outer_select
());
if
(
join
->
conds
||
join
->
having
)
{
Item
*
cond
;
if
(
!
join
->
having
)
cond
=
join
->
conds
;
else
if
(
!
join
->
conds
)
cond
=
join
->
having
;
else
if
(
!
(
cond
=
new
Item_cond_and
(
join
->
conds
,
join
->
having
)))
goto
err
;
if
(
!
(
substitution
=
new
Item_func_if
(
cond
,
substitution
,
new
Item_null
())))
goto
err
;
}
/* SELECT without FROM clause can't have WHERE or HAVING clause */
DBUG_ASSERT
(
join
->
conds
==
0
&&
join
->
having
==
0
);
return
RES_REDUCE
;
}
return
RES_OK
;
...
...
@@ -616,8 +604,14 @@ String *Item_exists_subselect::val_str(String *str)
return
str
;
}
double
Item_in_subselect
::
val
()
{
/*
As far as Item_in_subselect called only from Item_in_optimizer this
method should not be used
*/
DBUG_ASSERT
(
0
);
DBUG_ASSERT
(
fixed
==
1
);
if
(
exec
())
{
...
...
@@ -630,6 +624,7 @@ double Item_in_subselect::val()
return
(
double
)
value
;
}
longlong
Item_in_subselect
::
val_int
()
{
DBUG_ASSERT
(
fixed
==
1
);
...
...
@@ -644,8 +639,14 @@ longlong Item_in_subselect::val_int()
return
value
;
}
String
*
Item_in_subselect
::
val_str
(
String
*
str
)
{
/*
As far as Item_in_subselect called only from Item_in_optimizer this
method should not be used
*/
DBUG_ASSERT
(
0
);
DBUG_ASSERT
(
fixed
==
1
);
if
(
exec
())
{
...
...
@@ -705,6 +706,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
Item
*
subs
;
if
(
!
select_lex
->
group_list
.
elements
&&
!
select_lex
->
having
&&
!
select_lex
->
with_sum_func
&&
!
(
select_lex
->
next_select
()))
{
...
...
@@ -1040,6 +1042,7 @@ Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
bool
result
;
DBUG_ENTER
(
"Item_in_subselect::select_in_like_transformer"
);
if
(
changed
)
{
DBUG_RETURN
(
RES_OK
);
...
...
@@ -1089,6 +1092,8 @@ Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
/* we do not support row operation for ALL/ANY/SOME */
if
(
func
!=
&
eq_creator
)
{
if
(
arena
)
thd
->
restore_backup_item_arena
(
arena
,
&
backup
);
my_error
(
ER_OPERAND_COLUMNS
,
MYF
(
0
),
1
);
DBUG_RETURN
(
RES_ERROR
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment