diff options
author | Michael Widenius <monty@askmonty.org> | 2011-06-24 10:08:09 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2011-06-24 10:08:09 +0300 |
commit | 6a9ac86cd374185918a0398c56d101ac7e1fddf8 (patch) | |
tree | d1cbfdde25f2ce155ebf00ec8c29b22fd7eb8b6e /sql/sql_select.cc | |
parent | 135ce0ba6c9457c4c968b420a16e5bda69f222e0 (diff) | |
download | mariadb-git-6a9ac86cd374185918a0398c56d101ac7e1fddf8.tar.gz |
Fix for bug lp:798597 Incorrect "Duplicate entry" error with views and GROUP BY
mysql-test/r/join.result:
Test case for LP:798597
mysql-test/t/join.test:
Test case for LP:798597
sql/sql_select.cc:
In simplify_joins we reset table->maybe_null for outer join tables that can't ever be NULL.
This caused a conflict between the previously calculated items and the group_buffer against the fields
in the temporary table that are created as not null thanks to the optimization.
The fix is to correct the group by items to also be not_null so that they match the used fields and keys.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 91fc95a2909..0bd4e8ae647 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10637,15 +10637,30 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT1 || (ha_base_keytype) key_part_info->type == HA_KEYTYPE_VARTEXT2) ? 0 : FIELDFLAG_BINARY; + if (!using_unique_constraint) { cur_group->buff=(char*) group_buff; + + if (maybe_null & !field->null_bit) + { + /* + This can only happen in the unusual case where an outer join + table was found to be not-nullable by the optimizer and we + the item can't really be null. + We solve this by marking the item as !maybe_null to ensure + that the key,field and item definition match. + */ + (*cur_group->item)->maybe_null= maybe_null= 0; + } + if (!(cur_group->field= field->new_key_field(thd->mem_root,table, group_buff + test(maybe_null), field->null_ptr, field->null_bit))) goto err; /* purecov: inspected */ + if (maybe_null) { /* @@ -10667,6 +10682,12 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, } keyinfo->key_length+= key_part_info->length; } + /* + Ensure we didn't overrun the group buffer. The < is only true when + some maybe_null fields was changed to be not null fields. + */ + DBUG_ASSERT(using_unique_constraint || + group_buff <= param->group_buff + param->group_length); } if (distinct && field_count != param->hidden_field_count) |