[MDEV-32219] Shift/reduce grammar conflict: GRANT .. ON FUNCTION Created: 2023-09-21  Updated: 2023-09-21  Resolved: 2023-09-21

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 10.6, 10.7, 10.8, 10.9, 10.11, 11.0, 11.1, 11.2, 11.3
Fix Version/s: 11.3.0

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

Issue Links:
Blocks
blocks MDEV-32101 CREATE PACKAGE [BODY] for sql_mode=DE... Closed

 Description   

The grammar in sql_yacc.yy is conflicting in the grant_privileges rule.

  • The keyword FUNCTION is not reserved in MariaDB, it's a valid a table name.
  • The keywotd TABLE is optional in the ON TABLE syntax

So the sequence "ON FUNCTION" is ambiguous:

grant_privileges ON FUNCTION f1 TO foo@localhost;
grant_privileges ON [TABLE] function TO foo@localhost;

It can either be a ON FUNCTION or "ON TABLE function" with

Here's the bison -rall output:

  222 sp_handler: . FUNCTION_SYM
  223           | . PROCEDURE_SYM
  224           | . PACKAGE_ORACLE_SYM
  225           | . PACKAGE_ORACLE_SYM BODY_ORACLE_SYM
  3405 grant_command: grant_privileges ON . opt_table grant_ident TO_SYM grant_l
  3406              | grant_privileges ON . sp_handler grant_ident TO_SYM grant_
  3419 opt_table: . %empty  [IDENT, IDENT_QUOTED, EMPTY_SYM, JSON_TABLE_SYM, IGN
  3420          | . TABLE_SYM
 
    PACKAGE_ORACLE_SYM  shift, and go to state 2152
    PROCEDURE_SYM       shift, and go to state 2153
    TABLE_SYM           shift, and go to state 2154
    FUNCTION_SYM        shift, and go to state 2155
 
    FUNCTION_SYM  [reduce using rule 3419 (opt_table)]
    $default      reduce using rule 3419 (opt_table)

The same problem is also reported in the REVOKE grammar.

The opt_table rule should be resolve using %prec. It's empty branch should parse only if the following lookahead token is not FUNCTION_SYM.


Generated at Thu Feb 08 10:29:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.