mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
do not try to use equal field from outer query as field of local join (BUG#6384)
mysql-test/r/subselect.result: changes in plans test for bug#6384 mysql-test/t/subselect.test: test for bug#6384 sql/sql_select.cc: do not set equal field from outer query
This commit is contained in:
@ -333,7 +333,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 Using index
|
2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 Using index
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1276 Field or reference 'clinic_uq' of SELECT #2 was resolved in SELECT #1
|
Note 1276 Field or reference 'clinic_uq' of SELECT #2 was resolved in SELECT #1
|
||||||
Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 AS `Not_used` from `test`.`t7` where (`test`.`t6`.`clinic_uq` = `test`.`t7`.`uq`))
|
Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 AS `Not_used` from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
|
||||||
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
|
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
|
||||||
ERROR 23000: Column 'a' in field list is ambiguous
|
ERROR 23000: Column 'a' in field list is ambiguous
|
||||||
drop table t1,t2,t3;
|
drop table t1,t2,t3;
|
||||||
@ -1744,7 +1744,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 Using where; Using index
|
2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 Using where; Using index
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1276 Field or reference 'tt.id' of SELECT #2 was resolved in SELECT #1
|
Note 1276 Field or reference 'tt.id' of SELECT #2 was resolved in SELECT #1
|
||||||
Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where not(exists(select `test`.`t1`.`id` AS `id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`tt`.`id` = `test`.`t1`.`id`)) having (`test`.`t1`.`id` is not null)))
|
Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where not(exists(select `test`.`t1`.`id` AS `id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))
|
||||||
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
|
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
|
||||||
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
|
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
|
||||||
insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
|
insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
|
||||||
@ -2272,7 +2272,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||||||
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
|
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1276 Field or reference 'up.a' of SELECT #2 was resolved in SELECT #1
|
Note 1276 Field or reference 'up.a' of SELECT #2 was resolved in SELECT #1
|
||||||
Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 AS `Not_used` from `test`.`t1` where (`test`.`up`.`a` = `test`.`t1`.`a`))
|
Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 AS `Not_used` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
|
||||||
drop table t1;
|
drop table t1;
|
||||||
CREATE TABLE t1 (t1_a int);
|
CREATE TABLE t1 (t1_a int);
|
||||||
INSERT INTO t1 VALUES (1);
|
INSERT INTO t1 VALUES (1);
|
||||||
|
@ -1777,7 +1777,6 @@ DROP TABLE t1,t2;
|
|||||||
#
|
#
|
||||||
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ
|
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ
|
||||||
#
|
#
|
||||||
|
|
||||||
CREATE TABLE t1 ( c1 integer );
|
CREATE TABLE t1 ( c1 integer );
|
||||||
INSERT INTO t1 VALUES ( 1 );
|
INSERT INTO t1 VALUES ( 1 );
|
||||||
INSERT INTO t1 VALUES ( 2 );
|
INSERT INTO t1 VALUES ( 2 );
|
||||||
@ -1822,3 +1821,18 @@ CREATE TABLE `t2` (
|
|||||||
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
|
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
|
||||||
SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
|
SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30;
|
||||||
drop tables t1,t2;
|
drop tables t1,t2;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Correct building of equal fields list (do not include outer
|
||||||
|
# fields) (BUG#6384)
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (EMPNUM CHAR(3));
|
||||||
|
CREATE TABLE t2 (EMPNUM CHAR(3) );
|
||||||
|
INSERT INTO t1 VALUES ('E1');
|
||||||
|
INSERT INTO t2 VALUES ('E1');
|
||||||
|
DELETE FROM t1
|
||||||
|
WHERE t1.EMPNUM NOT IN
|
||||||
|
(SELECT t2.EMPNUM
|
||||||
|
FROM t2
|
||||||
|
WHERE t1.EMPNUM = t2.EMPNUM);
|
||||||
|
DROP TABLE t1,t2;
|
||||||
|
@ -6381,7 +6381,9 @@ static bool check_equality(Item *item, COND_EQUAL *cond_equal)
|
|||||||
Item *left_item= ((Item_func*) item)->arguments()[0];
|
Item *left_item= ((Item_func*) item)->arguments()[0];
|
||||||
Item *right_item= ((Item_func*) item)->arguments()[1];
|
Item *right_item= ((Item_func*) item)->arguments()[1];
|
||||||
if (left_item->type() == Item::FIELD_ITEM &&
|
if (left_item->type() == Item::FIELD_ITEM &&
|
||||||
right_item->type() == Item::FIELD_ITEM)
|
right_item->type() == Item::FIELD_ITEM &&
|
||||||
|
!((Item_field*)left_item)->depended_from &&
|
||||||
|
!((Item_field*)right_item)->depended_from)
|
||||||
{
|
{
|
||||||
/* The predicate the form field1=field2 is processed */
|
/* The predicate the form field1=field2 is processed */
|
||||||
|
|
||||||
@ -6460,13 +6462,15 @@ static bool check_equality(Item *item, COND_EQUAL *cond_equal)
|
|||||||
/* The predicate of the form field=const/const=field is processed */
|
/* The predicate of the form field=const/const=field is processed */
|
||||||
Item *const_item= 0;
|
Item *const_item= 0;
|
||||||
Item_field *field_item= 0;
|
Item_field *field_item= 0;
|
||||||
if (left_item->type() == Item::FIELD_ITEM &&
|
if (left_item->type() == Item::FIELD_ITEM &&
|
||||||
|
!((Item_field*)left_item)->depended_from &&
|
||||||
right_item->const_item())
|
right_item->const_item())
|
||||||
{
|
{
|
||||||
field_item= (Item_field*) left_item;
|
field_item= (Item_field*) left_item;
|
||||||
const_item= right_item;
|
const_item= right_item;
|
||||||
}
|
}
|
||||||
else if (right_item->type() == Item::FIELD_ITEM &&
|
else if (right_item->type() == Item::FIELD_ITEM &&
|
||||||
|
!((Item_field*)right_item)->depended_from &&
|
||||||
left_item->const_item())
|
left_item->const_item())
|
||||||
{
|
{
|
||||||
field_item= (Item_field*) right_item;
|
field_item= (Item_field*) right_item;
|
||||||
|
Reference in New Issue
Block a user