首页 > 数据库 >flex and bison usage in mysql

flex and bison usage in mysql

时间:2023-10-19 15:05:25浏览次数:29  
标签:flex union mysql parse lex does bison sql usage

query parsing in mysql

mysql source code version: 8.0.34 (from MYSQL_VERSION file)

This an article from questions to understandings.

  • which file does mysql use to define sql grammar?
    sql/sql_yacc.yy

  • what is the name yyparse replaced with in mysql?
    Searching name-prefix in mysql source code, you will get --name-prefix=MYSQL in sql/CMakeLists.txt. In short, yyparse function is replaced with MYSQLparse function. In latest version of mysql, yyparse is named as my_sql_parser_parse due to the directive %define api.prefix {my_sql_parser_}.

  • where does the MYSQLparse function be called?
    In THD::sql_parser() method, which is defined in sql/sql_class.cc file.

  • what is the signature of MYSQLparse function and how is it generated?
    Here's the signature,

    extern int MYSQLparse(class THD * thd, class Parse_tree_root * *root);
    

    This signature will be generated by bison command with following declaration:

    %parse-param { class THD *YYTHD }
    %parse-param { class Parse_tree_root **parse_tree }
    
  • How does the parameters YYTHD and parse_tree be used in semantic actions?
    Here's how YYTHD used,

    prepare:
          PREPARE_SYM ident FROM prepare_src
          {
            THD *thd= YYTHD;
            LEX *lex= thd->lex;
            lex->sql_command= SQLCOM_PREPARE;
            lex->prepared_stmt_name= to_lex_cstring($2);
            lex->contains_plaintext_password= true;
          }
        ;
    
    

    Here's how parse_tree used,

    simple_statement_or_begin:
          simple_statement      { *parse_tree= $1; }
        | begin_stmt
        ;
    
  • How does mysql define the bison YYSTYPE?
    Generally, YYSTYPE definition is generated by bison tool with directive %union. Such as, in .yy file,

    %union {
    	int ival;
    }
    

    and use it as type for nonterminal symbol,

    %type <ival> Iconst
    

    Bison tool will generate a definition in .c or .cc file,

    union YYSTYPE {
      int ival;
    };
    

    However, mysql does not use the %union directive and defines YYSTYPE type in a separate header file sql/parser_yystype.h,

    union YYSTYPE {
      Lexer_yystype lexer;  // terminal values from the lexical scanner
    };
    

    The Lexer_yystype is defined as,

    union Lexer_yystype {
      LEX_STRING lex_str;
      LEX_SYMBOL keyword;
      const CHARSET_INFO *charset;
      PT_hint_list *optimizer_hints;
      LEX_CSTRING hint_string;
    };
    

    Then, mysql defines its nonterminal symbol type as,

    %type <lexer.lex_str> TEXT_STRING_sys TEXT_STRING
    
  • In general, yyparse function calls yylex function internally. How does mysql implement its lexical analyzer?
    From previous question, we know yyparse is replaced with MYSQLparse. As a consequence, yylex is named MYSQLlex. However, mysql does not use flex tool as its lexical analyzer. Instead, mysql implements its own lexical analysis process in class Lex_input_stream.

标签:flex,union,mysql,parse,lex,does,bison,sql,usage
From: https://www.cnblogs.com/lddcool/p/17774696.html

相关文章

  • 非常实用的Flex布局
    [非常实用的Flex布局-个人博客|沧沧凉凉的小站](https://www.cclliang.com/2020/10/01/%E9%9D%A2%E8%AF%95/%E9%9D%9E%E5%B8%B8%E5%AE%9E%E7%94%A8%E7%9A%84Flex%E5%B8%83%E5%B1%80/)Flex布局传统的布局,基于盒装模型,早期的前端开发就是一个叠盒子的过程,即各种<div>的互相嵌套......
  • : Only one usage of each socket address (protocol/network address/port) is norma
    2023/10/1619:07:45tick2023/10/1619:07:46dialtcp7.11.12.26:3309:connectex:Onlyoneusageofeachsocketaddress(protocol/networkaddress/port)isnormallypermitted.panic:runtimeerror:invalidmemoryaddressornilpointerdereference[signal0xc......
  • aFlex脚本入门
    aFlex脚本入门对于A10的aFelx脚本,相信很多人都知道,甚至用过,但是实际上很多工程师在各种项目中的使用可能都是按照模板进行修改,虽然能ok,但是却缺乏对aFelx脚本本质上的了解,所以在用户实际场景与脚本应用场景不完全一致的时候,就会碰到问题,不知如何修改。而更多的技术人员或者用户更......
  • Mybatis-Flex核心功能之@Column
    1、是什么?MyBatis-Flex提供了@Column用来对字段进行更多的配置public@interfaceColumn{/***字段名称*/Stringvalue()default"";/***是否忽略该字段,可能只是业务字段,而非数据库对应字段*/booleanignore()defaultfal......
  • Mybatis-Flex核心功能之@Id
    1、是什么?在Entity类中,MyBatis-Flex是使用@Id注解来标识主键的2、怎么玩?public@interfaceId{/***ID生成策略,默认为none**@return生成策略*/KeyTypekeyType()defaultKeyType.None;/***若keyType类型是seque......
  • vue cli2 3 4使用lib-flexible px2rem完美解决移动端适配问题
    安装lib-flexible$npminstalllib-flexible--savelib-fiexble,lib-flexible会自动在html的head中添加一个metaname="viewport"的标签,同时会自动设置html的font-size为屏幕宽度除以10,也就是1rem等于html根节点的font-size。假如设计稿的宽度是750px,此时1rem应该等于75px。......
  • 父元素flex:1 子元素height:100%
    <style>.box{display:flex;flex-direction:column;overflow:hidden;//只要不是auto}.parent{flex:1;min-height:0;//orheight:0}.children{......
  • Flex布局的三个属性要深刻理解!
    在我们日常开发中,flex布局可以说是家常便饭,对于很多的我们来说(你懂得^_^),可能我们用的比较多的应该就是垂直居中里,也就是下面这段代码:.flex-box{display:flex;justify-content:center;align-items:center;}写的非常好(^_^)!然后我们都知道这个是定义在父元素的,布局效果是......
  • 为什么 CSS flex 布局中没有 `justify-items` 和 `justify-self`?
    为什么CSSflex布局中没有justify-items和justify-self?为什么在CSSflex布局中存在align-items和align-self,却没有justify-items和justify-self呢?要解答这个问题,首先需要理解主轴(mainaxis)和交叉轴(crossaxis)之间的差异。1.主轴和交叉轴的区别在没有折行的情况......
  • flex-basis主轴基准线
    <!DOCTYPEhtml><html> <head> <metacharset="utf-8"> <title></title> <style> html, body{ margin:0; padding:0; } .outer{ width:calc(100vw-200px); height:calc(10......