• unknown's avatar
    Bug#30625 (Performance, reduce depth for expressions) · be8db2de
    unknown authored
    This is a performance bug, affecting in particular the bison generated code
    for the parser.
    
    Prior to this fix, the grammar used a long chain of reduces to parse an
    expression, like:
      bit_expr -> bit_term
      bit_term -> bit_factor
      bit_factor -> value_expr
      value_expr -> term
      term -> factor
    etc
    
    This chain of reduces cause the internal state automaton in the generated
    parser to execute more state transitions and more reduces, so that the
    generated MySQLParse() function would spend a lot of time looping to execute
    all the grammar reductions.
    
    With this patch, the grammar has been reorganized so that rules are more
    "flat", limiting the depth of reduces needed to parse <expr>.
    
    Tests have been written to enforce that relative priorities and properties
    of operators have not changed while changing the grammar.
    
    See the bug report for performance data.
    
    
    mysql-test/r/parser_precedence.result:
      Improved test coverage for operator precedence
    mysql-test/t/parser_precedence.test:
      Improved test coverage for operator precedence
    sql/sql_yacc.yy:
      Simplified the grammar to improve performances
    be8db2de
parser_precedence.result 24 KB