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
caf31114
Commit
caf31114
authored
Sep 18, 2012
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merged the fix for bug lp:1009187, mdev-373
parents
0704d470
0bc89929
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
335 additions
and
203 deletions
+335
-203
mysql-test/r/subselect4.result
mysql-test/r/subselect4.result
+159
-0
mysql-test/t/subselect4.test
mysql-test/t/subselect4.test
+69
-0
sql/item_subselect.cc
sql/item_subselect.cc
+105
-200
sql/item_subselect.h
sql/item_subselect.h
+2
-3
No files found.
mysql-test/r/subselect4.result
View file @
caf31114
...
...
@@ -206,6 +206,165 @@ default(a)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
DROP TABLE t;
#
# LP BUG#1009187, MDEV-373, MYSQL bug#58628
# Wrong result for a query with [NOT] IN subquery predicate if
# the left part of the predicate is explicit NULL
#
CREATE TABLE t1 (pk INT NOT NULL, i INT NOT NULL);
INSERT INTO t1 VALUES (0,10), (1,20), (2,30), (3,40);
CREATE TABLE t2a (pk INT NOT NULL, i INT NOT NULL, PRIMARY KEY(i,pk));
INSERT INTO t2a VALUES (0,0), (1,1), (2,2), (3,3);
CREATE TABLE t2b (pk INT, i INT);
INSERT INTO t2b VALUES (0,0), (1,1), (2,2), (3,3);
CREATE TABLE t2c (pk INT NOT NULL, i INT NOT NULL);
INSERT INTO t2c VALUES (0,0), (1,1), (2,2), (3,3);
create index it2c on t2c (i,pk);
CREATE TABLE t2d (pk INT NOT NULL, i INT NOT NULL, PRIMARY KEY(i));
INSERT INTO t2d VALUES (0,0), (1,1), (2,2), (3,3);
EXPLAIN
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk);
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 t2a unique_subquery PRIMARY PRIMARY 8 const,test.t1.pk 1 Using index; Using where; Full scan on NULL key
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk);
pk i
SELECT * FROM t1 WHERE 1+NULL NOT IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk);
pk i
SELECT * FROM t1 WHERE NULL IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk) IS UNKNOWN;
pk i
0 10
1 20
2 30
3 40
SELECT t1.pk, NULL NOT IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk) FROM t1;
pk NULL NOT IN (SELECT t2a.i FROM t2a WHERE t2a.pk = t1.pk)
0 NULL
1 NULL
2 NULL
3 NULL
EXPLAIN
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2b.i FROM t2b WHERE t2b.pk = t1.pk);
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 t2b ALL NULL NULL NULL NULL 4 Using where
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2b.i FROM t2b WHERE t2b.pk = t1.pk);
pk i
SELECT * FROM t1 WHERE NULL IN (SELECT t2b.i FROM t2b WHERE t2b.pk = t1.pk) IS UNKNOWN;
pk i
0 10
1 20
2 30
3 40
SELECT t1.pk, NULL NOT IN (SELECT t2b.i FROM t2b WHERE t2b.pk = t1.pk) FROM t1;
pk NULL NOT IN (SELECT t2b.i FROM t2b WHERE t2b.pk = t1.pk)
0 NULL
1 NULL
2 NULL
3 NULL
EXPLAIN
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2c.i FROM t2c WHERE t2c.pk = t1.pk);
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 t2c index_subquery it2c it2c 8 const,test.t1.pk 2 Using index; Using where; Full scan on NULL key
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2c.i FROM t2c WHERE t2c.pk = t1.pk);
pk i
SELECT * FROM t1 WHERE NULL IN (SELECT t2c.i FROM t2c WHERE t2c.pk = t1.pk) IS UNKNOWN;
pk i
0 10
1 20
2 30
3 40
SELECT t1.pk, NULL NOT IN (SELECT t2c.i FROM t2c WHERE t2c.pk = t1.pk) FROM t1;
pk NULL NOT IN (SELECT t2c.i FROM t2c WHERE t2c.pk = t1.pk)
0 NULL
1 NULL
2 NULL
3 NULL
EXPLAIN
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2d.i FROM t2d WHERE t2d.pk = t1.pk);
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 t2d const PRIMARY PRIMARY 4 const 1 Using where; Full scan on NULL key
SELECT * FROM t1 WHERE NULL NOT IN (SELECT t2d.i FROM t2d WHERE t2d.pk = t1.pk);
pk i
SELECT * FROM t1 WHERE NULL IN (SELECT t2d.i FROM t2d WHERE t2d.pk = t1.pk) IS UNKNOWN;
pk i
0 10
1 20
2 30
3 40
SELECT t1.pk, NULL NOT IN (SELECT t2d.i FROM t2d WHERE t2d.pk = t1.pk) FROM t1;
pk NULL NOT IN (SELECT t2d.i FROM t2d WHERE t2d.pk = t1.pk)
0 NULL
1 NULL
2 NULL
3 NULL
EXPLAIN
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk);
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 t2a eq_ref PRIMARY PRIMARY 8 const,test.t1.pk 1 Using where; Using index; Full scan on NULL key
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk);
pk i
0 10
2 30
3 40
SELECT (NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk) from t1;
(NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk)
1
NULL
1
1
EXPLAIN
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2b.i, t2b.pk FROM t2b WHERE t2b.pk = t1.pk);
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 t2b ALL NULL NULL NULL NULL 4 Using where
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2b.i, t2b.pk FROM t2b WHERE t2b.pk = t1.pk);
pk i
0 10
2 30
3 40
SELECT (NULL, 1) NOT IN (SELECT t2b.i, t2b.pk FROM t2b WHERE t2b.pk = t1.pk) from t1;
(NULL, 1) NOT IN (SELECT t2b.i, t2b.pk FROM t2b WHERE t2b.pk = t1.pk)
1
NULL
1
1
EXPLAIN
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk);
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 t2c ref it2c it2c 8 const,test.t1.pk 2 Using where; Using index; Full scan on NULL key
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk);
pk i
0 10
2 30
3 40
SELECT (NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk) from t1;
(NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk)
1
NULL
1
1
EXPLAIN
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2d.i, t2d.pk FROM t2d WHERE t2d.pk = t1.pk);
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 t2d const PRIMARY PRIMARY 4 const 1 Using where; Full scan on NULL key
SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2d.i, t2d.pk FROM t2d WHERE t2d.pk = t1.pk);
pk i
0 10
2 30
3 40
SELECT (NULL, 1) NOT IN (SELECT t2d.i, t2d.pk FROM t2d WHERE t2d.pk = t1.pk) from t1;
(NULL, 1) NOT IN (SELECT t2d.i, t2d.pk FROM t2d WHERE t2d.pk = t1.pk)
1
NULL
1
1
drop table t1, t2a, t2b, t2c, t2d;
#
# End of 5.1 tests.
#
#
...
...
mysql-test/t/subselect4.test
View file @
caf31114
...
...
@@ -184,6 +184,75 @@ INSERT INTO t VALUES (''),(''),(''),(''),(''),(''),(''),(''),(''),(''),('');
SELECT
*
FROM
(
SELECT
default
(
a
)
FROM
t
GROUP
BY
a
)
d
;
DROP
TABLE
t
;
--
echo
#
--
echo
# LP BUG#1009187, MDEV-373, MYSQL bug#58628
--
echo
# Wrong result for a query with [NOT] IN subquery predicate if
--
echo
# the left part of the predicate is explicit NULL
--
echo
#
CREATE
TABLE
t1
(
pk
INT
NOT
NULL
,
i
INT
NOT
NULL
);
INSERT
INTO
t1
VALUES
(
0
,
10
),
(
1
,
20
),
(
2
,
30
),
(
3
,
40
);
CREATE
TABLE
t2a
(
pk
INT
NOT
NULL
,
i
INT
NOT
NULL
,
PRIMARY
KEY
(
i
,
pk
));
INSERT
INTO
t2a
VALUES
(
0
,
0
),
(
1
,
1
),
(
2
,
2
),
(
3
,
3
);
CREATE
TABLE
t2b
(
pk
INT
,
i
INT
);
INSERT
INTO
t2b
VALUES
(
0
,
0
),
(
1
,
1
),
(
2
,
2
),
(
3
,
3
);
CREATE
TABLE
t2c
(
pk
INT
NOT
NULL
,
i
INT
NOT
NULL
);
INSERT
INTO
t2c
VALUES
(
0
,
0
),
(
1
,
1
),
(
2
,
2
),
(
3
,
3
);
create
index
it2c
on
t2c
(
i
,
pk
);
CREATE
TABLE
t2d
(
pk
INT
NOT
NULL
,
i
INT
NOT
NULL
,
PRIMARY
KEY
(
i
));
INSERT
INTO
t2d
VALUES
(
0
,
0
),
(
1
,
1
),
(
2
,
2
),
(
3
,
3
);
EXPLAIN
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2a
.
i
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2a
.
i
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
1
+
NULL
NOT
IN
(
SELECT
t2a
.
i
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
IN
(
SELECT
t2a
.
i
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
)
IS
UNKNOWN
;
SELECT
t1
.
pk
,
NULL
NOT
IN
(
SELECT
t2a
.
i
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
)
FROM
t1
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2b
.
i
FROM
t2b
WHERE
t2b
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2b
.
i
FROM
t2b
WHERE
t2b
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
IN
(
SELECT
t2b
.
i
FROM
t2b
WHERE
t2b
.
pk
=
t1
.
pk
)
IS
UNKNOWN
;
SELECT
t1
.
pk
,
NULL
NOT
IN
(
SELECT
t2b
.
i
FROM
t2b
WHERE
t2b
.
pk
=
t1
.
pk
)
FROM
t1
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2c
.
i
FROM
t2c
WHERE
t2c
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2c
.
i
FROM
t2c
WHERE
t2c
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
IN
(
SELECT
t2c
.
i
FROM
t2c
WHERE
t2c
.
pk
=
t1
.
pk
)
IS
UNKNOWN
;
SELECT
t1
.
pk
,
NULL
NOT
IN
(
SELECT
t2c
.
i
FROM
t2c
WHERE
t2c
.
pk
=
t1
.
pk
)
FROM
t1
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2d
.
i
FROM
t2d
WHERE
t2d
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
NOT
IN
(
SELECT
t2d
.
i
FROM
t2d
WHERE
t2d
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
NULL
IN
(
SELECT
t2d
.
i
FROM
t2d
WHERE
t2d
.
pk
=
t1
.
pk
)
IS
UNKNOWN
;
SELECT
t1
.
pk
,
NULL
NOT
IN
(
SELECT
t2d
.
i
FROM
t2d
WHERE
t2d
.
pk
=
t1
.
pk
)
FROM
t1
;
EXPLAIN
SELECT
*
FROM
t1
WHERE
(
NULL
,
1
)
NOT
IN
(
SELECT
t2a
.
i
,
t2a
.
pk
FROM
t2a
WHERE
t2a
.
pk
=
t1
.
pk
);
SELECT
*
FROM
t1
WHERE
(
NULL
,
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
pk
=
t1
.
pk
)
from
t1
;
drop
table
t1
,
t2a
,
t2b
,
t2c
,
t2d
;
--
echo
#
--
echo
# End of 5.1 tests.
--
echo
#
...
...
sql/item_subselect.cc
View file @
caf31114
This diff is collapsed.
Click to expand it.
sql/item_subselect.h
View file @
caf31114
...
...
@@ -591,6 +591,7 @@ public:
/* Inform 'this' that it was computed, and contains a valid result. */
void
set_first_execution
()
{
if
(
first_execution
)
first_execution
=
FALSE
;
}
bool
expr_cache_is_needed
(
THD
*
thd
);
inline
bool
left_expr_has_null
();
int
optimize
(
double
*
out_rows
,
double
*
cost
);
/*
...
...
@@ -869,7 +870,6 @@ protected:
expression is NULL.
*/
bool
empty_result_set
;
bool
null_keypart
;
/* TRUE <=> constructed search tuple has a NULL */
public:
// constructor can assign THD because it will be called after JOIN::prepare
...
...
@@ -893,8 +893,7 @@ public:
bool
no_tables
();
int
index_lookup
();
/* TIMOUR: this method needs refactoring. */
int
scan_table
();
bool
copy_ref_key
();
int
copy_ref_key_simple
();
/* TIMOUR: this method needs refactoring. */
bool
copy_ref_key
(
bool
skip_constants
);
bool
no_rows
()
{
return
empty_result_set
;
}
virtual
enum_engine_type
engine_type
()
{
return
UNIQUESUBQUERY_ENGINE
;
}
};
...
...
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