-
Ole John Aske authored
Root cause for this bug is that the optimizer try to detect& optimize the special case: '<field> BETWEEN c1 AND c1' and handle this as the condition '<field> = c1' This was implemented inside add_key_field(.. *field, *value[]...) which assumed field to refer key Field, and value[] to refer a [low...high] constant pair. value[0] and value[1] was then compared for equality. In a 'normal' BETWEEN condition of the form '<field> BETWEEN val1 and val2' the BETWEEN operation is represented with an argementlist containing the values [<field>, val1, val2] - add_key_field() is then called with parameters field=<field>, *value=val1. However, if the BETWEEN predicate specified: 1) '<const1> BETWEEN<const2> AND<field> the 'field' and 'value' arguments to add_key_field() had to be swapped. This was implemented by trying to cheat add_key_field() to handle it like: 2) '<const1> GE<const2> AND<const1> LE<field>' As we didn't really replace the BETWEEN operation with 'ge' and 'le', add_key_field() still handled it as a 'BETWEEN' and compared the (swapped) arguments<const1> and<const2> for equality. If they was equal, the condition 1) was incorrectly 'optimized' to: 3) '<field> EQ <const1>' This fix moves this optimization of '<field> BETWEEN c1 AND c1' into add_key_fields() which then calls add_key_equal_fields() to collect key equality / comparison for the key fields in the BETWEEN condition.
59269b1d