mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
BUG#1002630: Valgrind warnings 'Invalid read' in subselect_engine::calc_const_tables with SELECT
- In JOIN::exec(), make the having->update_used_tables() call before we've made the JOIN::cleanup(full=true) call. The latter frees SJ-Materialization structures, which correlated subquery predicate items attempt to walk afterwards.
This commit is contained in:
@ -2264,6 +2264,8 @@ JOIN::exec()
|
||||
List<Item> *curr_all_fields= &all_fields;
|
||||
List<Item> *curr_fields_list= &fields_list;
|
||||
TABLE *curr_tmp_table= 0;
|
||||
bool tmp_having_used_tables_updated= FALSE;
|
||||
|
||||
/*
|
||||
Initialize examined rows here because the values from all join parts
|
||||
must be accumulated in examined_row_count. Hence every join
|
||||
@ -2511,12 +2513,22 @@ JOIN::exec()
|
||||
if (curr_tmp_table->distinct)
|
||||
curr_join->select_distinct=0; /* Each row is unique */
|
||||
|
||||
|
||||
/*
|
||||
curr_join->join_free() will call JOIN::cleanup(full=TRUE). It will not
|
||||
be safe to call update_used_tables() after that.
|
||||
*/
|
||||
if (curr_join->tmp_having)
|
||||
{
|
||||
curr_join->tmp_having->update_used_tables();
|
||||
tmp_having_used_tables_updated= TRUE;
|
||||
}
|
||||
|
||||
curr_join->join_free(); /* Free quick selects */
|
||||
|
||||
if (curr_join->select_distinct && ! curr_join->group_list)
|
||||
{
|
||||
thd_proc_info(thd, "Removing duplicates");
|
||||
if (curr_join->tmp_having)
|
||||
curr_join->tmp_having->update_used_tables();
|
||||
if (remove_duplicates(curr_join, curr_tmp_table,
|
||||
*curr_fields_list, curr_join->tmp_having))
|
||||
DBUG_VOID_RETURN;
|
||||
@ -2589,7 +2601,8 @@ JOIN::exec()
|
||||
! curr_join->sort_and_group)
|
||||
{
|
||||
// Some tables may have been const
|
||||
curr_join->tmp_having->update_used_tables();
|
||||
if (!tmp_having_used_tables_updated)
|
||||
curr_join->tmp_having->update_used_tables();
|
||||
JOIN_TAB *curr_table= &curr_join->join_tab[curr_join->const_tables];
|
||||
table_map used_tables= (curr_join->const_table_map |
|
||||
curr_table->table->map);
|
||||
|
Reference in New Issue
Block a user