Database query statement parsing method, device and storage medium
By creating empty tables in the database and using the built-in parser to parse query statements, the problem of insufficient resolution coverage and accuracy of third-party parsers in the existing technology is solved, and more efficient and accurate database query statement analysis is achieved.
Patent Information
- Application Number
- CN202410897308.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-07-04
AI Technical Summary
The third-party parsers in the prior art have low coverage, low accuracy and efficiency in the analysis of database query statements, and are difficult to achieve semantic optimization.
By obtaining the query statement of the database table to be queried, creating an empty database table with the same structure, executing the query statement in the empty table, using the built-in parser of the database to parse the statement and generate a syntax tree, and finally serializing the syntax tree to output the parsing result.
It improves the resolution coverage, semantic optimization capabilities and accuracy of database query statements, and ensures the correct analysis of query statements of any syntax supported by the database, and is not restricted by database version.
Smart Images

Figure CN118760668B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer and network communication technology, and in particular to a method, device and storage medium for parsing a database query statement. Background Art
[0002] Database systems are widely used in various industries, such as MySQL databases, and database performance tuning is particularly important. In many aspects of database performance tuning (such as query statement rewriting, index recommendation, etc.), query statement parsing is an essential first step.
[0003] Generally speaking, query statement parsing includes lexical analysis, syntax analysis, semantic optimization and other steps. In the prior art, a third-party parser is usually used to parse the query statements of the database, and then the database performance is tuned based on the parsing results.
[0004] However, the third-party parser in the prior art has low parsing coverage of various grammars in the database, low parsing accuracy and efficiency, and may not be able to achieve semantic optimization. Summary of the invention
[0005] The embodiments of the present disclosure provide a method, device and storage medium for parsing database query statements to improve the parsing coverage, semantic optimization capability and accuracy of database query statements.
[0006] In a first aspect, an embodiment of the present disclosure provides a method for parsing a database query statement, comprising:
[0007] Obtaining a query statement for a database table to be queried, and creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried;
[0008] Execute the query statement in the empty database table, call the parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table;
[0009] During the execution of the query statement, the syntax tree is obtained from the parser, and a syntax tree serialization result is generated according to the syntax tree as a parsing result output of the query statement.
[0010] In a second aspect, an embodiment of the present disclosure provides a database query statement parsing device, including:
[0011] An acquisition unit, used to acquire a query statement for a database table to be queried;
[0012] A creating unit, used for creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried;
[0013] An execution unit, configured to execute the query statement in the empty database table, call a parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table;
[0014] A serialization unit is used to obtain the syntax tree from the parser during the execution of the query statement, and generate a syntax tree serialization result according to the syntax tree as a parsing result output of the query statement.
[0015] In a third aspect, an embodiment of the present disclosure provides an electronic device, including: at least one processor and a memory;
[0016] The memory stores computer-executable instructions;
[0017] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect.
[0018] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect is implemented.
[0019] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including computer execution instructions. When a processor executes the computer execution instructions, it implements the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect.
[0020] The parsing method, device and storage medium of database query statements provided by the disclosed embodiment, by obtaining a query statement for a database table to be queried, creating an empty database table corresponding to the database table to be queried, the empty database table having the same structure as the database table to be queried; executing the query statement in the empty database table, calling the built-in parser in the database to parse the query statement to obtain a syntax tree, and generating an execution plan based on the syntax tree to execute in the empty database table; obtaining the syntax tree from the parser during the execution of the query statement, and generating a syntax tree serialization result according to the syntax tree as the parsing result output of the query statement. In the disclosed embodiment, the database query statement outputs a syntax tree with the help of the built-in parser in the database, and then serializes the syntax tree to obtain a structured parsing result, which utilizes the database's own parsing ability for the query statement, and the parsing result is consistent with the database itself, which improves the efficiency and accuracy of the parsing process, and can correctly parse any query statement of syntax supported by the database, and is not limited by the database version, and has higher parsing coverage, semantic optimization ability and accuracy than third-party parsers. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0022] Figure 1a An example diagram of a detailed process of parsing a database query statement provided in an embodiment of the present disclosure;
[0023] Figure 1b An example diagram of the overall process of parsing a database query statement provided by another embodiment of the present disclosure;
[0024] Figure 2 A schematic diagram of a method for parsing a database query statement provided in an embodiment of the present disclosure;
[0025] Figure 3 It is a traversal schematic diagram of the print method in the MySQL database in the prior art;
[0026] Figure 4 A structural block diagram of a database query statement parsing device provided in an embodiment of the present disclosure;
[0027] Figure 5 A schematic diagram of the hardware structure of an electronic device provided in one embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0029] Database systems are widely used in various industries, such as MySQL databases, and are particularly important for database performance tuning. In many aspects of database performance tuning (such as query statement rewriting, index recommendation, etc.), query statement parsing is an indispensable first step. For example, the SQL query statement rewriting task will detect whether there are redundant and simplifiable conditional clauses in the query statement based on the parsing results; for another example, the index recommendation task will identify which columns and conditions are included in the where clause of the SQL statement, and which relational tables are included in the from clause based on the parsing results.
[0030] Generally speaking, query statement parsing includes lexical analysis, syntax analysis, semantic optimization and other steps. For example, the SQL statement parsing process can be as follows:
[0031] 1) Lexical parsing is the first stage of SQL parsing. Its main task is to decompose the input SQL string into a series of tokens. These tokens are usually the basic elements that make up the SQL statement, such as keywords, identifiers, operators, literals (such as numbers and strings), etc. For example, SELECT*FROM table WHERE id=123; will be decomposed into SELECT, *, FROM, table, WHERE, id, =, 123,; and other tokens;
[0032] 2) Syntax parsing is the second stage of SQL parsing. Its main task is to use the token information generated in the lexical parsing stage to build a grammatical structure, usually called an Abstract Syntax Tree (AST). Specifically, according to certain SQL grammar rules, the parser attempts to organize the token information into a structured tree structure. In this process, the parser needs to check whether the order and combination of tokens conform to the SQL grammar specification.
[0033] 3) Semantic optimization is the third stage of SQL parsing, which involves optimizing SQL query statements. This stage focuses on understanding and improving the intent and logic of the query, and is achieved by transforming the AST syntax tree. Common semantic optimizations include: simplifying conditions, determining column ownership (supplementing complete table information for columns used in queries, especially when multiple table joins are involved, clearly specifying which table each column belongs to to avoid ambiguity), adjusting join structure information (converting "multi-table join representations mixed with USING / ON / WHERE" into "multi-table join representations with unified and standardized forms", which is conducive to downstream task identification), etc.
[0034] In the prior art, a third-party parser is usually used to parse database query statements, and then the database performance is tuned based on the parsing results. However, the syntax tree structure obtained by the third-party parser for parsing database query statements should be consistent with the database's own parsing of the query statement during execution. This requires not only correct parsing of the syntax tree (including identifying the query, subquery, keyword, and parameter contained in the query statement), but also correct optimization and deformation of the syntax tree. Therefore, the challenges that the parser needs to solve include:
[0035] 1) Parsing coverage: The syntax of database query statements is very complex. For example, there are many subtle differences in the syntax of different versions of databases (called dialects). However, it is very difficult for a third-party parser to 100% cover all syntaxes. Developers need to adapt and solve the problem, which is time-consuming and costly.
[0036] 2) Semantic optimization: Semantic optimization capabilities are very important for downstream tasks. For example, determining column attribution is a prerequisite for subsequent optimization tasks, which requires the parser to be combined with the table schema to complete; for example, the MySQL database will transform, optimize, and simplify SQL statements during the logic optimization phase. Currently, most third-party parsers can implement lexical parsing and grammatical parsing, but may not have semantic optimization capabilities, or their semantic optimization capabilities are often inferior to the semantic optimization capabilities of the database itself. In addition, the optimization rules of third-party parsers may also differ from the semantic optimization rules of the database itself, resulting in inaccurate semantic optimization, affecting or even misleading subsequent index recommendations;
[0037] 3) Support for multiple database versions: Databases exist in different versions, and the differences between different versions may be very large. Currently available third-party parsers often do not support customized parsing of multiple versions.
[0038] In summary, the third-party parser in the prior art has low parsing coverage of various grammars in the database, low parsing accuracy and efficiency, and may not be able to achieve semantic optimization.
[0039] In order to solve at least one technical problem in the prior art, the present disclosure provides a method for parsing a database query statement, by obtaining a query statement for a database table to be queried, creating an empty database table corresponding to the database table to be queried, and the empty database table has the same structure as the database table to be queried; executing the query statement in the empty database table, calling the built-in parser in the database to parse the query statement to obtain a syntax tree, and generating an execution plan based on the syntax tree to execute in the empty database table; obtaining the syntax tree from the parser during the execution of the query statement, and generating a syntax tree serialization result according to the syntax tree as the parsing result output of the query statement. In the embodiment of the present disclosure, the database query statement outputs a syntax tree with the help of the built-in parser in the database, and then serializes the syntax tree to obtain a structured parsing result, which utilizes the database's own parsing ability for the query statement, and the parsing result is consistent with the database itself, which improves the efficiency and accuracy of the parsing process, and can correctly parse any query statement of syntax supported by the database, and is not limited by the database version, and has higher parsing coverage, semantic optimization ability and accuracy than third-party parsers.
[0040] like Figure 1a As shown, the parsing method of database query statements provided by the present disclosure adopts a parser built into the database, and the parsing process of the query statements mainly includes lexical parsing, grammatical parsing, semantic optimization, and query optimization process, wherein lexical parsing is to segment the query statements to obtain different types of segmentation results, grammatical parsing is to build a grammar tree based on the segmentation results, semantic optimization is to obtain an equivalent grammar tree by equivalent deformation based on the grammar tree, and query optimization is to generate an execution plan based on the equivalent grammar tree and select the optimal execution plan. The above parsing process is the capability of the parser built into the database itself, however, the parser built into the database does not output the grammar tree for display to the user after parsing the grammar tree, but directly uses it for subsequent processes. Therefore, the present disclosure transforms the parser built into the database, adds the ability to output the grammar tree to the parser built into the database, and serializes the output grammar tree to generate a grammar tree serialization result, so as to be easy to understand, improve compatibility, be more friendly to the parsing and processing of downstream tasks, and be conducive to application in different purposes.
[0041] Based on the parser built into the above database, the parsing method of the database query statement disclosed in the present invention is as follows: Figure 1bAs shown, for the query statement of the database table to be queried, an empty database table corresponding to the database table to be queried is first created, and the user can trigger and execute the statement to create the empty database table; then the query statement is executed in the empty database table, and the execution process is based on the built-in parser of the above-mentioned database for parsing and execution, and the syntax tree serialization result is output as the parsing result corresponding to the query statement. Further, the user can query the parsing result.
[0042] It should be noted that the data involved in this disclosure (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0043] The parsing method of the database query statement disclosed in the present invention will be described in detail below in conjunction with specific embodiments.
[0044] refer to Figure 2 , Figure 2 A flowchart of a method for parsing a database query statement provided in an embodiment of the present disclosure. The method of this embodiment can be applied in a terminal device or a server, and the method for parsing a database query statement includes:
[0045] S201: Obtain a query statement for a database table to be queried, and create an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried.
[0046] In this embodiment, when it is necessary to parse one or more query statements of the database, a query statement can be obtained first. The query statement is a query statement for the database table to be queried, where the database table to be queried can be a library table in any type of database, for example, it can be a MySQL database, and the corresponding query statement is an SQL statement.
[0047] In this embodiment, a corresponding empty database table can be created for the database table to be queried. The empty database table has the same structure as the database table to be queried, including the same number of columns and the same column names, but the number of rows does not need to be paid attention to. No data is required in the empty database table. The empty database table is used to execute the query statement in the following S202. In this embodiment, the query statement is not executed based on the database table to be queried, but is executed based on the empty database table. Considering that there may be a large amount of data in the database table to be queried, it takes a long time to execute the query statement, and it may also be unsafe and there are certain risks. When executing the query statement in the empty database table, although the returned result is empty, the execution process is the same, and it takes a short time and has high security.
[0048] S202: Execute the query statement in the empty database table, call a parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table.
[0049] In this embodiment, a query statement is executed in an empty database table. During the execution process, the query statement is parsed by a built-in parser of the database to obtain an abstract syntax tree (AST), which can also be called a syntax tree. An execution plan is generated based on the syntax tree, and the generated execution plan is executed in the empty database table. The built-in parser of the database is the parser that comes with the database, not a third-party parser. For example, for a MySQL database, the SQL parser of the MySQL database is used to parse the query statement. The parsing process in this embodiment is the same as the conventional parsing process, which can include lexical parsing, grammatical parsing, semantic optimization, etc. of the query statement. After grammatical parsing, a syntax tree can be obtained, and semantic optimization is to optimize the syntax tree obtained after grammatical parsing to obtain an equivalent syntax tree. The semantic optimization capability is the data processing capability of the database itself, and the optimization rules fully use the optimization rules of the database itself, including but not limited to: library table information completion, query condition simplification, connection structure optimization, etc.
[0050] S203: Acquire the syntax tree from the parser during the execution of the query statement, and generate a syntax tree serialization result according to the syntax tree as a parsing result output of the query statement.
[0051] In this embodiment, the parser built into the database usually does not output the syntax tree corresponding to the query statement, but directly generates an execution plan based on the syntax tree and executes it. In this embodiment, in order to obtain the syntax tree corresponding to the query statement, the parser built into the database can be modified to a certain extent so that the parser built into the database can output the syntax tree corresponding to the query statement. For example, a preset embedding point is deployed in the parser built into the database (that is, the program code for collecting the syntax tree is attached at a specific location in the program code of the parser built into the database), and the syntax tree is obtained after the parser built into the database parses the query statement to obtain the syntax tree. Of course, other methods can also be used to implement it, which is easier to implement for some open source databases.
[0052] Optionally, since a syntax tree can be obtained after syntax parsing during the parsing process, and an equivalent syntax tree can be obtained after semantic optimization, a first preset embedding point can be deployed at the syntax parsing process in the parser built into the database (that is, the program code for collecting syntax trees is attached after the program code for the syntax parsing function in the parser built into the database), and the first syntax tree obtained by the parser performing syntax parsing on the query statement can be obtained based on the first preset embedding point; and / or, a second preset embedding point can also be deployed at the semantic optimization process in the parser built into the database (that is, the program code for collecting syntax trees is attached after the program code for the semantic optimization function in the parser built into the database), and the second syntax tree obtained by the parser performing semantic optimization on the query statement can be obtained based on the second preset embedding point. Among them, the difference between syntax trees at different stages lies in whether they are optimized, such as constant passing, equivalent value passing, removal of useless conditions, etc.
[0053] Furthermore, after obtaining the syntax tree corresponding to the query statement, the syntax tree corresponding to the query statement can be serialized to generate a syntax tree serialization result, and the syntax tree serialization result is in the form of a string, that is, the serialization process is to represent the syntax tree in the form of a string.
[0054] Optionally, the syntax tree corresponding to the query statement can be represented as a JSON format string. The JSON format string is platform-independent, has a flexible data structure, is easy to understand, and is convenient for data exchange. It can provide good compatibility in various platforms and programming languages. It not only supports complex lists and attribute structures, but also greatly simplifies the serialization and deserialization process. It is more friendly to the parsing and processing of downstream tasks, and is conducive to application in different purposes.
[0055] Furthermore, in this embodiment, the syntax tree serialization result obtained above is used as the parsing result corresponding to the query statement, and is output to facilitate the subsequent use of the parsing result corresponding to the query statement.
[0056] In an optional embodiment, the syntax tree serialization result can be saved as a file, and the access path of the file can be obtained, and the user can download the file through remote access. Downloading files through remote access is relatively simple, but it requires database login permissions and file copy permissions, but there are certain risks in the process of copying files.
[0057] In another optional embodiment, the syntax tree serialization result can be stored in the optimizer tracking table corresponding to the query statement, wherein the optimizer tracking table is a system table of the database, which is intended to generate human- and program-readable output, and can help understand the decisions and operations taken by the optimizer. For example, for a MySQL database, the optimizer tracking table is also the OPTIMIZER_TRACE table, which can help understand the decisions and operations taken by the MySQL optimizer. Therefore, storing the syntax tree serialization result in the optimizer tracking table can be convenient for users to view and eliminates the traditional additional file storage and transmission requirements. Optionally, the syntax tree serialization result can be stored in the trace information of the optimizer tracking table corresponding to the query statement, and of course, it can also be stored in any other location of the optimizer tracking table.
[0058] In specific implementation, since each query statement will generate an optimizer tracking table, which contains detailed information on the decisions and operations made by the query statement during query processing, the optimizer tracking table corresponding to the subsequent query statement will usually overwrite the optimizer tracking table corresponding to the current query statement. Therefore, the optimizer tracking table corresponding to the current query statement can be queried before the optimizer tracking table is generated for the subsequent query statement.
[0059] When querying, the optimizer trace table corresponding to the query statement can be displayed in response to a viewing instruction for the optimizer trace table (such as the show_trace instruction, which is also a standard query statement); then the syntax tree serialization result can be obtained from the optimizer trace table corresponding to the query statement and output. In this embodiment, the user can access the parsing result through a standard query statement, which enhances practicality and operability.
[0060] Optionally, when storing the syntax tree serialization result in the optimizer tracking table corresponding to the query statement, it can be stored in a key-value pair, wherein the key in the key-value pair is the identification information of the syntax tree serialization result, which is used to identify the syntax tree serialization result, or to distinguish the syntax tree serialization results corresponding to the first syntax tree and the second syntax tree at different stages, and the value in the key-value pair is the syntax tree serialization result. The syntax tree serialization results at different stages can be used to reflect the database logic optimization characteristics. Furthermore, when querying, the syntax tree serialization result can be obtained from the optimizer tracking table corresponding to the query statement based on the key, and output as the parsing result corresponding to the query statement.
[0061] Of course, in this embodiment, the syntax tree serialization result can also be stored in other system tables of the database, which are not listed one by one here.
[0062] Furthermore, the parsing results corresponding to the query statement can be used for different purposes. For example, the database table to be queried can be optimized. In one optimization, an index recommendation can be made for the database table, that is, the columns to be queried can be determined based on the parsing results, and indexes can be created for the queried columns. Subsequently, queries can be performed based on the indexes to speed up the query. Another example is to optimize the query statement based on the parsing results. Of course, other optimizations can also be performed based on the parsing results, which are not listed here one by one.
[0063] The parsing method of database query statements provided in this embodiment, by obtaining a query statement for a database table to be queried, creating an empty database table corresponding to the database table to be queried, the empty database table having the same structure as the database table to be queried; executing the query statement in the empty database table, calling the built-in parser in the database to parse the query statement to obtain a syntax tree, and generating an execution plan based on the syntax tree to execute in the empty database table; obtaining the syntax tree from the parser during the execution of the query statement, and generating a syntax tree serialization result based on the syntax tree as the parsing result output of the query statement. In this embodiment, the database query statement outputs a syntax tree with the help of the built-in parser in the database, and then serializes the syntax tree to obtain a structured parsing result, which utilizes the database's own parsing ability for query statements, and the parsing result is consistent with the database itself, which improves the efficiency and accuracy of the parsing process, and can correctly parse any query statement of syntax supported by the database, and is not limited by the database version. Compared with third-party parsers, it has higher parsing coverage, semantic optimization capabilities and accuracy.
[0064] Based on any of the above embodiments, when generating a syntax tree serialization result according to the syntax tree in S203, the following steps may be specifically included:
[0065] S2031, traversing the nodes in the syntax tree, generating a corresponding structure of a preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, wherein the structure of the preset data structure includes the node type, attribute information, and child node information;
[0066] S2032: Convert the tree structure into a character string to obtain the syntax tree serialization result.
[0067] In this embodiment, a structure of a preset data structure is designed to record relevant information of nodes in a syntax tree, wherein the structure of the preset data structure includes but is not limited to node type, attribute information, and child node information.
[0068] Optionally, the structure of the preset data structure may be a JSONItem class object, which has three fields:
[0069] item_type: type, describing the type of the current object (node) in the database;
[0070] properties: a key-value pair consisting of strings, where the key is the property identifier (such as name) and the value is the specific property information of the current object. It describes the property information of the current object and is the property information of interest during the parsing process, such as the name, full name, column name, column type, memory address, database, table, etc. of the current object;
[0071] data: a list of JSONItem, describing the sub-object information contained in the current object.
[0072] JSONItem can compatibly represent various types of objects in the syntax tree and depict the hierarchical relationship between objects.
[0073] In addition, JSONItem also provides three methods:
[0074] create_data: The input is a type value, which adds a sub-object to the data of the current object and returns the memory address pointing to the sub-object.
[0075] add_properties: The input is a key and value in string form, which adds the properties of interest to the properties of the current object.
[0076] to_json: Convert the current object into a JSON string representation for subsequent storage.
[0077] The create_data method and add_properties method can be used to create JSONItem class objects; the to_json method can be used to convert the current object into a JSON string representation.
[0078] In this embodiment, each node in the syntax tree can be represented as a structure of a corresponding preset data structure, and the hierarchical structure of the syntax tree is still retained between the structures, that is, a tree structure based on the structure corresponding to the syntax tree is formed, and the tree structure is easier to understand than the syntax tree, and can be conveniently serialized into a string. The serialization result is also easier to understand and has good compatibility, which is conducive to application in different purposes.
[0079] In a specific implementation, when traversing the nodes in the syntax tree at S2031, generating a structure of a corresponding preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, the method may specifically include:
[0080] Traverse the nodes in the syntax tree, call the preset function in turn to extract the corresponding node type, attribute information and child node information for each node, and add the node type, attribute information and child node information corresponding to each node to a preset data structure to generate a structure of the corresponding preset data structure.
[0081] In this embodiment, each level of the syntax tree can be traversed in sequence, and the node type, attribute information, and child node information of each node can be extracted during the traversal process, added to a preset data structure, and a corresponding data structure can be generated. In the process of traversing, extracting node information, and generating a data structure, the mechanism of the print method in the MySQL database can be referred to for implementation.
[0082] For reference, there is an execution process in the MySQL database that splices the syntax tree into an SQL statement string (hereinafter referred to as MySQL_AST_to_SQL). This process traverses all nodes in the syntax tree that appear in the SQL statement and converts the key information related to the node into a string. The principle is that the MySQL database itself provides print methods for various syntax tree node types. In the print method, the print method of the child node can be further called to complete the output of the content of the node. Figure 3 Indicates that in different types of SQL statements, the child nodes are also different. After calling the outer print method, the print methods of the respective child nodes will be called in turn. Take the print method of the most common SELECT statement as an example. After calling print_query_block(), the print methods of the child nodes such as print_hints(), print_select_options(), and print_item_list() will be called in turn. In the child node print_where_cond() method, the print method of each condition ITEM will be further called, and so on, until the node of the underlying type is traversed, such as ITEM type or TableRef type. The print methods for UPDATE statements, DELETE statements, INSERT statements, or REPLACE statements are similar to those for SELECT statements, and will not be repeated here.
[0083] Based on the mechanism of the print method in the MySQL database, the print method is reused in this embodiment to traverse the syntax tree logic, and the print method of the child node is replaced by a method for generating a structure of the corresponding preset data structure. For example, a preset function can be defined as a to_json_xxx() method. Taking the SELECT statement in the above example as an example, after calling to_json_query_block(), to_json_hints(), to_json_select_options(), to_json_item_list() and other child nodes' to_json methods are called in sequence. In the child node to_json_where_cond() method, the to_json method of each condition ITEM is further called. In each to_json_xxx() method, the node type, attribute information and child node information of the corresponding node can be extracted, and added to a preset data structure (for example, through the create_data method and add_properties method in the above example), and the structure of the corresponding preset data structure is generated. That is, each to_json_xxx() method can return the structure of the preset data structure of the corresponding node, such as the above-mentioned JSONItem class object, and finally a tree structure based on the structure is constructed.
[0084] This embodiment accurately replicates the hierarchical structure of the syntax tree through a tree structure based on a structure, and is easier to understand; and in addition to the information used in the query statement, the attribute structure based on the structure can also extract more additional but useful hidden information, such as JOIN (connection) type, column attribution information, UNION (merge) type, etc.; compared with the complexity of attributes and functions in the syntax tree, the syntax tree is represented by a tree structure based on a structure in this implementation, which can be easier to understand, and can also improve parsing efficiency and ensure the correctness and completeness of the parsing results.
[0085] Furthermore, the tree structure is converted into a string to obtain a syntax tree serialization result, wherein optionally, the structure in the entire tree structure can be converted into a JSON string through the to_json() method of the outermost root node.
[0086] On the basis of any of the above embodiments, when the syntax tree serialization result is stored in the optimizer tracking table corresponding to the query statement, the function of recording the optimizer tracking table can be enabled before executing the query statement in the empty database table, and then an optimizer tracking table can be generated when the query statement is executed. Subsequently, the syntax tree serialization result corresponding to the query statement can be stored in the optimizer tracking table corresponding to the query statement.
[0087] In addition, if there are multiple query statements, since the optimizer tracking table corresponding to the previous query statement will be overwritten by the optimizer tracking table corresponding to the next query statement, after each query statement is executed, the syntax tree serialization result corresponding to the query statement is obtained from the optimizer tracking table corresponding to the query statement and output, and it is determined whether there are other query statements to be executed. If there are other query statements to be executed, the next query statement is executed. If there are no other query statements to be executed, the above process can be terminated. Optionally, if there are no other query statements to be executed, the function of recording the optimizer tracking table can also be turned off.
[0088] On the basis of any of the above embodiments, although the parsing of the query statement is performed by the parser built into the utilization database, since the parser built into the database does not have the ability to output the syntax tree, the above embodiments actually modify the parser built into the database, and add the ability to output the syntax tree to the parser built into the database. In addition, the ability to generate the syntax tree serialization result according to the syntax tree, and the ability to store and output the syntax tree serialization result are added. Therefore, a preset database instance can be created, and the above capabilities can be embedded in the preset database instance, that is, by integrating the logic of outputting the syntax tree, the logic of serializing the syntax tree, and the logic of outputting the parsing result in the above embodiments. The logic such as compilation is integrated into the database source code and recompiled into a highly customized database image (that is, a preset database instance). Furthermore, when creating an empty database table corresponding to the database table to be queried, an empty database table corresponding to the database table to be queried can be created in the preset database instance, and then the query statement is executed in the empty database table of the preset database instance, and the syntax tree is obtained from the parser in the preset database instance, and the syntax tree serialization result is generated and output, wherein the preset database instance and the database instance where the database table to be queried is located are different database instances, that is, it will not affect the normal operation of the original database table to be queried, nor will it affect the security of the original table.
[0089] Corresponding to the parsing method of the database query statement in the above embodiment, Figure 4 A structural block diagram of a database query statement parsing device provided in an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Figure 4 The database query statement parsing device 400 includes: an acquisition unit 401, a creation unit 402, an execution unit 403, and a serialization unit 404.
[0090] The acquisition unit 401 is used to acquire a query statement for the database table to be queried;
[0091] A creating unit 402 is used to create an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried;
[0092] An execution unit 403 is used to execute the query statement in the empty database table, call a parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table;
[0093] The serialization unit 404 is used to obtain the syntax tree from the parser during the execution of the query statement, and generate a syntax tree serialization result according to the syntax tree as the parsing result output of the query statement.
[0094] In one or more embodiments of the present disclosure, when the execution unit 403 obtains the syntax tree from the parser during the execution of the query statement, it is used to:
[0095] Based on preset embedding points in the parser, the syntax tree is obtained after the parser parses the query statement to obtain the syntax tree.
[0096] In one or more embodiments of the present disclosure, the execution unit 403, when acquiring the syntax tree after the parser parses the query statement to obtain the syntax tree based on the preset embedding point in the parser, is used to:
[0097] Based on a first preset embedding point in the parser, obtaining a first syntax tree obtained by the parser performing syntax parsing on the query statement; and / or
[0098] Based on a second preset embedding point in the parser, a second syntax tree obtained by the parser performing semantic optimization on the first syntax tree is obtained.
[0099] In one or more embodiments of the present disclosure, when the serialization unit 404 generates a syntax tree serialization result according to the syntax tree, it is used to:
[0100] Traversing the nodes in the syntax tree, generating a corresponding structure of a preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, wherein the structure of the preset data structure includes the node type, attribute information, and child node information;
[0101] The tree structure is converted into a character string to obtain the syntax tree serialization result.
[0102] In one or more embodiments of the present disclosure, when the serialization unit 404 traverses the nodes in the syntax tree and sequentially generates a structure of a corresponding preset data structure for each node to obtain a tree structure based on the structure corresponding to the syntax tree, it is used to:
[0103] Traverse the nodes in the syntax tree, call the preset function in turn to extract the corresponding node type, attribute information and child node information for each node, and add the node type, attribute information and child node information corresponding to each node to a preset data structure to generate a structure of the corresponding preset data structure.
[0104] In one or more embodiments of the present disclosure, when the serialization unit 404 generates a syntax tree serialization result according to the syntax tree and outputs it as a parsing result of the query statement, it is used to:
[0105] After generating the syntax tree serialization result, storing the syntax tree serialization result in the optimizer tracking table corresponding to the query statement;
[0106] In response to an instruction to view the optimizer tracking table, displaying the optimizer tracking table corresponding to the query statement;
[0107] The syntax tree serialization result is obtained from the optimizer tracking table corresponding to the query statement and outputted.
[0108] In one or more embodiments of the present disclosure, the execution unit 403 is further configured to:
[0109] Before executing the query statement in the empty database table, a function of recording the optimizer tracking table is enabled.
[0110] In one or more embodiments of the present disclosure, when creating an empty database table corresponding to the database table to be queried, the creating unit 402 is used to:
[0111] An empty database table corresponding to the database table to be queried is created in a preset database instance, wherein the preset database instance and the database instance where the database table to be queried is located are different database instances.
[0112] The device provided in this embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0113] refer to Figure 5, which shows a schematic diagram of the structure of an electronic device 500 suitable for implementing the embodiment of the present disclosure, and the electronic device 500 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0114] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. Various programs and data required for the operation of the electronic device 500 are also stored in the RAM 503. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0115] Typically, the following devices may be connected to the I / O interface 505: input devices 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 509. The communication devices 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0116] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0117] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0118] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0119] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0120] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0121] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0122] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".
[0123] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0124] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0125] In a first aspect, according to one or more embodiments of the present disclosure, a method for parsing a database query statement is provided, comprising:
[0126] Obtaining a query statement for a database table to be queried, and creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried;
[0127] Execute the query statement in the empty database table, call the parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table;
[0128] During the execution of the query statement, the syntax tree is obtained from the parser, and a syntax tree serialization result is generated according to the syntax tree as a parsing result output of the query statement.
[0129] According to one or more embodiments of the present disclosure, obtaining the syntax tree from the parser during the execution of the query statement includes:
[0130] Based on preset embedding points in the parser, the syntax tree is obtained after the parser parses the query statement to obtain the syntax tree.
[0131] According to one or more embodiments of the present disclosure, the step of obtaining the syntax tree after the parser parses the query statement to obtain the syntax tree based on the preset embedding point in the parser includes:
[0132] Based on a first preset embedding point in the parser, obtaining a first syntax tree obtained by the parser performing syntax parsing on the query statement; and / or
[0133] Based on a second preset embedding point in the parser, a second syntax tree obtained by the parser performing semantic optimization on the first syntax tree is obtained.
[0134] According to one or more embodiments of the present disclosure, generating a syntax tree serialization result according to the syntax tree includes:
[0135] Traversing the nodes in the syntax tree, generating a corresponding structure of a preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, wherein the structure of the preset data structure includes the node type, attribute information, and child node information;
[0136] The tree structure is converted into a character string to obtain the syntax tree serialization result.
[0137] According to one or more embodiments of the present disclosure, traversing the nodes in the syntax tree, sequentially generating a structure of a corresponding preset data structure for each node, and obtaining a tree structure based on the structure corresponding to the syntax tree, includes:
[0138] Traverse the nodes in the syntax tree, call the preset function in turn to extract the corresponding node type, attribute information and child node information for each node, and add the node type, attribute information and child node information corresponding to each node to a preset data structure to generate a structure of the corresponding preset data structure.
[0139] According to one or more embodiments of the present disclosure, generating a syntax tree serialization result according to the syntax tree as the parsing result output of the query statement includes:
[0140] After generating the syntax tree serialization result, storing the syntax tree serialization result in the optimizer tracking table corresponding to the query statement;
[0141] In response to an instruction to view the optimizer tracking table, displaying the optimizer tracking table corresponding to the query statement;
[0142] The syntax tree serialization result is obtained from the optimizer tracking table corresponding to the query statement and outputted.
[0143] According to one or more embodiments of the present disclosure, the method further includes:
[0144] Before executing the query statement in the empty database table, a function of recording the optimizer tracking table is enabled.
[0145] According to one or more embodiments of the present disclosure, the step of creating an empty database table corresponding to the database table to be queried includes:
[0146] An empty database table corresponding to the database table to be queried is created in a preset database instance, wherein the preset database instance and the database instance where the database table to be queried is located are different database instances.
[0147] In a second aspect, according to one or more embodiments of the present disclosure, a database query statement parsing device is provided, comprising:
[0148] An acquisition unit, used to acquire a query statement for a database table to be queried;
[0149] A creating unit, used for creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried;
[0150] An execution unit, configured to execute the query statement in the empty database table, call a parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table;
[0151] A serialization unit is used to obtain the syntax tree from the parser during the execution of the query statement, and generate a syntax tree serialization result according to the syntax tree as a parsing result output of the query statement.
[0152] According to one or more embodiments of the present disclosure, when the execution unit obtains the syntax tree from the parser during the execution of the query statement, it is used to:
[0153] Based on preset embedding points in the parser, the syntax tree is obtained after the parser parses the query statement to obtain the syntax tree.
[0154] According to one or more embodiments of the present disclosure, the execution unit, based on a preset embedding point in the parser, when acquiring the syntax tree after the parser parses the query statement to obtain the syntax tree, is used to:
[0155] Based on a first preset embedding point in the parser, obtaining a first syntax tree obtained by the parser performing syntax parsing on the query statement; and / or
[0156] Based on a second preset embedding point in the parser, a second syntax tree obtained by the parser performing semantic optimization on the first syntax tree is obtained.
[0157] According to one or more embodiments of the present disclosure, when the serialization unit generates a syntax tree serialization result according to the syntax tree, it is used to:
[0158] Traversing the nodes in the syntax tree, generating a corresponding structure of a preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, wherein the structure of the preset data structure includes the node type, attribute information, and child node information;
[0159] The tree structure is converted into a character string to obtain the syntax tree serialization result.
[0160] According to one or more embodiments of the present disclosure, when the serialization unit traverses the nodes in the syntax tree, generates a structure of a corresponding preset data structure for each node in turn, and obtains a tree structure based on the structure corresponding to the syntax tree, it is used to:
[0161] Traverse the nodes in the syntax tree, call the preset function in turn to extract the corresponding node type, attribute information and child node information for each node, and add the node type, attribute information and child node information corresponding to each node to a preset data structure to generate a structure of the corresponding preset data structure.
[0162] According to one or more embodiments of the present disclosure, when the serialization unit generates a syntax tree serialization result according to the syntax tree and outputs it as a parsing result of the query statement, it is used to:
[0163] After generating the syntax tree serialization result, storing the syntax tree serialization result in the optimizer tracking table corresponding to the query statement;
[0164] In response to an instruction to view the optimizer tracking table, displaying the optimizer tracking table corresponding to the query statement;
[0165] The syntax tree serialization result is obtained from the optimizer tracking table corresponding to the query statement and outputted.
[0166] According to one or more embodiments of the present disclosure, the execution unit is further configured to:
[0167] Before executing the query statement in the empty database table, a function of recording the optimizer tracking table is enabled.
[0168] According to one or more embodiments of the present disclosure, when creating an empty database table corresponding to the database table to be queried, the creation unit is used to:
[0169] An empty database table corresponding to the database table to be queried is created in a preset database instance, wherein the preset database instance and the database instance where the database table to be queried is located are different database instances.
[0170] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, comprising: at least one processor and a memory;
[0171] The memory stores computer-executable instructions;
[0172] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect.
[0173] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect is implemented.
[0174] In a fifth aspect, according to one or more embodiments of the present disclosure, a computer program product is provided, comprising computer execution instructions. When a processor executes the computer execution instructions, the method for parsing database query statements as described in the first aspect and various possible designs of the first aspect is implemented.
[0175] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0176] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0177] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for parsing a database query statement, characterized in that: include: Obtaining a query statement for a database table to be queried, and creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried; Execute the query statement in the empty database table, call the parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table; During the execution of the query statement, the syntax tree is obtained from the parser, and a syntax tree serialization result is generated according to the syntax tree as a parsing result output of the query statement.
2. The method according to claim 1, characterized in that The obtaining the syntax tree from the parser during the execution of the query statement includes: Based on preset embedding points in the parser, the syntax tree is obtained after the parser parses the query statement to obtain the syntax tree.
3. The method according to claim 2, characterized in that The method of obtaining the syntax tree based on the preset embedding point in the parser after the parser parses the query statement to obtain the syntax tree includes: Based on a first preset embedding point in the parser, obtaining a first syntax tree obtained by the parser performing syntax parsing on the query statement; and / or Based on a second preset embedding point in the parser, a second syntax tree obtained by the parser performing semantic optimization on the first syntax tree is obtained.
4. The method according to claim 1, characterized in that The generating a syntax tree serialization result according to the syntax tree includes: Traversing the nodes in the syntax tree, generating a corresponding structure of a preset data structure for each node in turn, and obtaining a tree structure based on the structure corresponding to the syntax tree, wherein the structure of the preset data structure includes the node type, attribute information, and child node information; The tree structure is converted into a character string to obtain the syntax tree serialization result.
5. The method according to claim 4, characterized in that The traversing of the nodes in the syntax tree, sequentially generating a structure of a corresponding preset data structure for each node, and obtaining a tree structure based on the structure corresponding to the syntax tree, includes: Traverse the nodes in the syntax tree, call the preset function in turn to extract the corresponding node type, attribute information and child node information for each node, and add the node type, attribute information and child node information corresponding to each node to a preset data structure to generate a structure of the corresponding preset data structure.
6. The method according to any one of claims 1 to 5, characterized in that: Generating a syntax tree serialization result according to the syntax tree as the parsing result output of the query statement includes: After generating the syntax tree serialization result, storing the syntax tree serialization result in the optimizer tracking table corresponding to the query statement; In response to an instruction to view the optimizer tracking table, displaying the optimizer tracking table corresponding to the query statement; The syntax tree serialization result is obtained from the optimizer tracking table corresponding to the query statement and outputted.
7. The method according to any one of claims 1 to 5, characterized in that: The step of creating an empty database table corresponding to the database table to be queried includes: An empty database table corresponding to the database table to be queried is created in a preset database instance, wherein the preset database instance and the database instance where the database table to be queried is located are different database instances.
8. A database query statement parsing device, characterized in that: include: An acquisition unit, used to acquire a query statement for a database table to be queried; A creating unit, used for creating an empty database table corresponding to the database table to be queried, wherein the empty database table has the same structure as the database table to be queried; An execution unit, configured to execute the query statement in the empty database table, call a parser built in the database to parse the query statement to obtain a syntax tree, and generate an execution plan based on the syntax tree to execute in the empty database table; A serialization unit is used to obtain the syntax tree from the parser during the execution of the query statement, and generate a syntax tree serialization result according to the syntax tree as a parsing result output of the query statement.
9. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, characterized in that The method comprises computer-executable instructions, and when a processor executes the computer-executable instructions, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
File serialization method of model library of physical modeling language Modelica
CN102043657A
Data processing method and device based on database engine, terminal and medium
CN111522816A