MySQL lexical analysis on this link on a little introduction, you can understand a rough: http://blog.imaginea.com/mysql-query-parsing/
Key points:
1. SQL parsing includes a syntax analyzer and a lexical analyzer.
A simple practice is to use the bison/flex combination. However, the MySQL lexical analyzer is manually created.
The syntax analyzer entry function is MYSQLparse, and the lexical analyzer entry function is MYSQLlex.
2. the lexical analysis checks whether the token is a keyword.
The most direct method is to get a large keyword array and perform a half-fold search. MySQL has made some optimizations here.
This section mainly introduces this part.
Considering that the keyword is a read-only list, creating a read-only search tree can improve the search performance.
Generate search tree:
1. read the keyword array to generate a Trie tree.
2. adjust the tree and generate an array (that is, a tree not represented by a linked list ).
Use the search tree:
This is relatively simple. let's look at the function get_hash_symbol.
Generate the search tree. The Makefile rules are as follows:
In 'SQL/CMakeFiles/SQL. dir/build. make ':
Static SYMBOL symbols [] = {
{"&", SYM (AND_AND_SYM )},
Static uchar symbols_map [8] = {
0, 0, 1, 0, <== 1 = number of elements in the symbols [] array, indicating that no elements are found
0, 0, 0, 0, <== symbols [0]
};
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service