{"id":3851,"date":"2012-11-02T10:40:54","date_gmt":"2012-11-02T02:40:54","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=3851"},"modified":"2023-11-01T23:10:15","modified_gmt":"2023-11-01T15:10:15","slug":"mysql-innodb-source-code-optimization-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2012\/11\/mysql-innodb-source-code-optimization-1\/","title":{"rendered":"MySQL\u6e90\u4ee3\u7801\uff1a\u4eceSQL\u8bed\u53e5\u5230MySQL\u5185\u90e8\u5bf9\u8c61"},"content":{"rendered":"<style>\n#content h3{\n  color:red;\n  font-size:14px;\n}\n#content h4{\n  color:blue;\n  font-size:14px;\n}\n#content blockquote{\n  font-family:\"Courier New\",Courier,monospace;\n  white-space:pre;\n}\n<\/style>\n<p>\u81ea\u4ece\u6709\u4e86\u5fae\u8584\u540e<a href=\"http:\/\/weibo.com\/1649162557\/z29E2Dxgm\">\u535a\u5ba2\u5c31\u5199\u5f97\u5c11\u4e86<\/a>\uff0c\u4e0a\u4e00\u7bc7\u535a\u5ba2\u5df2\u7ecf\u662f6\u6708\u4efd\u5199\u7684\u4e86&#8230; \u4ece\u5199<a href=\"http:\/\/www.orczhou.com\/index.php\/2010\/06\/mysql-innodb-source-code-sync-1\/\" target=\"_blank\" rel=\"noopener\">\u7b2c\u4e00\u7bc7\u5173\u4e8eMySQL\u6e90\u7801<\/a>\u7684\u6587\u7ae0\u4e4b\u540e\u4e5f\u5df2\u7ecf\u8fc7\u4e86\u5f88\u4e45\uff0c\u7ee7\u7eed\u4e0a\u8def\u3002<\/p>\n<p>\u4f18\u5316\u5668\u662f\u5173\u7cfb\u6570\u636e\u5e93\u7684\u4e00\u4e2a\u91cd\u8981\u800c\u6709\u7279\u8272\u7684\u90e8\u5206\uff0c\u4f18\u5316\u5668\u7684\u7406\u8bba\u548c\u5b9e\u8df5\u4e5f\u591a\u534a\u4e5f\u90fd\u5f88\u590d\u6742\uff0c\u672c\u7cfb\u5217\u6587\u7ae0\u5e0c\u671b\u901a\u8fc7\u89e3\u6790MySQL\u4f18\u5316\u5668\uff0c\u6765\u7528\u597dMySQL,\u626c\u5176\u957f\uff0c\u907f\u5176\u77ed\u3002\u987a\u4fbf\u4e5f\u4e00\u7aa5\u5173\u7cfb\u6570\u636e\u5e93\u4f18\u5316\u5668\u7684\u5b9e\u73b0\u601d\u8def\u3002\u6587\u7ae0\u5c06\u91cd\u70b9\u4ecb\u7ecd\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u7ed3\u6784\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u800c\u4e0d\u662f\u4fa7\u91cd\u4e8e\u4ee3\u7801\uff08&#8221;<a href=\"http:\/\/programmers.stackexchange.com\/questions\/163185\/torvalds-quote-about-good-programmer\" target=\"_blank\" rel=\"noopener\">Bad programmers worry about the code. Good programmers worry about data structures and their relationships<\/a>.&#8221;\uff09\u3002<\/p>\n\n<h3>0 \u5199\u5728\u524d\u9762<\/h3>\n<p>\u672c\u6587\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1a\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u6587\u7ae0\u80fd\u591f\u5e2e\u4f60\u66f4\u52a0\u987a\u7545\u7684\u7406\u89e3MySQL\u4f18\u5316\u5668\u7684\u884c\u4e3a\uff1b\u5728\u4f60\u9605\u8bfbMySQL\u6e90\u4ee3\u7801\u4e4b\u524d\u4e86\u89e3\u66f4\u591a\u7684\u80cc\u540e\u601d\u8def\u3002<\/p>\n<p>\u672c\u6587<strong>\u4e0d\u89e3\u51b3<\/strong>\u4ec0\u4e48\u95ee\u9898\uff1a\u6559\u4f60\u5982\u4f55\u8bfb\u61c2\u6e90\u4ee3\u7801\uff1b<\/p>\n<p>\u8fd9\u4e2a\u7cfb\u5217\u5f88\u957f,\u5927\u6982\u6309\u8fd9\u6837\u7684\u601d\u8def\u8fdb\u884c\u4e0b\u53bb: \u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\u3001\u8bed\u6cd5\u89e3\u6790\u3001JOIN\u7684\u4e3b\u8981\u7b97\u6cd5\u3001JOIN\u987a\u5e8f\u548c\u5355\u8868\u8bbf\u95ee\u3002\u6570\u636e\u7ed3\u6784(\u4ee5\u53ca\u4ed6\u4eec\u7684\u5173\u7cfb)\u548c\u7b97\u6cd5\u6d41\u7a0b\u603b\u662f\u76f8\u4e92\u7a7f\u63d2\u4ecb\u7ecd\u3002<\/p>\n<p>\u5efa\u8bae\u9605\u8bfb\uff1a\u53c2\u8003\u6587\u732e\u4e2d\u7684\u6587\u7ae0\u548c\u4e66\u7c4d\uff0c\u90fd\u5efa\u8bae\u5728\u9605\u8bfb\u672c\u6587\u4e4b\u524d\u9605\u8bfb\u3002<\/p>\n<h3>1 SQL\u8bed\u53e5\u89e3\u6790\u57fa\u7840<\/h3>\n<h4>1.1 \u8bed\u6cd5\u89e3\u6790\u57fa\u7840\/Flex\u4e0eBison<\/h4>\n<p>MySQL\u8bed\u6cd5\u89e3\u6790\u5c01\u88c5\u5728\u51fd\u6570MYSQLparser\u4e2d\u5b8c\u6210\u3002\u8ddf\u5176\u4ed6\u7684\u8bed\u6cd5\u89e3\u6790\u5668\u4e00\u6837\uff0c\u5b83\u5305\u542b\u4e24\u4e2a\u6a21\u5757\uff1a\u8bcd\u6cd5\u5206\u6790(Lexical scanner)\u548c\u8bed\u6cd5\u89c4\u5219(Grammar rule module)\u3002\u8bcd\u6cd5\u5206\u6790\u5c06\u6574\u4e2aSQL\u8bed\u53e5\u6253\u788e\u6210\u4e00\u4e2a\u4e2a\u5355\u8bcd(Token)\uff0c\u800c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u5219\u6839\u636eMySQL\u5b9a\u4e49\u7684\u8bed\u6cd5\u89c4\u5219\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u5b58\u50a8\u5728\u5bf9\u8c61THD->LEX\u7ed3\u6784\u5f53\u4e2d\u3002\u6700\u540e\u4f18\u5316\u5668\uff0c\u6839\u636e\u8fd9\u91cc\u7684\u6570\u636e\uff0c\u751f\u6210\u6267\u884c\u8ba1\u5212\uff0c\u518d\u8c03\u7528\u5b58\u50a8\u5f15\u64ce\u63a5\u53e3\u6267\u884c\u3002<\/p>\n<p>\u8bcd\u6cd5\u5206\u6790\u548c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u6709\u4e24\u4e2a\u8f83\u6210\u719f\u7684\u5f00\u6e90\u5de5\u5177Flex\u548cBison\u5206\u522b\u7528\u6765\u89e3\u51b3\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002MySQL\u51fa\u4e8e\u6027\u80fd\u548c\u7075\u6d3b\u8003\u8651\uff0c\u9009\u62e9\u4e86\u81ea\u5df1\u5b8c\u6210\u8bcd\u6cd5\u89e3\u6790\u90e8\u5206\uff0c\u8bed\u6cd5\u89c4\u5219\u90e8\u5206\u4f7f\u7528Bison\u3002\u8bcd\u6cd5\u89e3\u6790\u548cBison\u6c9f\u901a\u7684\u6838\u5fc3\u51fd\u6570\u662f\u7531\u8bcd\u6cd5\u89e3\u6790\u5668\u63d0\u4f9b\u7684\u51fd\u6570\u63a5\u53e3yylex()\uff0c\u5728Bison\u4e2d\uff0c\u5fc5\u8981\u7684\u65f6\u5019\u8c03\u7528yylex()\u83b7\u5f97\u8bcd\u6cd5\u89e3\u6790\u7684\u6570\u636e\uff0c\u5b8c\u6210\u81ea\u5df1\u7684\u8bed\u6cd5\u89e3\u6790\u3002Bison\u7684\u5165\u53e3\u65f6yyparse()\uff0c\u5728MySQL\u4e2d\u662f\uff0cMYSQLParse\u3002<\/p>\n<p>\u5982\u679c\u5bf9\u8bcd\u6cd5\u5206\u6790\u548c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u611f\u5230\u964c\u751f\uff0c\u5efa\u8bae\u9605\u8bfb\u53c2\u8003\u6587\u732e[4][5][6]\u5148<sup>\u6ce81<\/sup>\uff0c\u5426\u5219\u5f88\u96be\u7406\u89e3\u6574\u4e2a\u67b6\u6784\uff0c\u6216\u8005\u81f3\u5c11\u4f1a\u6709\u5f88\u5f3a\u7684\u65ad\u5c42\u611f\u3002\u800c\u4e14\uff0c\u6839\u636eBison\u7684Action\u8ffd\u8e2aMySQL\u6570\u636e\u7684\u5b58\u50a8\u7ed3\u6784\u662f\u5f88\u6709\u6548\u7684\u3002<!--more--><\/p>\n<h4>1.2 MySQL\u8bed\u6cd5\u89e3\u6790Sample\u4e0e\u793a\u610f\u56fe<\/h4>\n<p>\u7b80\u5355\u7684\u89e3\u6790\u8fc7\u7a0b\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u793a\u610f\u56fe\u8bf4\u660e\uff1a<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/8137677062\/\" title=\"MySQL\u8bed\u6cd5\u89e3\u6790\u8bf4\u660e--1 by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm9.staticflickr.com\/8056\/8137677062_acce7dc9fd.jpg\" width=\"500\" height=\"148\" alt=\"MySQL\u8bed\u6cd5\u89e3\u6790\u8bf4\u660e--1\"><\/a><\/p>\n<p>\u5177\u4f53\u7684\u89e3\u6790\u4e00\u4e2aSQL\u8bed\u53e5\u7684WHERE\u90e8\u5206:<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/8138271359\/\" title=\"MySQL\u8bed\u6cd5\u89e3\u6790\u8bf4\u660e--2 by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm9.staticflickr.com\/8192\/8138271359_b0d5c747ea_z.jpg\" width=\"600\" height=\"230\" alt=\"MySQL\u8bed\u6cd5\u89e3\u6790\u8bf4\u660e--2\"><\/a><\/p>\n<h3>2 SQL\u8bed\u53e5\u5230MySQL\u7684\u5185\u90e8\u5bf9\u8c61<\/h3>\n<p>Bison\u5728\u505a\u8bed\u6cd5\u89e3\u6790\u540e\uff0c\u4f1a\u5c06\u89e3\u6790\u7ed3\u679c\uff08\u4e00\u9897\u89e3\u6790\u6811\/AST\uff09\u5b58\u50a8\u5728THD::LEX\u4e2d\u3002\u8fd9\u91cc\u5c06\u901a\u8fc7\u8003\u5bdf\u5b58\u50a8WHERE\u7684\u6570\u636e\u7ed3\u6784\u6765\u67e5\u770b\u8bed\u6cd5\u89e3\u6790\u7684\u7ed3\u679c\u3002<\/p>\n<h4>2.1 \u8457\u540d\u7684Item\u5bf9\u8c61<\/h4>\n<p>\u5728\u4e86\u89e3MySQL\u7684\u89e3\u6790\u6811\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u6765\u8ba4\u8bc6\u4e00\u4e2a\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784Item\u3002\u8fd9\u662f\u4e00\u4e2a\u57fa\u7840\u5bf9\u8c61\uff0c\u5728\u4f18\u5316\u5668\u90e8\u5206\u4ee3\u7801\uff0c\u6ee1\u5730\u90fd\u662f\u3002\u5728MySQL Internal Manual\u4e2d\u4e5f\u5355\u72ec\u4ecb\u7ecd\uff1a<a href=\"http:\/\/dev.mysql.com\/doc\/internals\/en\/item-class.html\" target=\"_blank\" rel=\"noopener\">The Item Class<\/a>\u3002<\/p>\n<p>Item\u662f\u4e00\u4e2a\u57fa\u7840\u7c7b\uff0c\u5728\u4ed6\u7684\u57fa\u7840\u4e0a\u6d3e\u751f\u4e86\u5f88\u591a\u5b50\u5b59\u3002<strong>\u8fd9\u4e9b\u5b50\u7c7b\u57fa\u672c\u63cf\u8ff0\u6240\u6709SQL\u8bed\u53e5\u4e2d\u7684\u5bf9\u8c61<\/strong>\uff0c\u4ed6\u4eec\u5305\u62ec\uff1a<\/p>\n<li>\u4e00\u4e2a\u6587\u672c\u5b57\u7b26\u4e32\/\u6570\u503c\u5bf9\u8c61<\/li>\n<li>\u4e00\u4e2a\u6570\u636e\u8868\u7684\u67d0\u4e00\u5217\uff08\u4f8b\u5982\uff0cselect c1,c2 from dual&#8230;\u4e2d\u7684c1\uff0cc2\uff09<\/li>\n<li>\u4e00\u4e2a\u6bd4\u8f83\u52a8\u4f5c\uff0c\u4f8b\u5982c1>10<\/li>\n<li>\u4e00\u4e2aWHERE\u5b50\u53e5\u7684\u6240\u6709\u4fe1\u606f<\/li>\n<li>&#8230;&#8230;<\/li>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cItem\u57fa\u672c\u4e0a\u4ee3\u7801SQL\u8bed\u53e5\u4e2d\u7684\u6240\u6709\u5bf9\u8c61\u3002\u5728\u8bed\u6cd5\u89e3\u6790\u6811\u4e2d\uff0c\u8fd9\u4e9bItem\u4ee5\u4e00\u9897\u6811\u7684\u5f62\u5f0f\u5b58\u5728\u3002\u793a\u610f\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/8137802908\/\" title=\"WHERE\u8bed\u6cd5\u6811 by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm9.staticflickr.com\/8464\/8137802908_ed20dd05e2.jpg\" width=\"500\" height=\"375\" alt=\"WHERE\u8bed\u6cd5\u6811\"><\/a><\/p>\n<h4>2.2 Bison\u8bed\u6cd5\u4e2d\u7684WHERE<\/h4>\n<p>\u4eceSELECT\u5b50\u53e5\u5f00\u59cb\uff0c\u6211\u4eec\u770b\u5230\u5bf9\u5e94\u7684where_clause\u5c31\u662f\u6211\u4eec\u5173\u6ce8\u7684WHERE\uff1a<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/8137782297\/\" title=\"bison_where by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm9.staticflickr.com\/8336\/8137782297_b73b1e55b5_z.jpg\" width=\"572\" height=\"298\" alt=\"bison_where\"><\/a><\/p>\n<p>\u6211\u4eec\u6765\u770b\u770bBison\u4e2d\u7684\u51e0\u4e2a\u91cd\u8981\u7684Action<sup>\u53c2\u8003\u6ce81<\/sup>\uff1a<\/p>\n<pre><blockquote>where_clause:\r\n        \/* empty *\/ {}\r\n      | WHERE expr\r\n      {\r\n        THD->lex->current_select->where = $2\r\n      }\r\n\r\nexpr:\r\n      ...\r\n      | expr and expr \r\n       {\r\n         $$ = new (YYTHD->mem_root) Item_cond_and($1, $3)\r\n       } \r\n      |ident comp_op NUM   \/*\u8fd9\u4e00\u884c\u5e76\u4e0d\u662f\u6e90\u7801\u7684\u4e00\u90e8\u5206\uff0c\u4fbf\u4e8e\u7406\u89e3\u7b80\u5316\u5982\u6b64*\/\r\n      {\r\n         $$ = new Item_func_ge(a, b); \/*\u8fd9\u4e00\u884c\u5e76\u4e0d\u662f\u6e90\u7801\u7684\u4e00\u90e8\u5206\uff0c\u4fbf\u4e8e\u7406\u89e3\u7b80\u5316\u5982\u6b64*\/\r\n      }\r\n<\/blockquote><\/pre>\n<p>\u6839\u636e\u8fd9\u91cc\u7684Bison\u8bed\u6cd5\uff0c\u5c31\u53ef\u4ee5\u751f\u4ea7\u4e0a\u9762\u7684WHERE\u8bed\u6cd5\u6811\u4e86\u3002\u5982\u679c\u4f60\u662f\u548c\u6211\u4e00\u6837\u521a\u521a\u4e86\u89e3Flex\/Bison\/AST\uff0c\u4e00\u5b9a\u4e5f\u4f1a\u51b3\u5b9a\u5f88\u5de7\u5999\uff01<\/p>\n<h4>2.3 WHERE\u7684\u6570\u636e\u7ed3\u6784\u548c\u4ed6\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb<\/h4>\n<p>\u7ed8\u5236\u4e86\u4e0b\u9762\u7684\u5173\u7cfb\u56fe\u7528\u6765\u63cf\u8ff0WHERE\u548cWHERE\u89e3\u6790\u6811\u7684\u5404\u4e2a\u5206\u652f\uff1a<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/8137822435\/\" title=\"theclassofwhere by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm9.staticflickr.com\/8328\/8137822435_f14fa91c0c_z.jpg\" width=\"640\" height=\"164\" alt=\"theclassofwhere\"><\/a><\/p>\n<p>\u4f8b\u5982WHERE\u6761\u4ef6<strong>WHERE c1=&#8221;orczhou&#8221; and c2 > 10<\/strong>\uff0cWHERE\u672c\u8eab(lex->select->where)\u5c31\u662f\u4e00\u4e2aItem_cond_and\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u4e2d\u6709\u4e00\u4e2aItem List\uff0c\u5c06List\u4e2d\u6bcf\u4e00\u4e2aItem\u7684\u503c\u505aAND\u8fd0\u8f93\uff0c%E<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u81ea\u4ece\u6709\u4e86\u5fae\u8584\u540e\u535a\u5ba2\u5c31\u5199\u5f97\u5c11\u4e86\uff0c\u4e0a\u4e00\u7bc7\u535a\u5ba2\u5df2\u7ecf\u662f6\u6708\u4efd\u5199\u7684\u4e86&#8230; \u4ece\u5199\u7b2c\u4e00\u7bc7\u5173\u4e8eMySQL\u6e90\u7801\u7684\u6587\u7ae0\u4e4b\u540e\u4e5f\u5df2\u7ecf\u8fc7\u4e86\u5f88\u4e45\uff0c\u7ee7\u7eed\u4e0a\u8def\u3002 \u4f18\u5316\u5668\u662f\u5173\u7cfb\u6570\u636e\u5e93\u7684\u4e00\u4e2a\u91cd\u8981\u800c\u6709\u7279\u8272\u7684\u90e8\u5206\uff0c\u4f18\u5316\u5668\u7684\u7406\u8bba\u548c\u5b9e\u8df5\u4e5f\u591a\u534a\u4e5f\u90fd\u5f88\u590d\u6742\uff0c\u672c\u7cfb\u5217\u6587\u7ae0\u5e0c\u671b\u901a\u8fc7\u89e3\u6790MySQL\u4f18\u5316\u5668\uff0c\u6765\u7528\u597dMySQL,\u626c\u5176\u957f\uff0c\u907f\u5176\u77ed\u3002\u987a\u4fbf\u4e5f\u4e00\u7aa5\u5173\u7cfb\u6570\u636e\u5e93\u4f18\u5316\u5668\u7684\u5b9e\u73b0\u601d\u8def\u3002\u6587\u7ae0\u5c06\u91cd\u70b9\u4ecb\u7ecd\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u7ed3\u6784\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u800c\u4e0d\u662f\u4fa7\u91cd\u4e8e\u4ee3\u7801\uff08&#8221;Bad programmers worry about the code. Good programmers worry about data structures and their relationships.&#8221;\uff09\u3002 0 \u5199\u5728\u524d\u9762 \u672c\u6587\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898\uff1a\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u6587\u7ae0\u80fd\u591f\u5e2e\u4f60\u66f4\u52a0\u987a\u7545\u7684\u7406\u89e3MySQL\u4f18\u5316\u5668\u7684\u884c\u4e3a\uff1b\u5728\u4f60\u9605\u8bfbMySQL\u6e90\u4ee3\u7801\u4e4b\u524d\u4e86\u89e3\u66f4\u591a\u7684\u80cc\u540e\u601d\u8def\u3002 \u672c\u6587\u4e0d\u89e3\u51b3\u4ec0\u4e48\u95ee\u9898\uff1a\u6559\u4f60\u5982\u4f55\u8bfb\u61c2\u6e90\u4ee3\u7801\uff1b \u8fd9\u4e2a\u7cfb\u5217\u5f88\u957f,\u5927\u6982\u6309\u8fd9\u6837\u7684\u601d\u8def\u8fdb\u884c\u4e0b\u53bb: \u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\u3001\u8bed\u6cd5\u89e3\u6790\u3001JOIN\u7684\u4e3b\u8981\u7b97\u6cd5\u3001JOIN\u987a\u5e8f\u548c\u5355\u8868\u8bbf\u95ee\u3002\u6570\u636e\u7ed3\u6784(\u4ee5\u53ca\u4ed6\u4eec\u7684\u5173\u7cfb)\u548c\u7b97\u6cd5\u6d41\u7a0b\u603b\u662f\u76f8\u4e92\u7a7f\u63d2\u4ecb\u7ecd\u3002 \u5efa\u8bae\u9605\u8bfb\uff1a\u53c2\u8003\u6587\u732e\u4e2d\u7684\u6587\u7ae0\u548c\u4e66\u7c4d\uff0c\u90fd\u5efa\u8bae\u5728\u9605\u8bfb\u672c\u6587\u4e4b\u524d\u9605\u8bfb\u3002 1 SQL\u8bed\u53e5\u89e3\u6790\u57fa\u7840 1.1 \u8bed\u6cd5\u89e3\u6790\u57fa\u7840\/Flex\u4e0eBison MySQL\u8bed\u6cd5\u89e3\u6790\u5c01\u88c5\u5728\u51fd\u6570MYSQLparser\u4e2d\u5b8c\u6210\u3002\u8ddf\u5176\u4ed6\u7684\u8bed\u6cd5\u89e3\u6790\u5668\u4e00\u6837\uff0c\u5b83\u5305\u542b\u4e24\u4e2a\u6a21\u5757\uff1a\u8bcd\u6cd5\u5206\u6790(Lexical scanner)\u548c\u8bed\u6cd5\u89c4\u5219(Grammar rule module)\u3002\u8bcd\u6cd5\u5206\u6790\u5c06\u6574\u4e2aSQL\u8bed\u53e5\u6253\u788e\u6210\u4e00\u4e2a\u4e2a\u5355\u8bcd(Token)\uff0c\u800c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u5219\u6839\u636eMySQL\u5b9a\u4e49\u7684\u8bed\u6cd5\u89c4\u5219\u751f\u6210\u5bf9\u5e94\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u5b58\u50a8\u5728\u5bf9\u8c61THD->LEX\u7ed3\u6784\u5f53\u4e2d\u3002\u6700\u540e\u4f18\u5316\u5668\uff0c\u6839\u636e\u8fd9\u91cc\u7684\u6570\u636e\uff0c\u751f\u6210\u6267\u884c\u8ba1\u5212\uff0c\u518d\u8c03\u7528\u5b58\u50a8\u5f15\u64ce\u63a5\u53e3\u6267\u884c\u3002 \u8bcd\u6cd5\u5206\u6790\u548c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u6709\u4e24\u4e2a\u8f83\u6210\u719f\u7684\u5f00\u6e90\u5de5\u5177Flex\u548cBison\u5206\u522b\u7528\u6765\u89e3\u51b3\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002MySQL\u51fa\u4e8e\u6027\u80fd\u548c\u7075\u6d3b\u8003\u8651\uff0c\u9009\u62e9\u4e86\u81ea\u5df1\u5b8c\u6210\u8bcd\u6cd5\u89e3\u6790\u90e8\u5206\uff0c\u8bed\u6cd5\u89c4\u5219\u90e8\u5206\u4f7f\u7528Bison\u3002\u8bcd\u6cd5\u89e3\u6790\u548cBison\u6c9f\u901a\u7684\u6838\u5fc3\u51fd\u6570\u662f\u7531\u8bcd\u6cd5\u89e3\u6790\u5668\u63d0\u4f9b\u7684\u51fd\u6570\u63a5\u53e3yylex()\uff0c\u5728Bison\u4e2d\uff0c\u5fc5\u8981\u7684\u65f6\u5019\u8c03\u7528yylex()\u83b7\u5f97\u8bcd\u6cd5\u89e3\u6790\u7684\u6570\u636e\uff0c\u5b8c\u6210\u81ea\u5df1\u7684\u8bed\u6cd5\u89e3\u6790\u3002Bison\u7684\u5165\u53e3\u65f6yyparse()\uff0c\u5728MySQL\u4e2d\u662f\uff0cMYSQLParse\u3002 \u5982\u679c\u5bf9\u8bcd\u6cd5\u5206\u6790\u548c\u8bed\u6cd5\u89c4\u5219\u6a21\u5757\u611f\u5230\u964c\u751f\uff0c\u5efa\u8bae\u9605\u8bfb\u53c2\u8003\u6587\u732e[4][5][6]\u5148\u6ce81\uff0c\u5426\u5219\u5f88\u96be\u7406\u89e3\u6574\u4e2a\u67b6\u6784\uff0c\u6216\u8005\u81f3\u5c11\u4f1a\u6709\u5f88\u5f3a\u7684\u65ad\u5c42\u611f\u3002\u800c\u4e14\uff0c\u6839\u636eBison\u7684Action\u8ffd\u8e2aMySQL\u6570\u636e\u7684\u5b58\u50a8\u7ed3\u6784\u662f\u5f88\u6709\u6548\u7684\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6,5],"tags":[118,58,98],"class_list":["post-3851","post","type-post","status-publish","format-standard","hentry","category-mysql","category-code-staff","tag-mysql","tag-source-code","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=3851"}],"version-history":[{"count":78,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3851\/revisions"}],"predecessor-version":[{"id":9505,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/3851\/revisions\/9505"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=3851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=3851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=3851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}