mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Fixed LP bug #806057.
A table expression with a natural join or a USING clause is transformed into an equivalent expression with equi-join ON conditions. If a reference to a virtual column happened to occur only in these generated equi-join conditions then it was not erroneously marked in the TABLE::vcol_set bitmap. This could lead to wrong results for queries containing natural join expressions or USING clauses.
This commit is contained in:
@ -262,3 +262,33 @@ NULL
|
||||
explain select sum(c) from t1 group by b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
|
||||
#
|
||||
# Bug #806057: join with USING over a virtual column
|
||||
#
|
||||
CREATE TABLE t1 (b int);
|
||||
INSERT INTO t1 VALUES (NULL),( 78), (185), (0), (154);
|
||||
CREATE TABLE t2 (a int, b int AS (a) VIRTUAL);
|
||||
INSERT INTO t2 VALUES (187,187), (9,9), (187,187);
|
||||
Warnings:
|
||||
Warning 1647 The value specified for computed column 'b' in table 't2' ignored
|
||||
Warning 1647 The value specified for computed column 'b' in table 't2' ignored
|
||||
Warning 1647 The value specified for computed column 'b' in table 't2' ignored
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 JOIN t2 USING (b);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`b` = `test`.`t2`.`b`)
|
||||
SELECT * FROM t1 JOIN t2 USING (b);
|
||||
b a
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 NATURAL JOIN t2;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`b` = `test`.`t2`.`b`)
|
||||
SELECT * FROM t1 NATURAL JOIN t2;
|
||||
b a
|
||||
DROP TABLE t1,t2;
|
||||
|
@ -48,3 +48,23 @@ eval SET @@session.storage_engine = 'MyISAM';
|
||||
#------------------------------------------------------------------------------#
|
||||
# Cleanup
|
||||
--source suite/vcol/inc/vcol_cleanup.inc
|
||||
|
||||
--echo #
|
||||
--echo # Bug #806057: join with USING over a virtual column
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (b int);
|
||||
INSERT INTO t1 VALUES (NULL),( 78), (185), (0), (154);
|
||||
|
||||
CREATE TABLE t2 (a int, b int AS (a) VIRTUAL);
|
||||
INSERT INTO t2 VALUES (187,187), (9,9), (187,187);
|
||||
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 JOIN t2 USING (b);
|
||||
SELECT * FROM t1 JOIN t2 USING (b);
|
||||
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 NATURAL JOIN t2;
|
||||
SELECT * FROM t1 NATURAL JOIN t2;
|
||||
|
||||
DROP TABLE t1,t2;
|
||||
|
@ -7151,11 +7151,16 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
|
||||
if (!(eq_cond= new Item_func_eq(item_ident_1, item_ident_2)))
|
||||
goto err; /* Out of memory. */
|
||||
|
||||
if (field_1 && field_1->vcol_info)
|
||||
field_1->table->mark_virtual_col(field_1);
|
||||
if (field_2 && field_2->vcol_info)
|
||||
field_2->table->mark_virtual_col(field_2);
|
||||
|
||||
/*
|
||||
Add the new equi-join condition to the ON clause. Notice that
|
||||
fix_fields() is applied to all ON conditions in setup_conds()
|
||||
so we don't do it here.
|
||||
*/
|
||||
*/
|
||||
add_join_on((table_ref_1->outer_join & JOIN_TYPE_RIGHT ?
|
||||
table_ref_1 : table_ref_2),
|
||||
eq_cond);
|
||||
|
Reference in New Issue
Block a user