Commit f75fd03e authored by Sergey Petrunya's avatar Sergey Petrunya

MariaDB 5.2 -> 5.2 post-merge fixes:

- When building multiple-equalities for HAVING, don't set JOIN::cond_equal, set
  join_having_equal instead. Setting JOIN::cond_equal based on HAVING makes 
  equality propagation data self-inconsistent
parent c27b3902
...@@ -127,7 +127,8 @@ static uint build_bitmap_for_nested_joins(List<TABLE_LIST> *join_list, ...@@ -127,7 +127,8 @@ static uint build_bitmap_for_nested_joins(List<TABLE_LIST> *join_list,
static COND *optimize_cond(JOIN *join, COND *conds, static COND *optimize_cond(JOIN *join, COND *conds,
List<TABLE_LIST> *join_list, List<TABLE_LIST> *join_list,
Item::cond_result *cond_value); Item::cond_result *cond_value,
COND_EQUAL **cond_equal);
static bool const_expression_in_where(COND *conds,Item *item, Item **comp_item); static bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
static bool create_internal_tmp_table_from_heap2(THD *, TABLE *, static bool create_internal_tmp_table_from_heap2(THD *, TABLE *,
ENGINE_COLUMNDEF *, ENGINE_COLUMNDEF **, ENGINE_COLUMNDEF *, ENGINE_COLUMNDEF **,
...@@ -813,7 +814,7 @@ JOIN::optimize() ...@@ -813,7 +814,7 @@ JOIN::optimize()
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
} }
conds= optimize_cond(this, conds, join_list, &cond_value); conds= optimize_cond(this, conds, join_list, &cond_value, &cond_equal);
if (thd->is_error()) if (thd->is_error())
{ {
error= 1; error= 1;
...@@ -822,7 +823,7 @@ JOIN::optimize() ...@@ -822,7 +823,7 @@ JOIN::optimize()
} }
{ {
having= optimize_cond(this, having, join_list, &having_value); having= optimize_cond(this, having, join_list, &having_value, &having_equal);
if (thd->is_error()) if (thd->is_error())
{ {
error= 1; error= 1;
...@@ -2378,6 +2379,7 @@ JOIN::destroy() ...@@ -2378,6 +2379,7 @@ JOIN::destroy()
DBUG_RETURN(tmp_join->destroy()); DBUG_RETURN(tmp_join->destroy());
} }
cond_equal= 0; cond_equal= 0;
having_equal= 0;
cleanup(1); cleanup(1);
/* Cleanup items referencing temporary table columns */ /* Cleanup items referencing temporary table columns */
...@@ -9118,6 +9120,7 @@ static COND *build_equal_items(THD *thd, COND *cond, ...@@ -9118,6 +9120,7 @@ static COND *build_equal_items(THD *thd, COND *cond,
if (cond->type() == Item::COND_ITEM && if (cond->type() == Item::COND_ITEM &&
((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC) ((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
cond_equal= &((Item_cond_and*) cond)->cond_equal; cond_equal= &((Item_cond_and*) cond)->cond_equal;
else if (cond->type() == Item::FUNC_ITEM && else if (cond->type() == Item::FUNC_ITEM &&
((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC) ((Item_cond*) cond)->functype() == Item_func::MULT_EQUAL_FUNC)
{ {
...@@ -10404,7 +10407,7 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab, ...@@ -10404,7 +10407,7 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab,
static COND * static COND *
optimize_cond(JOIN *join, COND *conds, List<TABLE_LIST> *join_list, optimize_cond(JOIN *join, COND *conds, List<TABLE_LIST> *join_list,
Item::cond_result *cond_value) Item::cond_result *cond_value, COND_EQUAL **cond_equal)
{ {
THD *thd= join->thd; THD *thd= join->thd;
DBUG_ENTER("optimize_cond"); DBUG_ENTER("optimize_cond");
...@@ -10412,7 +10415,7 @@ optimize_cond(JOIN *join, COND *conds, List<TABLE_LIST> *join_list, ...@@ -10412,7 +10415,7 @@ optimize_cond(JOIN *join, COND *conds, List<TABLE_LIST> *join_list,
if (!conds) if (!conds)
{ {
*cond_value= Item::COND_TRUE; *cond_value= Item::COND_TRUE;
build_equal_items(join->thd, NULL, NULL, join_list, &join->cond_equal); build_equal_items(join->thd, NULL, NULL, join_list, cond_equal);
} }
else else
{ {
......
...@@ -1570,6 +1570,7 @@ public: ...@@ -1570,6 +1570,7 @@ public:
TABLE_LIST *tables_list; ///<hold 'tables' parameter of mysql_select TABLE_LIST *tables_list; ///<hold 'tables' parameter of mysql_select
List<TABLE_LIST> *join_list; ///< list of joined tables in reverse order List<TABLE_LIST> *join_list; ///< list of joined tables in reverse order
COND_EQUAL *cond_equal; COND_EQUAL *cond_equal;
COND_EQUAL *having_equal;
SQL_SELECT *select; ///<created in optimisation phase SQL_SELECT *select; ///<created in optimisation phase
JOIN_TAB *return_tab; ///<used only for outer joins JOIN_TAB *return_tab; ///<used only for outer joins
Item **ref_pointer_array; ///<used pointer reference for this select Item **ref_pointer_array; ///<used pointer reference for this select
...@@ -1657,6 +1658,7 @@ public: ...@@ -1657,6 +1658,7 @@ public:
zero_result_cause= 0; zero_result_cause= 0;
optimized= 0; optimized= 0;
cond_equal= 0; cond_equal= 0;
having_equal= 0;
group_optimized_away= 0; group_optimized_away= 0;
no_rows_in_result_called= 0; no_rows_in_result_called= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment