← Back to team overview

maria-developers team mailing list archive

Re: Probably in a bug in simple_pred()

 

Hi!

> From: Alexander Barkov <bar@xxxxxxxxxxx>

> Hi Sergey,
>
> I probably found a bug in simple_pred() in opt_sum.cc.
>
> In this piece of code:
>
>>   case 3:
>>     /* field BETWEEN const AND const */
>>     item= func_item->arguments()[0]->real_item();
>>     if (item->type() == Item::FIELD_ITEM)
>>     {
>>       args[0]= item;
>>       for (int i= 1 ; i <= 2; i++)
>>       {
>>         item= func_item->arguments()[i]->real_item();
>>         if (!item->const_item())
>>           return 0;
>>         args[i]= item;
>>         if (check_item1_shorter_item2(args[0], args[1]))
>
>
> Should't it be
>
> if (check_item1_shorter_item2(args[0], args[i]))
>
> ?
>
>>           return 0;
>>       }
>>     }
>
>
> If this is a bug, can you please help to make an SQL scrip which would
> be affected by this bug?

yes, it's a bug.  Here is a script that shows that:

drop table if exists t1;
create table t1 (a varchar(10), key (a));
insert into t1 values("bar"),("Cafe");
explain select min(a) from t1 where a between "a" and "Cafe2";
explain select min(a) from t1 where a between "a" and
"Cafeeeeeeeeeeeeeeeeeeeeeeeeee";
explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb"
and "Cafe2";

The output is:
 1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    |
NULL | NULL | Select tables optimized away |

For the two first cases and:
|    1 | SIMPLE      | t1    | index | a             | a    | 13
| NULL |    2 | Using where; Using index |

for the last
The second case should have the same output as the third.

Will fix and push into 10.1

Regards,
Monty


References