diff options
author | Sergei Petrunia <sergey@mariadb.com> | 2022-08-29 23:12:27 +0300 |
---|---|---|
committer | Sergei Petrunia <sergey@mariadb.com> | 2022-08-29 23:12:27 +0300 |
commit | 64ce02a5a800eb30377ce3d1624e4e844af4a59d (patch) | |
tree | 1a0715998af631b994907e46a773432c5ef8cd76 /sql/sql_join_cache.cc | |
parent | 8cb75b9863a7043ebf2545158b3d2e634bca1831 (diff) | |
download | mariadb-git-bb-10.9-mdev29382.tar.gz |
MDEV-29382: Query returns wrong number of recordsbb-10.9-mdev29382
The issue occurred when DuplicateWeedout optimization was applied
together with Join Buffer, and also there was an SJ-Materialization-lookup
table in the join prefix.
DuplicateWeedout optimization includes the rowid of SJ-Materialization
temptable into its Duplicate checks.
However, Join Buffering code did not save/restore the rowids of
SJ-Materialization temptables. This meant the check could miss some
duplicates.
The fix makes the Join Buffering code to save/restore rowids for
SJ-Materialization temp.tables.
Diffstat (limited to 'sql/sql_join_cache.cc')
-rw-r--r-- | sql/sql_join_cache.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 620c52a3f40..0188cc9ac8f 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -219,8 +219,10 @@ void JOIN_CACHE::calc_record_fields() /* The following loop will get inside SJM nests, because data may be unpacked to sjm-inner tables. + We also cover SJM roots (aka bush roots), as their rowids may need to be + saved and restored. */ - for (; tab != join_tab ; tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) + for (; tab != join_tab ; tab= next_linear_tab(join, tab, WITH_BUSH_ROOTS)) { tab->calc_used_field_length(FALSE); flag_fields+= MY_TEST(tab->used_null_fields || tab->used_uneven_bit_fields); @@ -585,7 +587,7 @@ void JOIN_CACHE::create_remaining_fields() CACHE_FIELD **copy_ptr= blob_ptr+data_field_ptr_count; for (tab= start_tab; tab != join_tab; - tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) + tab= next_linear_tab(join, tab, WITH_BUSH_ROOTS)) { MY_BITMAP *rem_field_set; TABLE *table= tab->table; @@ -599,10 +601,21 @@ void JOIN_CACHE::create_remaining_fields() rem_field_set= &table->tmp_set; } - length+= add_table_data_fields_to_join_cache(tab, rem_field_set, - &data_field_count, ©, - &data_field_ptr_count, - ©_ptr); + /* + Do not add columns for SJM nests: + - for SJ-Materialization-Scan, the columns are unpacked to the + source tables. + - for SJ-Materialization-Lookup, equality substitution should + make sure all references are made to the source of data for + making the lookup. + */ + if (!tab->bush_children) + { + length+= add_table_data_fields_to_join_cache(tab, rem_field_set, + &data_field_count, ©, + &data_field_ptr_count, + ©_ptr); + } /* SemiJoinDuplicateElimination: allocate space for rowid if needed */ if (tab->keep_current_rowid) |