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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1ad63bdf
Commit
1ad63bdf
authored
Jan 26, 2007
by
igor@olga.mysql.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge olga.mysql.com:/home/igor/mysql-5.0-opt
into olga.mysql.com:/home/igor/dev-opt/mysql-5.0-opt-bug24653
parents
45f61a06
7740b024
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
163 additions
and
1 deletion
+163
-1
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+74
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+59
-0
sql/filesort.cc
sql/filesort.cc
+5
-1
sql/item_subselect.cc
sql/item_subselect.cc
+4
-0
sql/sql_select.cc
sql/sql_select.cc
+21
-0
No files found.
mysql-test/r/subselect.result
View file @
1ad63bdf
...
...
@@ -3046,6 +3046,80 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
DROP TABLE t1;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (2), (4), (1), (3);
CREATE TABLE t2 (b int, c int);
INSERT INTO t2 VALUES
(2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 );
a
2
4
1
3
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1);
ERROR 21000: Subquery returns more than 1 row
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a;
a
1
2
3
4
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a;
ERROR 21000: Subquery returns more than 1 row
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2);
b MAX(c)
1 4
2 2
4 4
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1);
ERROR 21000: Subquery returns more than 1 row
SELECT a FROM t1 GROUP BY a
HAVING IFNULL((SELECT b FROM t2 WHERE b > 2),
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
a
1
2
3
4
SELECT a FROM t1 GROUP BY a
HAVING IFNULL((SELECT b FROM t2 WHERE b > 1),
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
ERROR 21000: Subquery returns more than 1 row
SELECT a FROM t1 GROUP BY a
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
a
4
SELECT a FROM t1 GROUP BY a
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3;
ERROR 21000: Subquery returns more than 1 row
SELECT a FROM t1
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2),
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
a
2
4
1
3
SELECT a FROM t1
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1),
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
ERROR 21000: Subquery returns more than 1 row
SELECT a FROM t1
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
a
2
1
3
4
SELECT a FROM t1
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
ERROR 21000: Subquery returns more than 1 row
DROP TABLE t1,t2;
create table t1 (df decimal(5,1));
insert into t1 values(1.1);
insert into t1 values(2.2);
...
...
mysql-test/t/subselect.test
View file @
1ad63bdf
...
...
@@ -2000,6 +2000,65 @@ SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL;
EXPLAIN
SELECT
a
FROM
t1
WHERE
(
SELECT
1
FROM
DUAL
WHERE
1
=
0
)
IS
NULL
;
DROP
TABLE
t1
;
#
# Bug 24653: sorting by expressions containing subselects
# that return more than one row
#
CREATE
TABLE
t1
(
a
int
);
INSERT
INTO
t1
VALUES
(
2
),
(
4
),
(
1
),
(
3
);
CREATE
TABLE
t2
(
b
int
,
c
int
);
INSERT
INTO
t2
VALUES
(
2
,
1
),
(
1
,
3
),
(
2
,
1
),
(
4
,
4
),
(
2
,
2
),
(
1
,
4
);
SELECT
a
FROM
t1
ORDER
BY
(
SELECT
c
FROM
t2
WHERE
b
>
2
);
--
error
1242
SELECT
a
FROM
t1
ORDER
BY
(
SELECT
c
FROM
t2
WHERE
b
>
1
);
SELECT
a
FROM
t1
ORDER
BY
(
SELECT
c
FROM
t2
WHERE
b
>
2
),
a
;
--
error
1242
SELECT
a
FROM
t1
ORDER
BY
(
SELECT
c
FROM
t2
WHERE
b
>
1
),
a
;
SELECT
b
,
MAX
(
c
)
FROM
t2
GROUP
BY
b
,
(
SELECT
c
FROM
t2
WHERE
b
>
2
);
--
error
1242
SELECT
b
,
MAX
(
c
)
FROM
t2
GROUP
BY
b
,
(
SELECT
c
FROM
t2
WHERE
b
>
1
);
SELECT
a
FROM
t1
GROUP
BY
a
HAVING
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
2
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
2
ORDER
BY
b
))
>
3
;
--
error
1242
SELECT
a
FROM
t1
GROUP
BY
a
HAVING
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
1
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
2
ORDER
BY
b
))
>
3
;
SELECT
a
FROM
t1
GROUP
BY
a
HAVING
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
4
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
2
ORDER
BY
b
))
>
3
;
--
error
1242
SELECT
a
FROM
t1
GROUP
BY
a
HAVING
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
4
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
1
ORDER
BY
b
))
>
3
;
SELECT
a
FROM
t1
ORDER
BY
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
2
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
2
ORDER
BY
b
));
--
error
1242
SELECT
a
FROM
t1
ORDER
BY
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
1
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
1
ORDER
BY
b
));
SELECT
a
FROM
t1
ORDER
BY
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
4
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
2
ORDER
BY
b
));
--
error
1242
SELECT
a
FROM
t1
ORDER
BY
IFNULL
((
SELECT
b
FROM
t2
WHERE
b
>
4
),
(
SELECT
c
FROM
t2
WHERE
c
=
a
AND
b
>
1
ORDER
BY
b
));
DROP
TABLE
t1
,
t2
;
# End of 4.1 tests
#
...
...
sql/filesort.cc
View file @
1ad63bdf
...
...
@@ -428,7 +428,8 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
byte
*
ref_pos
,
*
next_pos
,
ref_buff
[
MAX_REFLENGTH
];
my_off_t
record
;
TABLE
*
sort_form
;
volatile
THD
::
killed_state
*
killed
=
&
current_thd
->
killed
;
THD
*
thd
=
current_thd
;
volatile
THD
::
killed_state
*
killed
=
&
thd
->
killed
;
handler
*
file
;
DBUG_ENTER
(
"find_all_keys"
);
DBUG_PRINT
(
"info"
,(
"using: %s"
,(
select
?
select
->
quick
?
"ranges"
:
"where"
:
"every row"
)));
...
...
@@ -525,6 +526,9 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
}
else
file
->
unlock_row
();
/* It does not make sense to read more keys in case of a fatal error */
if
(
thd
->
net
.
report_error
)
DBUG_RETURN
(
HA_POS_ERROR
);
}
if
(
quick_select
)
{
...
...
sql/item_subselect.cc
View file @
1ad63bdf
...
...
@@ -195,6 +195,10 @@ bool Item_subselect::exec()
{
int
res
;
if
(
thd
->
net
.
report_error
)
/* Do not execute subselect in case of a fatal error */
return
1
;
res
=
engine
->
exec
();
if
(
engine_changed
)
...
...
sql/sql_select.cc
View file @
1ad63bdf
...
...
@@ -855,6 +855,13 @@ JOIN::optimize()
{
ORDER
*
org_order
=
order
;
order
=
remove_const
(
this
,
order
,
conds
,
1
,
&
simple_order
);
if
(
thd
->
net
.
report_error
)
{
error
=
1
;
DBUG_PRINT
(
"error"
,(
"Error from remove_const"
));
DBUG_RETURN
(
1
);
}
/*
If we are using ORDER BY NULL or ORDER BY const_expression,
return result in any order (even if we are using a GROUP BY)
...
...
@@ -962,6 +969,12 @@ JOIN::optimize()
group_list
=
remove_const
(
this
,
(
old_group_list
=
group_list
),
conds
,
rollup
.
state
==
ROLLUP
::
STATE_NONE
,
&
simple_group
);
if
(
thd
->
net
.
report_error
)
{
error
=
1
;
DBUG_PRINT
(
"error"
,(
"Error from remove_const"
));
DBUG_RETURN
(
1
);
}
if
(
old_group_list
&&
!
group_list
)
select_distinct
=
0
;
}
...
...
@@ -978,6 +991,12 @@ JOIN::optimize()
{
group_list
=
procedure
->
group
=
remove_const
(
this
,
procedure
->
group
,
conds
,
1
,
&
simple_group
);
if
(
thd
->
net
.
report_error
)
{
error
=
1
;
DBUG_PRINT
(
"error"
,(
"Error from remove_const"
));
DBUG_RETURN
(
1
);
}
calc_group_buffer
(
this
,
group_list
);
}
...
...
@@ -6415,6 +6434,8 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
*
simple_order
=
0
;
// Must do a temp table to sort
else
if
(
!
(
order_tables
&
not_const_tables
))
{
if
(
order
->
item
[
0
]
->
with_subselect
)
order
->
item
[
0
]
->
val_str
(
&
order
->
item
[
0
]
->
str_value
);
DBUG_PRINT
(
"info"
,(
"removing: %s"
,
order
->
item
[
0
]
->
full_name
()));
continue
;
// skip const item
}
...
...
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