[MDEV-17374] Shift/reduce conflicts because of SOUNDS_SYM, ESCAPE_SYM, USER_SYM not given precedence Created: 2018-10-04  Updated: 2018-10-04  Resolved: 2018-10-04

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.3.11

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-17359 || operator is not understand by "lik... Closed

 Description   

bison -v sql_yacc.yy reports some conflicts caused by the fact that SOUNDS_SYM, ESCAPE_SYM, USER_SYM are not given any precedence.

Summary:

  • SOUNDS_SYM should have the same precedence with LIKE and REGEXP (i.e. should be in the same %left directive with LIKE). It seems it was just forgotten.
  • ESCAPE_SYM should have its own %left directive with a very low precedence, and the empty branch in the opt_escape rule should have even lower precedence than ESCAPE_SYM. The current parser default behavior is to hungry scan all possible expressions between LIKE and the optional ESCAPE clause. Adding precedence as described for empty and non-empty ESCAPE clauses will preserve this behavior and remove conflicts.
  • The "| USER_SYM" line in keyword_sp_var_and_label should have its %prec directive, to treat "USER" as a identifier only if it's not followed by a TEXT_STRING. Similar conflicts were earlier addressed for TRANSACTION_SYM, TIMESTAMP, PERIOD_SYM, SYSTEM (they can also be identifiers, or can have a special meaning).

The relevant bison -v output pieces:

State 1019
  ...
  1482          | bit_expr . SOUNDS_SYM LIKE bit_expr
  ...
    SOUNDS_SYM         shift, and go to state 1548
    SOUNDS_SYM  [reduce using rule 1487 (predicate)]

State 1963
 
  1612 function_call_keyword: USER_SYM . '(' ')'
  2366 kill_expr: USER_SYM . user
  2952 keyword_sp_var_and_label: USER_SYM .
 
    USER_SYM                     shift, and go to state 557
    SOUNDS_SYM  [reduce using rule 2952 (keyword_sp_var_and_label)]

State 2183
 
  1483 predicate: bit_expr LIKE mysql_concatenation_expr . opt_escape
  1591 mysql_concatenation_expr: mysql_concatenation_expr . MYSQL_CONCAT_SYM simple_expr
 
    MYSQL_CONCAT_SYM  shift, and go to state 1560
    ESCAPE_SYM        shift, and go to state 2827
 
    MYSQL_CONCAT_SYM  [reduce using rule 1923 (opt_escape)]
    ESCAPE_SYM        [reduce using rule 1923 (opt_escape)]
    $default          reduce using rule 1923 (opt_escape)
 
    opt_escape  go to state 2828

State 2834
 
  1484 predicate: bit_expr not LIKE mysql_concatenation_expr . opt_escape
  1591 mysql_concatenation_expr: mysql_concatenation_expr . MYSQL_CONCAT_SYM simple_expr
 
    MYSQL_CONCAT_SYM  shift, and go to state 1560
    ESCAPE_SYM        shift, and go to state 2827
 
    MYSQL_CONCAT_SYM  [reduce using rule 1923 (opt_escape)]
    ESCAPE_SYM        [reduce using rule 1923 (opt_escape)]
    $default          reduce using rule 1923 (opt_escape)
 
    opt_escape  go to state 3407


Generated at Thu Feb 08 08:35:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.