@@ -159,7 +159,8 @@ static COND *build_equal_items(JOIN *join, COND *cond,
159
159
static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab,
160
160
COND *cond,
161
161
COND_EQUAL *cond_equal,
162
- void *table_join_idx);
162
+ void *table_join_idx,
163
+ bool do_substitution);
163
164
static COND *simplify_joins(JOIN *join, List<TABLE_LIST> *join_list,
164
165
COND *conds, bool top, bool in_sj);
165
166
static bool check_interleaving_with_nj(JOIN_TAB *next);
@@ -2304,7 +2305,7 @@ int JOIN::optimize_stage2()
2304
2305
if (conds)
2305
2306
{
2306
2307
conds= substitute_for_best_equal_field(thd, NO_PARTICULAR_TAB, conds,
2307
- cond_equal, map2table);
2308
+ cond_equal, map2table, true );
2308
2309
if (unlikely(thd->is_error()))
2309
2310
{
2310
2311
error= 1;
@@ -2320,7 +2321,7 @@ int JOIN::optimize_stage2()
2320
2321
if (having)
2321
2322
{
2322
2323
having= substitute_for_best_equal_field(thd, NO_PARTICULAR_TAB, having,
2323
- having_equal, map2table);
2324
+ having_equal, map2table, false );
2324
2325
if (thd->is_error())
2325
2326
{
2326
2327
error= 1;
@@ -2347,7 +2348,7 @@ int JOIN::optimize_stage2()
2347
2348
*tab->on_expr_ref= substitute_for_best_equal_field(thd, NO_PARTICULAR_TAB,
2348
2349
*tab->on_expr_ref,
2349
2350
tab->cond_equal,
2350
- map2table);
2351
+ map2table, true );
2351
2352
if (unlikely(thd->is_error()))
2352
2353
{
2353
2354
error= 1;
@@ -2377,7 +2378,7 @@ int JOIN::optimize_stage2()
2377
2378
while (equals)
2378
2379
{
2379
2380
ref_item= substitute_for_best_equal_field(thd, tab, ref_item,
2380
- equals, map2table);
2381
+ equals, map2table, true );
2381
2382
if (unlikely(thd->is_fatal_error))
2382
2383
DBUG_RETURN(1);
2383
2384
@@ -15418,7 +15419,8 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels,
15418
15419
static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab,
15419
15420
COND *cond,
15420
15421
COND_EQUAL *cond_equal,
15421
- void *table_join_idx)
15422
+ void *table_join_idx,
15423
+ bool do_substitution)
15422
15424
{
15423
15425
Item_equal *item_equal;
15424
15426
COND *org_cond= cond; // Return this in case of fatal error
@@ -15447,7 +15449,8 @@ static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab,
15447
15449
{
15448
15450
Item *new_item= substitute_for_best_equal_field(thd, context_tab,
15449
15451
item, cond_equal,
15450
- table_join_idx);
15452
+ table_join_idx,
15453
+ do_substitution);
15451
15454
/*
15452
15455
This works OK with PS/SP re-execution as changes are made to
15453
15456
the arguments of AND/OR items only
@@ -15529,7 +15532,7 @@ static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab,
15529
15532
cond= eliminate_item_equal(thd, 0, cond_equal, item_equal);
15530
15533
return cond ? cond : org_cond;
15531
15534
}
15532
- else
15535
+ else if (do_substitution)
15533
15536
{
15534
15537
while (cond_equal)
15535
15538
{
0 commit comments