mysql - An explanation for BNF rule -
i'm investigating mysql's sql parser @ moment.
and here interesting thing have noticed , cannot explain:
(in sql_yacc.yy
)
predicate: ... | bit_expr between_sym bit_expr and_sym predicate { $$= new (yythd->mem_root) item_func_between($1,$3,$5); if ($$ == null) mysql_yyabort; }
the same on expression syntax page:
predicate: ... | bit_expr [not] between bit_expr , predicate
that means that
foo between 1 , bar between 1 , 2
query syntactically correct, while makes no sense @ all.
my question: used for? miss if used
bit_expr [not] between bit_expr , bit_expr
instead?
lol (not lol anymore actually)
this query executes without errors:
select * users id between 1 , id between 1 , 10; // returns row id = 1 select * users id between 2 , id between 2 , 10; empty set (0.00 sec)
(update added here) ... , is expected.
presumably converts second expression straight 0
or 1
, uses operand.
upd:
i've filed bug - http://bugs.mysql.com/bug.php?id=69208
it's not expected syntax @ all
upd 2: looks it's minor typo doesn't change parser behaviour @ (well, clear makes unnoticeable slower common between
expression).
your analysis correct:
foo between 1 , bar between 1 , 2
is parsed as:
foo between 1 , (bar between 1 , 2)
and second (parenthesized) predicate presumably evaluate either 0 or 1 (for false or true). therefore, if bar
not between 1 , 2, set of selected values foo
empty (because foo between 1 , 0
shorthand foo >= 1 , f <= 0
, there no values true, allowing nulls). contrariwise, if bar
between 1 , 2, set of selected values foo
set `foo1 equals 1.
and alternative question "what lose if replaced 'predicate' term 'bit_expr'?" might "would gain if replaced 'bit_expr' 'predicate'?"
without careful scrutiny of complete grammar (or, @ least, scrutiny of parts referenced bit_expr
, predicate
, , possibly review of places bit_expr
, predicate
used), hard know answer either question.
Comments
Post a Comment