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_select.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_select.cc')
-rw-r--r-- | sql/sql_select.cc | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3b0061fcf8e..1cb57e17a83 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10263,6 +10263,27 @@ void JOIN_TAB::calc_used_field_length(bool max_fl) MY_BITMAP *read_set= table->read_set; uneven_bit_fields= null_fields= blobs= fields= rec_length=0; + + /* Take into account that DuplicateElimination may need to store rowid */ + uint rowid_add_size= 0; + + if (keep_current_rowid) + { + rowid_add_size= table->file->ref_length; + rec_length += rowid_add_size; + fields++; + } + + if (bush_children) + { + /* + This JOIN_TAB represents an SJ-Materialization nest. The table is + the materialized temptable. For such tables, we may need their rowid + (taken care of above). We don't need any columns. + */ + goto save_and_exit; + } + for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++) { if (bitmap_is_set(read_set, field->field_index)) @@ -10284,14 +10305,6 @@ void JOIN_TAB::calc_used_field_length(bool max_fl) if (table->maybe_null) rec_length+=sizeof(my_bool); - /* Take into account that DuplicateElimination may need to store rowid */ - uint rowid_add_size= 0; - if (keep_current_rowid) - { - rowid_add_size= table->file->ref_length; - rec_length += rowid_add_size; - fields++; - } if (max_fl) { @@ -10308,7 +10321,8 @@ void JOIN_TAB::calc_used_field_length(bool max_fl) } else if (table->file->stats.mean_rec_length) set_if_smaller(rec_length, table->file->stats.mean_rec_length + rowid_add_size); - + +save_and_exit: used_fields=fields; used_fieldlength=rec_length; used_blobs=blobs; |