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
edc69e32
Commit
edc69e32
authored
Mar 13, 2011
by
Igor Babaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
26d6806f
3d3d5f1d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
4 deletions
+158
-4
mysql-test/r/subselect.result
mysql-test/r/subselect.result
+28
-0
mysql-test/r/subselect_no_mat.result
mysql-test/r/subselect_no_mat.result
+28
-0
mysql-test/r/subselect_no_opts.result
mysql-test/r/subselect_no_opts.result
+28
-0
mysql-test/r/subselect_no_semijoin.result
mysql-test/r/subselect_no_semijoin.result
+28
-0
mysql-test/t/subselect.test
mysql-test/t/subselect.test
+23
-0
sql/sql_select.cc
sql/sql_select.cc
+21
-4
sql/sql_select.h
sql/sql_select.h
+2
-0
No files found.
mysql-test/r/subselect.result
View file @
edc69e32
...
...
@@ -5018,3 +5018,31 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY it2 ALL NULL NULL NULL NULL 4
2 SUBQUERY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL);
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
DROP TABLE t1,t2;
mysql-test/r/subselect_no_mat.result
View file @
edc69e32
...
...
@@ -5020,6 +5020,34 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL);
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
DROP TABLE t1,t2;
set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%'
...
...
mysql-test/r/subselect_no_opts.result
View file @
edc69e32
...
...
@@ -5017,4 +5017,32 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DEPENDENT SUBQUERY it2 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY it3 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL);
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
DROP TABLE t1,t2;
set optimizer_switch=default;
mysql-test/r/subselect_no_semijoin.result
View file @
edc69e32
...
...
@@ -5017,4 +5017,32 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY it2 ALL NULL NULL NULL NULL 4
2 SUBQUERY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join)
DROP TABLE IF EXISTS ot1, ot4, it2, it3;
#
# Bug#729039: NULL keys used to evaluate subquery
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES (NULL), (1), (NULL), (2);
CREATE TABLE t2 (a int, INDEX idx(a)) ;
INSERT INTO t2 VALUES (NULL), (1), (NULL);
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
a
1
EXPLAIN
SELECT * FROM t1
WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
2 DEPENDENT SUBQUERY t2 ref idx idx 5 test.t1.a 2 Using index
DROP TABLE t1,t2;
set optimizer_switch=default;
mysql-test/t/subselect.test
View file @
edc69e32
...
...
@@ -4293,3 +4293,26 @@ eval explain $query;
DROP
TABLE
IF
EXISTS
ot1
,
ot4
,
it2
,
it3
;
--
echo
#
--
echo
# Bug#729039: NULL keys used to evaluate subquery
--
echo
#
CREATE
TABLE
t1
(
a
int
)
;
INSERT
INTO
t1
VALUES
(
NULL
),
(
1
),
(
NULL
),
(
2
);
CREATE
TABLE
t2
(
a
int
,
INDEX
idx
(
a
))
;
INSERT
INTO
t2
VALUES
(
NULL
),
(
1
),
(
NULL
);
SELECT
*
FROM
t1
WHERE
EXISTS
(
SELECT
a
FROM
t2
USE
INDEX
() WHERE t2.a = t1.a)
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
EXISTS
(
SELECT
a
FROM
t2
USE
INDEX
() WHERE t2.a = t1.a)
;
SELECT
*
FROM
t1
WHERE
EXISTS
(
SELECT
a
FROM
t2
WHERE
t2
.
a
=
t1
.
a
);
EXPLAIN
SELECT
*
FROM
t1
WHERE
EXISTS
(
SELECT
a
FROM
t2
WHERE
t2
.
a
=
t1
.
a
);
DROP
TABLE
t1
,
t2
;
sql/sql_select.cc
View file @
edc69e32
...
...
@@ -6894,7 +6894,7 @@ static void add_not_null_conds(JOIN *join)
UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
not_null_item is the t1.f1, but it's referred_tab is 0.
*/
if
(
!
referred_tab
||
referred_tab
->
join
!=
join
)
if
(
!
referred_tab
)
continue
;
if
(
!
(
notnull
=
new
Item_func_isnotnull
(
not_null_item
)))
DBUG_VOID_RETURN
;
...
...
@@ -6911,9 +6911,14 @@ static void add_not_null_conds(JOIN *join)
QT_ORDINARY
););
if
(
!
tab
->
first_inner
)
{
COND
*
new_cond
=
referred_tab
->
select_cond
;
COND
*
new_cond
=
referred_tab
->
join
==
join
?
referred_tab
->
select_cond
:
join
->
outer_ref_cond
;
add_cond_and_fix
(
&
new_cond
,
notnull
);
referred_tab
->
set_select_cond
(
new_cond
,
__LINE__
);
if
(
referred_tab
->
join
==
join
)
referred_tab
->
set_select_cond
(
new_cond
,
__LINE__
);
else
join
->
outer_ref_cond
=
new_cond
;
}
else
add_cond_and_fix
(
tab
->
first_inner
->
on_expr_ref
,
notnull
);
...
...
@@ -7130,6 +7135,15 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
DBUG_PRINT
(
"info"
,(
"Found impossible WHERE condition"
));
DBUG_RETURN
(
1
);
// Impossible const condition
}
COND
*
outer_ref_cond
=
make_cond_for_table
(
cond
,
OUTER_REF_TABLE_BIT
,
(
table_map
)
0
,
FALSE
,
FALSE
);
if
(
outer_ref_cond
)
{
add_cond_and_fix
(
&
outer_ref_cond
,
join
->
outer_ref_cond
);
join
->
outer_ref_cond
=
outer_ref_cond
;
}
}
}
...
...
@@ -13401,7 +13415,10 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
else
{
DBUG_ASSERT
(
join
->
tables
);
error
=
join
->
first_select
(
join
,
join_tab
,
0
);
if
(
join
->
outer_ref_cond
&&
!
join
->
outer_ref_cond
->
val_int
())
error
=
NESTED_LOOP_NO_MORE_ROWS
;
else
error
=
join
->
first_select
(
join
,
join_tab
,
0
);
if
(
error
==
NESTED_LOOP_OK
||
error
==
NESTED_LOOP_NO_MORE_ROWS
)
error
=
join
->
first_select
(
join
,
join_tab
,
1
);
if
(
error
==
NESTED_LOOP_QUERY_LIMIT
)
...
...
sql/sql_select.h
View file @
edc69e32
...
...
@@ -798,6 +798,7 @@ class JOIN :public Sql_alloc
ORDER
*
order
,
*
group_list
,
*
proc_param
;
//hold parameters of mysql_select
COND
*
conds
;
// ---"---
Item
*
conds_history
;
// store WHERE for explain
COND
*
outer_ref_cond
;
///<part of conds containing only outer references
TABLE_LIST
*
tables_list
;
///<hold 'tables' parameter of mysql_select
List
<
TABLE_LIST
>
*
join_list
;
///< list of joined tables in reverse order
COND_EQUAL
*
cond_equal
;
...
...
@@ -903,6 +904,7 @@ class JOIN :public Sql_alloc
no_const_tables
=
FALSE
;
first_select
=
sub_select
;
outer_ref_cond
=
0
;
}
int
prepare
(
Item
***
rref_pointer_array
,
TABLE_LIST
*
tables
,
uint
wind_num
,
...
...
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