mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
information_schema.result, information_schema.test:
Added a test in connection with the fix for bug #6106. view.result, view.test: Added test cases for bugs #6106/6107. sql_show.cc: The addition of the case for items of the type REF_ITEM in the function uses_only_table_name_fields became necessary after the fix for bug #6106. sql_base.cc: The problem was due to the fact that two different column references were glued together though one of them belonged to a subquery while another to an outer query. This caused eventually a wrong calculation of values for the used_tables attribute.
This commit is contained in:
parent
f7d89dd468
commit
b622aba19f
6 changed files with 169 additions and 1 deletions
|
@ -68,6 +68,23 @@ t2
|
|||
t3
|
||||
v1
|
||||
select c,table_name from v1
|
||||
inner join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
||||
where v1.c like "t%";
|
||||
c table_name
|
||||
TABLES TABLES
|
||||
TABLE_PRIVILEGES TABLE_PRIVILEGES
|
||||
TABLE_CONSTRAINTS TABLE_CONSTRAINTS
|
||||
tables_priv tables_priv
|
||||
time_zone time_zone
|
||||
time_zone_leap_second time_zone_leap_second
|
||||
time_zone_name time_zone_name
|
||||
time_zone_transition time_zone_transition
|
||||
time_zone_transition_type time_zone_transition_type
|
||||
t1 t1
|
||||
t4 t4
|
||||
t2 t2
|
||||
t3 t3
|
||||
select c,table_name from v1
|
||||
left join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
||||
where v1.c like "t%";
|
||||
c table_name
|
||||
|
|
|
@ -1612,3 +1612,85 @@ insert into t3 select x from v1;
|
|||
insert into t2 select x from v1;
|
||||
drop view v1;
|
||||
drop table t1,t2,t3;
|
||||
CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10));
|
||||
INSERT INTO t1 VALUES(1,'trudy');
|
||||
INSERT INTO t1 VALUES(2,'peter');
|
||||
INSERT INTO t1 VALUES(3,'sanja');
|
||||
INSERT INTO t1 VALUES(4,'monty');
|
||||
INSERT INTO t1 VALUES(5,'david');
|
||||
INSERT INTO t1 VALUES(6,'kent');
|
||||
INSERT INTO t1 VALUES(7,'carsten');
|
||||
INSERT INTO t1 VALUES(8,'ranger');
|
||||
INSERT INTO t1 VALUES(10,'matt');
|
||||
CREATE TABLE t2 (col1 int, col2 int, col3 char(1));
|
||||
INSERT INTO t2 VALUES (1,1,'y');
|
||||
INSERT INTO t2 VALUES (1,2,'y');
|
||||
INSERT INTO t2 VALUES (2,1,'n');
|
||||
INSERT INTO t2 VALUES (3,1,'n');
|
||||
INSERT INTO t2 VALUES (4,1,'y');
|
||||
INSERT INTO t2 VALUES (4,2,'n');
|
||||
INSERT INTO t2 VALUES (4,3,'n');
|
||||
INSERT INTO t2 VALUES (6,1,'n');
|
||||
INSERT INTO t2 VALUES (8,1,'y');
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
||||
col1 col2 col2 col3
|
||||
1 trudy 2 y
|
||||
2 peter 1 n
|
||||
3 sanja 1 n
|
||||
4 monty 3 n
|
||||
5 david NULL NULL
|
||||
6 kent 1 n
|
||||
7 carsten NULL NULL
|
||||
8 ranger 1 y
|
||||
10 matt NULL NULL
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
||||
col1 col2 col2 col3
|
||||
1 trudy 2 y
|
||||
2 peter 1 n
|
||||
3 sanja 1 n
|
||||
4 monty 3 n
|
||||
5 david NULL NULL
|
||||
6 kent 1 n
|
||||
7 carsten NULL NULL
|
||||
8 ranger 1 y
|
||||
10 matt NULL NULL
|
||||
CREATE VIEW v2 AS SELECT * FROM t2;
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
||||
col1 col2 col2 col3
|
||||
1 trudy 2 y
|
||||
2 peter 1 n
|
||||
3 sanja 1 n
|
||||
4 monty 3 n
|
||||
5 david NULL NULL
|
||||
6 kent 1 n
|
||||
7 carsten NULL NULL
|
||||
8 ranger 1 y
|
||||
10 matt NULL NULL
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
||||
WHERE a.col1 IN (1,5,9) AND
|
||||
(b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
|
||||
col1 col2 col2 col3
|
||||
1 trudy 2 y
|
||||
5 david NULL NULL
|
||||
CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9);
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
||||
col1 col2 col2 col3
|
||||
1 trudy 2 y
|
||||
5 david NULL NULL
|
||||
DROP VIEW v1,v2,v3;
|
||||
DROP TABLE t1,t2;
|
||||
|
|
|
@ -24,6 +24,11 @@ create table t3(a int, KEY a_data (a));
|
|||
create table mysqltest.t4(a int);
|
||||
create view v1 (c) as select table_name from information_schema.TABLES;
|
||||
select * from v1;
|
||||
|
||||
select c,table_name from v1
|
||||
inner join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
||||
where v1.c like "t%";
|
||||
|
||||
select c,table_name from v1
|
||||
left join information_schema.TABLES v2 on (v1.c=v2.table_name)
|
||||
where v1.c like "t%";
|
||||
|
|
|
@ -1457,3 +1457,65 @@ insert into t3 select x from v1;
|
|||
insert into t2 select x from v1;
|
||||
drop view v1;
|
||||
drop table t1,t2,t3;
|
||||
|
||||
#
|
||||
# Test for BUG #6106: query over a view using subquery for the underlying table
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10));
|
||||
INSERT INTO t1 VALUES(1,'trudy');
|
||||
INSERT INTO t1 VALUES(2,'peter');
|
||||
INSERT INTO t1 VALUES(3,'sanja');
|
||||
INSERT INTO t1 VALUES(4,'monty');
|
||||
INSERT INTO t1 VALUES(5,'david');
|
||||
INSERT INTO t1 VALUES(6,'kent');
|
||||
INSERT INTO t1 VALUES(7,'carsten');
|
||||
INSERT INTO t1 VALUES(8,'ranger');
|
||||
INSERT INTO t1 VALUES(10,'matt');
|
||||
CREATE TABLE t2 (col1 int, col2 int, col3 char(1));
|
||||
INSERT INTO t2 VALUES (1,1,'y');
|
||||
INSERT INTO t2 VALUES (1,2,'y');
|
||||
INSERT INTO t2 VALUES (2,1,'n');
|
||||
INSERT INTO t2 VALUES (3,1,'n');
|
||||
INSERT INTO t2 VALUES (4,1,'y');
|
||||
INSERT INTO t2 VALUES (4,2,'n');
|
||||
INSERT INTO t2 VALUES (4,3,'n');
|
||||
INSERT INTO t2 VALUES (6,1,'n');
|
||||
INSERT INTO t2 VALUES (8,1,'y');
|
||||
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
||||
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
||||
|
||||
CREATE VIEW v2 AS SELECT * FROM t2;
|
||||
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
||||
|
||||
# Tests from the report for bug #6107
|
||||
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
||||
WHERE a.col1 IN (1,5,9) AND
|
||||
(b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
|
||||
|
||||
CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9);
|
||||
|
||||
SELECT a.col1,a.col2,b.col2,b.col3
|
||||
FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1
|
||||
WHERE b.col2 IS NULL OR
|
||||
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
||||
|
||||
DROP VIEW v1,v2,v3;
|
||||
DROP TABLE t1,t2;
|
||||
|
|
|
@ -3588,7 +3588,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, COND **conds)
|
|||
|
||||
thd->set_query_id=1;
|
||||
|
||||
thd->lex->current_select->no_wrap_view_item= 1;
|
||||
thd->lex->current_select->no_wrap_view_item= 0;
|
||||
select_lex->cond_count= 0;
|
||||
if (*conds)
|
||||
{
|
||||
|
|
|
@ -1704,6 +1704,8 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
|
|||
strlen(item_field->field_name), 0)))
|
||||
return 0;
|
||||
}
|
||||
else if (item->type() == Item::REF_ITEM)
|
||||
return uses_only_table_name_fields(item->real_item(), table);
|
||||
if (item->type() == Item::SUBSELECT_ITEM &&
|
||||
!item->const_item())
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue