Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
10.11.10
-
None
Description
A mis-typed query revealed that in the context of a DELETE FROM ... WHERE id IN (subquery) that the subquery could reference a column that would otherwise not be available to it as a stand-alone query. For example:
DROP TABLE IF EXISTS `t1`; |
CREATE TABLE `t1` ( |
`t1_id` int(11) NOT NULL |
);
|
INSERT INTO t1 VALUES (1), (2), (3), (5), (8), (13); |
|
DROP TABLE IF EXISTS `t2`; |
CREATE TABLE `t2` ( |
`t2_id` int(11) NOT NULL |
);
|
INSERT INTO t2 VALUES (2), (3), (5), (7), (11), (13); |
|
/* simulate a typo where where the t2_id is used instead of t1_id */
|
/* since table t1 does not have a column t2_id, we expect it to fail */
|
DELETE FROM t2 where t2_id IN ( SELECT t2_id FROM t1 ); |
|
SELECT t2_rows, |
CASE |
WHEN (t2_rows) = 6 THEN 'YAY' |
WHEN (t2_rows) = 3 THEN 'OK' |
ELSE 'DARN' |
END AS _result |
FROM (SELECT COUNT(*) AS t2_rows FROM t2) AS c2; |
Which results in:
t2_rows _result
|
0 DARN
|