From 0d734037ccabdb612e358db3fc91c7aaebf1c5ea Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 1 Jul 2010 22:13:19 -0700 Subject: [PATCH] Added missing calls of update_virtual_fields() in the join cache module. Without these calls SELECTs over tables with virtual columns that used join cache could return wrong results. This could be seen with the test case added into vcol_misc.test --- mysql-test/suite/vcol/r/vcol_misc.result | 20 ++++++++++++++++++++ mysql-test/suite/vcol/t/vcol_misc.test | 23 +++++++++++++++++++++++ sql/sql_join_cache.cc | 7 +++---- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 mysql-test/suite/vcol/r/vcol_misc.result create mode 100644 mysql-test/suite/vcol/t/vcol_misc.test diff --git a/mysql-test/suite/vcol/r/vcol_misc.result b/mysql-test/suite/vcol/r/vcol_misc.result new file mode 100644 index 00000000000..57460b1d669 --- /dev/null +++ b/mysql-test/suite/vcol/r/vcol_misc.result @@ -0,0 +1,20 @@ +drop table if exists t1,t2; +create table t1 (a int, b int); +insert into t1 values (3, 30), (4, 20), (1, 20); +create table t2 (c int, d int, v int as (d+1), index idx(c)); +insert into t2(c,d) values +(20, 100), (20, 300), (30, 100), (30, 200), (40, 500), +(70, 100), (40, 300), (60, 100), (40, 100), (70, 100); +set join_cache_level=6; +explain +select * from t1,t2 where t1.b=t2.c and d <= 100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ref idx idx 5 test.t1.b 2 Using where; Using join buffer +select * from t1,t2 where t1.b=t2.c and d <= 100; +a b c d v +4 20 20 100 101 +1 20 20 100 101 +3 30 30 100 101 +set join_cache_level=default; +drop table t1, t2; diff --git a/mysql-test/suite/vcol/t/vcol_misc.test b/mysql-test/suite/vcol/t/vcol_misc.test new file mode 100644 index 00000000000..afe6f838268 --- /dev/null +++ b/mysql-test/suite/vcol/t/vcol_misc.test @@ -0,0 +1,23 @@ +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +# +# SELECT that uses a virtual column and executed with BKA +# + +create table t1 (a int, b int); +insert into t1 values (3, 30), (4, 20), (1, 20); +create table t2 (c int, d int, v int as (d+1), index idx(c)); +insert into t2(c,d) values + (20, 100), (20, 300), (30, 100), (30, 200), (40, 500), + (70, 100), (40, 300), (60, 100), (40, 100), (70, 100); + +set join_cache_level=6; +explain +select * from t1,t2 where t1.b=t2.c and d <= 100; + +select * from t1,t2 where t1.b=t2.c and d <= 100; +set join_cache_level=default; + +drop table t1, t2; \ No newline at end of file diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 321297c2b49..e9923c3c983 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -1799,11 +1799,8 @@ enum_nested_loop_state JOIN_CACHE_BNL::join_matching_records(bool skip_last) } int err= 0; - /* - psergey3-merge: should we have this here by any chance: if (rc == NESTED_LOOP_OK) - update_virtual_fields(join_tab->table); - */ + update_virtual_fields(join_tab->table); /* Do not look for matches if the last read record of the joined table @@ -2324,6 +2321,7 @@ enum_nested_loop_state JOIN_CACHE_BKA::join_matching_records(bool skip_last) (!check_only_first_match || !get_match_flag_by_pos(rec_ptr))) { get_record_by_pos(rec_ptr); + update_virtual_fields(join_tab->table); rc= generate_full_extensions(rec_ptr); if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) goto finish; @@ -3211,6 +3209,7 @@ JOIN_CACHE_BKA_UNIQUE::join_matching_records(bool skip_last) (!check_only_first_match || !get_match_flag_by_pos(rec_ptr))) { get_record_by_pos(rec_ptr); + update_virtual_fields(join_tab->table); rc= generate_full_extensions(rec_ptr); if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) goto finish;