Database statement processing method and device, equipment, medium and product
By analyzing statements in the database system to generate a syntax tree and constructing auxiliary parsing nodes, the problem of inaccurate parameter type determination under multiple parameter types is solved, and more accurate constant and bound parameter type conversion is achieved, improving the accuracy and efficiency of database processing.
Patent Information
- Application Number
- CN202510346436.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-11
AI Technical Summary
In the database system, when there are multiple parameter types, the prior art cannot accurately determine the parameter types of constants and bound parameters, which affects the subsequent processing of statements.
Generate a syntax tree by parsing statements, and construct an auxiliary parsing node for each expression node. It traverses the syntax tree to convert the parameter type of the target expression node, and uses the parent node information of the auxiliary parsing node to determine the namespace pattern and data type mapping to achieve accurate conversion of parameter types.
在处理多种参数类型的数据时,能够更为准确地确定常量和绑定参数的参数类型,避免显式强制类型转换,提高了数据库处理的准确性和效率。
Smart Images

Figure CN120296027A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular, to a method, device, equipment, medium and product for processing statements of a database. Background Art
[0002] In a database system, corresponding parameter types are defined for different data in the statements processed by the database, such as numeric type, character type, time and date type, etc. Some statements also include data such as externally input constants and bound parameters. Since these data have data types related to external devices, the database also needs to convert the parameter types of these data in the statement into specific types that the database can process before performing subsequent calculations.
[0003] In the prior art, some databases can be used to process data of multiple different parameter types. In this case, due to the existence of multiple different parameter types, the database cannot determine that the parameter type of the externally input data needs to be converted into a certain specific type, thus affecting the subsequent processing of the statement.
[0004] Therefore, in the case where a database can be used to process data of at least two different parameter types, how to more accurately determine the parameter types of constants and bound parameters in the currently processed statement is a technical problem to be solved in this field. Summary of the Invention
[0005] This application provides a method, device, equipment, medium and product for processing statements of a database, which can more accurately determine the parameter types of constants and bound parameters in the currently processed statement in the case where a database can be used to process data of at least two parameter types.
[0006] In the first aspect of this application, a method for processing statements of a database is provided. The database supports processing data of at least two different parameter types. The method includes: parsing a statement to be processed to obtain a syntax tree of the statement; constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; traversing each expression node of the syntax tree, and for a target expression node in the syntax tree that meets a preset condition, converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node to obtain a query tree of the statement.
[0007] In an embodiment of the first aspect of this application, the auxiliary parsing node includes: a first pointer of the current auxiliary parsing node, a second pointer of the parent node of the current auxiliary parsing node, the parameter type of the current auxiliary parsing node, and indication information of the parameter type confirmation method of the current auxiliary parsing node; wherein, the second pointer of each auxiliary parsing node points to the parent node of the auxiliary parsing node, forming a linked list of auxiliary parsing nodes.
[0008] In an embodiment of the first aspect of the present application, the target expression node is an expression node with a parameter type of constant; the conversion of the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: determining the parameter type of the parent node of the auxiliary parsing node of the target expression node from the linked list of auxiliary parsing nodes; determining the namespace pattern corresponding to the target expression node according to the parameter type of the parent node of the auxiliary parsing node; and converting the parameter type of the target expression node into the parameter type corresponding to the constant in the namespace pattern.
[0009] In an embodiment of the first aspect of the present application, the target expression node is an expression node with a parameter type of bound parameter; the conversion of the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: determining the parameter type of the parent node of the auxiliary parsing node of the target expression node from the linked list of auxiliary parsing nodes; determining the namespace pattern corresponding to the target expression node according to the parameter type of the parent node of the auxiliary parsing node; determining the parameter type corresponding to the namespace pattern according to the namespace pattern and the data type mapping table; mapping the bound parameter in the target expression node to the parameter type corresponding to the namespace pattern; adding a type conversion node to the syntax tree, setting the parent node of the type conversion node to the parent node of the target expression node, and converting the parent node of the target expression node into the type conversion node, where the type conversion node is used to perform parameter type conversion between the parent node of the target expression node and the bound parameter of the target expression node.
[0010] In an embodiment of the first aspect of the present application, the conversion of the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: when the parameter type confirmation method indication information of the auxiliary parsing node of the target expression node is the first preset value, converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node; when the parameter type confirmation method indication information of the auxiliary parsing node of the target expression node is the second preset value, converting the parameter type of the target expression node according to the specified parameter type of the target expression node.
[0011] In an embodiment of the first aspect of the present application, when traversing each expression node of the syntax tree, it further includes: when traversing each expression node, replacing the auxiliary parsing node pointer in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node; after processing the current expression node, restoring the auxiliary parsing node pointer in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node.
[0012] The second aspect of the present application provides a statement processing device for a database, including: a parsing module for parsing a statement to be processed to obtain the syntax tree of the statement; a construction module for constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; a conversion module for traversing each expression node of the syntax tree, and for a target expression node in the syntax tree that meets a preset condition, converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node to obtain the query tree of the statement.
[0013] The third aspect of the present application provides an electronic device, including: a memory and a processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to execute the method according to any one of the first aspect of the present application.
[0014] The fourth aspect of the present application provides a computer-readable storage medium storing computer-executable instructions, and when the computer-executable instructions are executed, the method according to any one of the first aspect of the present application is implemented.
[0015] The fifth aspect of the present application provides a computer program product including a computer program, and when the computer program is executed, the method according to any one of the first aspect of the present application is implemented.
[0016] In summary, for the statement processing method, device, equipment, medium and product provided by the present application, when processing a statement, the database can parse the statement to be processed to obtain the syntax tree, and construct an auxiliary parsing node for each expression node, so that by traversing the syntax tree, the parameter type of the target expression node that meets the preset condition is converted according to the parameter type of the parent node of the corresponding auxiliary node, and thus when the database can be used to process data of at least two parameter types, the parameter types of constants and bound parameters in the currently processed statement can be determined more accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0018] Figure 1 Schematic flowchart of an embodiment of the statement processing method for the database provided by the present application;
[0019] Figure 2 Schematic diagram of an embodiment of the syntax tree of the statement provided by the present application;
[0020] Figure 3 Schematic diagram of the auxiliary parsing node corresponding to the expression node in the syntax tree provided by the present application;
[0021] Figure 4 Schematic diagram of a specific implementation manner of the auxiliary parsing node provided by the present application;
[0022] Figure 5 Schematic diagram of an embodiment of the query tree of the statement provided by the present application;
[0023] Figure 6 Schematic flowchart of an embodiment of the statement processing method for the database provided by the present application;
[0024] Figure 7 Schematic flowchart of an embodiment of the statement processing method for the database provided by the present application;
[0025] Figure 8 Schematic flowchart of an embodiment of the statement processing method for the database provided by the present application;
[0026] Figure 9 Schematic flowchart of an embodiment of the statement processing method for the database provided by the present application;
[0027] Figure 10 Schematic diagram of the structure of a statement processing device for a database provided by the present application;
[0028] Figure 11 Schematic diagram of the structure of an electronic device provided by the present application. Detailed implementation manners
[0029] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0030] The terms "first", "second", "third", "fourth", etc. (if any) in the specification, claims and the above-mentioned accompanying drawings of the present application are used to distinguish similar objects and do not necessarily describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily limit to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0031] Before formally introducing the embodiments of the present application, some technical terms involved will be explained first.
[0032] Single-type database system: In this type of database system, there is only one set of data type definitions, and there are no different data types with the same name in such a system.
[0033] Dual-type database system: In this type of database system, there are two sets of data type definitions, and a schema (namespace) is used to isolate between the two sets of data types. Since there are different data types with the same name in the two sets of data types, implicit type conversion rules are usually not allowed between different sets of data types, that is, no implicit type conversion in any direction is supported.
[0034] Multi-type database system: On the basis of a dual-type database system, one or more additional sets of type definitions are added, and the type isolation method and the conversion rules between different sets of types are similar to those of the dual-type database system.
[0035] Constant: Also known as literal, it is a general term for quantities that include numbers, ordinary strings, or formatted strings and do not change during the execution of SQL.
[0036] Expression: It is a meaningful permutation and combination composed of elements such as numbers, operators, parentheses, free variables, and bound variables for calculating numerical values.
[0037] This application is specifically applied in a database system. For different data in the statements processed by the database, corresponding parameter types are defined, such as numeric type, character type, time and date type, etc. For example, in a relational database system, the Structured Query Language (SQL for short) can define a set of data type systems.
[0038] In SQL language, the data directly input from the outside is usually represented in the form of constants or bound parameters. Constants and bound parameters can be used as expression parameters. During the semantic analysis process, the constants and bound parameters are converted into specific data types according to the context for subsequent expression calculations.
[0039] In the prior art, when the database processes statements, different methods are used to infer the data types of constants of different types in the statements. For example, constants usually include at least numeric constants and string constants. For numeric constants, since the target data type is usually clear, the database can infer whether it is an integer or a floating point number according to the input form of the constant; for string constants, since the target data type is usually not clear, there are two common target data types: one is the unknown intermediate type (unknown), and constants of this type can be used as input data for any data type; the other is the variable-length string type (varchar), and constants of this type need to be converted into other data types depending on the type conversion rules. In a single type system, the constant target type will only choose one of the two.
[0040] At the same time, in some technologies, in order to cope with complex actual requirements, application programs use a large amount of dynamic SQL. They dynamically bind different data to SQL statements through the client programming interface of the database (such as the JDBC driver), and the database server identifies the bound parameters through placeholders. Generally speaking, the application program calls different interface methods to bind data and specifies the parameter type. When the application program does not specify a specific parameter type for the bound data, the database server can infer the bound parameter as a specific type according to the expression context for expression calculation.
[0041] Taking the JDBC driver as an example, through the set series of methods provided by the PreparedStatement class of JDBC, the application program binds different Java type variables to the corresponding parameter types of SQL. In a single type database system, the JDBC driver usually uses a fixed type mapping to map Java types to SQL types. Since JDBC can only recognize the types of a single type system, the database server cannot change the type of the bound parameter.
[0042] In different databases, the behavior of data types with the same name is often different, and in some technologies, some databases can be used to handle data of multiple different parameter types. For example, in a database that supports a binary type system, there are two sets of data types, and the two sets of data types are isolated using different schemas. The same is true for multi-type database systems.
[0043] In this case, due to the existence of multiple different parameter types, the database cannot determine whether the parameter type of the external input data needs to be converted to a specific type, which affects the subsequent processing of the statement. Among them, for constants, in binary or multi-type database systems, the constant type inference method of a single-type database system is not applicable. For bound parameters, the client programming interface does not have the ability to parse SQL statements and cannot identify the contextual semantics of expressions in SQL statements. Therefore, the client programming interface always maps the application binding data to the data type in a fixed mode and cannot support two sets of data types in the binary type system at the same time.
[0044] Therefore, in the case where the database can be used to process data of at least two different parameter types, how to more accurately determine the parameter types of constants and bound parameters in the currently processed statement, specifically to enable the database to correctly infer the constants and bound parameter types as certain data types under a specific mode, while not being able to change the data type of the bound parameter, and to avoid using explicit forced type conversions in SQL statements as much as possible, is a technical problem that needs to be solved in this field.
[0045] Based on this, the present application provides a statement processing method for a database, which can more accurately determine the parameter types of constants and binding parameters in the currently processed statement when the database can be used to process data of at least two parameter types. The technical solution of the present application is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0046] Figure 1 A flowchart of an embodiment of a statement processing method for a database provided by the present application is shown in FIG. Figure 1 The method shown is applied to a database that supports processing data of at least two different parameter types, and is specifically executed by the database. Specifically, Figure 1 The statement processing method of the database shown includes:
[0047] S10: Parse the statement to be processed and obtain a syntax tree of the statement.
[0048] Specifically, after the database obtains the statement to be processed, it can perform syntax parsing on the statement and construct an abstract syntax tree (AST) corresponding to the statement.
[0049] Figure 2 FIG. is a schematic diagram of an embodiment of the syntax tree of the statement provided by the present application. Among them, taking the statement described in the embodiment of the present application as an SQL statement as an example, for the SQL statement: SELECT id, name FROM books WHERE price > 50.00 AND store < $1; after the database performs syntax parsing processing, the syntax tree of the statement as shown in Figure 2 can be obtained.
[0050] S20: Construct a corresponding auxiliary parsing node for each expression node in the syntax tree constructed in S101.
[0051] Specifically, the database can perform semantic analysis on the SQL syntax tree, traverse the syntax tree in a depth-first manner, and construct auxiliary parsing nodes for each expression node. Among them, the auxiliary parsing nodes can be used to analyze the data type of the expression nodes subsequently.
[0052] Figure 3 FIG. is a schematic diagram of the auxiliary parsing node corresponding to the expression node in the syntax tree provided by the present application. As shown in Figure 3 shows the schematic diagram of the auxiliary parsing node established for the syntax tree in Figure 2 . As shown in Figure 3 , in an embodiment of the present application, the auxiliary parsing node includes: a first pointer (E) of the current auxiliary parsing node, a second pointer (P) of the parent node of the current auxiliary parsing node, a parameter type (T) of the current parsing node, and a parameter type confirmation method indication information (C) of the current auxiliary parsing node. Among them, the second pointer (P) of each auxiliary parsing node points to the first pointer (E) of the parent node of the auxiliary parsing node, forming an auxiliary parsing node linked list.
[0053] Taking Figure 3 as an example, the expression node "WHERE" constructs an auxiliary parsing node N1, the expression node "AND" constructs an auxiliary parsing node N2, the expression node ">" constructs an auxiliary parsing node N3, the expression node "50.00" constructs an auxiliary parsing node N4, the expression node "<" constructs an auxiliary parsing node N5, and the expression node "$1" constructs an auxiliary parsing node N6.
[0054] Figure 4 FIG. is a schematic diagram of a specific implementation manner of the auxiliary parsing node provided by the present application. As shown in Figure 4 shows Figure 3The specific content included in the auxiliary parsing nodes N1 - N6 constructed therein. For example, in the auxiliary parsing node N1 corresponding to the expression node "WHERE", the first pointer (E) is cond, the second pointer (P) is NULL, the parameter type (T) of the current parsing node is bool, and the parameter type confirmation method indication information (C) of the current auxiliary parsing node is false; in the auxiliary parsing node N2 corresponding to the expression node "AND", the first pointer (E) is AND, the second pointer (P) is cond, the parameter type (T) of the current parsing node is bool, and the parameter type confirmation method indication information (C) of the current auxiliary parsing node is false, and so on. N1 - N6 form an auxiliary parsing node linked list.
[0055] S30: Traverse each expression node of the syntax tree and perform analysis and processing on each expression node. Among them, for the target expression nodes in the syntax tree that meet the preset conditions, convert the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node, and finally obtain the query tree (Query) of the statement as shown in Figure 5 shown, where Figure 5 is a schematic diagram of an embodiment of the query tree of the statement provided by this application.
[0056] Specifically, in the embodiments of this application, the target expression nodes in the syntax tree that meet the preset conditions include: expression nodes with a constant parameter type and expression nodes with a bound parameter type.
[0057] Among them, when the database traverses each expression node of the syntax tree, it replaces the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node. After processing the current expression node, it also restores the pointer of the auxiliary parsing node in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node for recursive processing of other expression nodes.
[0058] In one embodiment, when traversing to a target expression node in the syntax tree with a constant parameter type, specifically determine the parameter type of the parent node of the auxiliary parsing node of the target expression node from the auxiliary parsing node linked list. Subsequently, determine the namespace pattern corresponding to the target expression node according to the parameter type of the parent node of the auxiliary parsing node. Finally, convert the parameter type of the target expression node to the parameter type corresponding to the constant in the namespace pattern.
[0059] For example, for Figure 3The parameter type of the target expression node "50.00" in the shown syntax tree is a constant, and the auxiliary parsing node corresponding to this target expression node is N4. Then when traversing to this target expression node, it is determined that the parent node of the auxiliary parsing node N4 is N3, and the parameter type is determined to be float according to the auxiliary parsing node N3. Subsequently, according to the determined parameter type float, the namespace pattern corresponding to the target expression node "50.00" is determined. Finally, the parameter type of the target expression is converted to the data type in this pattern, that is, finally, the parameter type of the expression node "50.00" with a constant parameter type is determined to be float.
[0060] In one embodiment, when traversing to an expression node in the syntax tree whose parameter type is a bound parameter, specifically, the parameter type of the parent node of the auxiliary parsing node of the target expression node is determined from the linked list of auxiliary parsing nodes; according to the parameter type of the parent node of the auxiliary parsing node, the namespace pattern corresponding to the target expression node is determined; according to the namespace pattern and the data type mapping table, the parameter type corresponding to the namespace pattern is determined; the bound parameter in the target expression node is mapped to the parameter type corresponding to the namespace pattern; a type conversion node is added to the syntax tree, the parent node of the type conversion node is set to the parent node of the target expression node, and the parent node of the target expression node is converted into the type conversion node, where the type conversion node is used to perform parameter type conversion on the parent node of the target expression node and the bound parameter of the target expression node.
[0061] For example, for Figure 3 the parameter type of the target expression node "$1" in the shown syntax tree is a constant, and the auxiliary parsing node of this target expression node is N6. Then when traversing to this target expression node, it is determined that the parent node of the auxiliary parsing node N6 is N5, and the parameter type is determined to be B.int according to the auxiliary parsing node N5. Subsequently, the namespace pattern corresponding to the target expression node "$1" is determined according to the determined parameter type B.int. As Figure 5 shown, a type conversion node "cast" is added to the syntax tree, the parent node of the type conversion node "cast" is set to the parent node "<" of the target expression node "$1", and the parent node of the target expression node "$1" is converted from "<" to the type conversion node "cast", so that the type conversion node "cast" can be used to perform parameter type conversion on the parent node "<" of the target expression node and the bound parameter of the target expression node "$1". For example, if the parameter type of the bound parameter of the parent node "<" of the target expression node is B.int and the parameter type of the bound parameter of the target expression node "$1" is A.int, then the type conversion node "cast" can be used for the conversion of the parameter type of the bound parameter between A.int and B.int.
[0062] In summary, for the statement processing method of the database provided in the embodiments of the present application, when processing a statement, the database can parse the statement to be processed to obtain a syntax tree, and construct an auxiliary parsing node for each expression node. Thus, by traversing the syntax tree, the parameter types of the target expression nodes that meet the preset conditions are converted according to the parameter classes of the parent nodes of the corresponding auxiliary nodes. Furthermore, when the database can be used to process data of at least two parameter types, the parameter types of constants and bound parameters in the currently processed statement can be determined more accurately.
[0063] In a binary or multi-data type system in a specific implementation manner, when analyzing an SQL statement, the database can automatically infer the data types of constants and bound parameter types as the data types in a determined mode according to the semantic meaning of the expression context, avoiding the application from using explicit type casting to achieve this requirement.
[0064] In one embodiment, when the database analyzes and processes each expression node, it specifically determines how to convert the parameter type of the target expression node according to the parameter type confirmation method indication information (C) in the auxiliary parsing node corresponding to each expression node. Among them, when the parameter type confirmation method indication information (C) of the auxiliary parsing node of the target expression node is the first preset value (false), then according to Figure 1 the method in the shown embodiment, the parameter type of the target expression node is converted according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node. When the parameter type confirmation method indication information (C) of the auxiliary parsing node of the target expression node is the second preset value (True), the parameter type of the target expression node is converted according to the specified parameter type of the target expression node directly, realizing explicit type casting. In this embodiment, different ways of determining the parameter type can be adjusted through the indication information in the auxiliary parsing node, improving the flexibility when determining the parameter type, and being more conducive to the application and promotion of the embodiments of the present application.
[0065] Figure 6 This is a flowchart of an embodiment of the statement processing method of the database provided by the present application. As Figure 6 shown in the embodiment provides a specific implementation manner of the method as Figure 1 shown. The statement processing method of the database as Figure 6 shown includes:
[0066] S101, perform syntax parsing on the input SQL statement to construct an SQL abstract syntax tree (AST).
[0067] S102, perform semantic analysis on the SQL syntax tree, and traverse the AST in a depth-first manner.
[0068] S103. Analyze and process each SQL expression node on the AST one by one and then return.
[0069] S104. Complete the analysis and processing of all nodes on the AST and generate a query tree (Query).
[0070] Figure 7 This is a flowchart showing an embodiment of the method for processing statements in the database provided by this application. As Figure 7 shown Figure 6 in the method for analyzing and processing expression nodes in a statement, as Figure 7 shown, the method includes:
[0071] Step S201. For each SQL expression node, construct an auxiliary parsing node for it on the stack for type inference of its constant sub-nodes. Connect the auxiliary parsing nodes of the sub-SQL expression nodes with the auxiliary parsing node of the parent SQL expression node to form a linked list of auxiliary parsing nodes.
[0072] Step S202. Replace the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current SQL expression node.
[0073] Step S203. Determine whether each parameter of the SQL expression node is a typed expression node, that is, in the lower-level nodes of the expression parameter, each level of sub-expression cannot be all constants or bound parameters or a combination of both.
[0074] Step S204. Obtain the return type of the first typed parameter of the SQL expression node and record it on the corresponding auxiliary parsing node as the parameter reference type of the SQL expression node.
[0075] Step S205. Determine the type of the SQL expression node.
[0076] Step S206. Based on Step S205, if the SQL expression node is a constant node, analyze and infer the node type and then return.
[0077] Step S207. Based on Step S205, if the SQL expression node is a bound parameter node, process the node and then return.
[0078] Step S208. Based on Step S205, if the SQL expression node is another type of node, execute S201, perform general recursive processing on the node parameters and then return.
[0079] Step S209. Based on Steps S206 - S208, restore the pointer of the auxiliary parsing node in the semantic analysis context to the pointer of the auxiliary parsing node of the parent-level SQL expression node.
[0080] Figure 8 This is a schematic flowchart of an embodiment of the statement processing method for the database provided by this application, as Figure 8 shown Figure 7 The method for analyzing and processing the expression node of the constant in the statement in Figure 8 The method shown includes:
[0081] Step S301: Through the auxiliary parsing node of the constant node, find its parent auxiliary parsing node.
[0082] Step S302: According to the parameter reference type recorded on the parent auxiliary parsing node of the constant node, obtain the schema (namespace) to which this type belongs.
[0083] Step S303: According to the schema to which the parameter reference type belongs, convert the constant node into a constant of a determined data type in this schema.
[0084] Figure 9 This is a schematic flowchart of an embodiment of the statement processing method for the database provided by this application, as Figure 9 shown Figure 7 The method for analyzing and processing the expression node of the bound parameter in the statement in Figure 8 The method shown includes:
[0085] Step S301: Through the auxiliary parsing node of the bound parameter node, find its parent auxiliary parsing node.
[0086] Step S302: According to the parameter reference type recorded on the parent auxiliary parsing node of the bound parameter node, obtain the schema (namespace) to which this type belongs.
[0087] Step S303: According to the schema to which the parameter reference type belongs, search the data type mapping table and map the bound parameter type passed by the client programming interface to the corresponding data type in this schema.
[0088] Step S304: Wrap a type conversion node outside the bound parameter node and use the bound parameter node as the input parameter of this type conversion node.
[0089] Step S305: Use the type conversion node to replace the bound parameter node on the AST.
[0090] In the foregoing embodiments of the present application, the method for processing statements of the database provided by the embodiments of the present application has been introduced. To implement each function in the method for processing statements of the database provided by the foregoing embodiments of the present application, as an execution subject, the database can be implemented by a hardware structure and / or software module. For example, the foregoing functions can be implemented in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module. Whether a certain function among the foregoing functions is executed in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module depends on the specific application and design constraints of the technical solution.
[0091] For example, Figure 10 FIG. is a schematic structural diagram of a device for processing statements of a database provided by the present application. As Figure 10 shown, the device can be used to execute the method for processing statements of the database provided in any embodiment of the present application. In one embodiment, as Figure 10 shown, the device 1000 for processing statements of the database includes: a parsing module 1001, a construction module 1002, and a conversion module 1003. Among them, the parsing module 10014 is used to parse the statement to be processed to obtain the syntax tree of the statement. The construction module 1002 is used to construct a corresponding auxiliary parsing node for each expression node in the syntax tree. The conversion module 1003 is used to traverse each expression node of the syntax tree. For the target expression node that meets the preset conditions in the syntax tree, according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node, the parameter type of the target expression node is converted to obtain the query tree of the statement.
[0092] The specific implementation manner and principle of the foregoing device for processing statements of the database refer to the description in the foregoing method for processing statements of the database, and will not be elaborated here.
[0093] It should be noted that it should be understood that the division of each module of the above device is only a division of logical functions. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. And these modules can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the processing module can be a separately established processing element, or it can be integrated in a certain chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and the function of the above determined module can be called and executed by a certain processing element of the above device. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together or can be independently implemented. The processing element mentioned here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed by the integrated logic circuit in the processor element or the instruction in the form of software.
[0094] For example, the above-mentioned modules can be one or more integrated circuits configured to implement the above method, such as: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. Again, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0095] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.
[0096] For example, Figure 11 is a schematic structural diagram of an electronic device provided by the present application. As Figure 11 shown, the device can be used to execute the statement processing method of the database provided in any embodiment of the present application. In one embodiment, as Figure 11 shown, the electronic device 2000 includes one or more processors 2001 and a memory 2002; wherein, the memory 2002 is used to store computer-executable instructions, and the processor 2001 can execute the computer-executable instructions stored in the memory 2002. When the computer-executable instructions are executed by the processor 2001, the processor 2001 is caused to implement the statement processing method of any database in the foregoing embodiments of the present application. In one embodiment, as Figure 11 shown, the electronic device 2000 further includes a communication interface 2003, wherein the processor 2001 can communicate with other devices through the communication interface 2003.
[0097] The present application also provides a computer-readable storage medium storing computer-executable instructions, which can be used to implement the statement processing method of any database in the foregoing embodiments of the present application when the computer-executable instructions are executed.
[0098] The embodiments of the present application also provide a chip for executing instructions, and the chip is used to execute the statement processing method of any database in the foregoing embodiments of the present application.
[0099] An embodiment of the present application further provides a computer program product, including a computer program which, when executed, implements the statement processing method of any one of the databases as described above in the present application.
[0100] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above method embodiments; and the foregoing storage medium includes: various media such as ROM, RAM, magnetic disk, or optical disc that can store program codes.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for processing statements in a database, characterized in that, The database supports processing data of at least two different parameter types, and the method includes: Parsing the statement to be processed to obtain the syntax tree of the statement; Constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; Traversing each expression node of the syntax tree, and for the target expression node in the syntax tree that meets the preset conditions, converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node to obtain the query tree of the statement.
2. The method according to claim 1, wherein: The auxiliary parsing node includes: a first pointer of the current auxiliary parsing node, a second pointer of the parent node of the current auxiliary parsing node, the parameter type of the current auxiliary parsing node, and the parameter type confirmation method indication information of the current auxiliary parsing node; wherein, the second pointer of each auxiliary parsing node points to the parent node of the auxiliary parsing node, forming a linked list of auxiliary parsing nodes.
3. The method according to claim 2, wherein The target expression node is an expression node with a parameter type of constant; the converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: Determining the parameter type of the parent node of the auxiliary parsing node of the target expression node from the linked list of auxiliary parsing nodes; Determining the namespace pattern corresponding to the target expression node according to the parameter type of the parent node of the auxiliary parsing node; Converting the parameter type of the target expression node to the parameter type corresponding to the constant in the namespace pattern.
4. The method according to claim 2, characterized in that, The target expression node is an expression node with a parameter type of bound parameter; the converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: Determining the parameter type of the parent node of the auxiliary parsing node of the target expression node from the linked list of auxiliary parsing nodes; Determining the namespace pattern corresponding to the target expression node according to the parameter type of the parent node of the auxiliary parsing node; Determining the parameter type corresponding to the namespace pattern according to the namespace pattern and the data type mapping table; Mapping the bound parameter in the target expression node to the parameter type corresponding to the namespace pattern; Adding a type conversion node to the syntax tree, setting the parent node of the type conversion node to the parent node of the target expression node, and converting the parent node of the target expression node to the type conversion node, wherein the type conversion node is used to perform parameter type conversion between the parent node of the target expression node and the bound parameter of the target expression node.
5. The method according to any one of claims 2 to 4, characterized in that, The converting the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node includes: When the parameter type confirmation method indication information of the auxiliary parsing node of the target expression node is the first preset value, convert the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node; When the parameter type confirmation method indication information of the auxiliary parsing node of the target expression node is the second preset value, convert the parameter type of the target expression node according to the specified parameter type of the target expression node.
6. The method according to claim 2, wherein When traversing each expression node of the syntax tree, it further includes: When traversing each expression node, replace the auxiliary parsing node pointer in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node; After processing the current expression node, restore the auxiliary parsing node pointer in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node.
7. A statement processing device for a database, characterized in that, The database supports processing data of at least two different parameter types, including: A parsing module for parsing the statement to be processed to obtain the syntax tree of the statement; A construction module for constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; A conversion module for traversing each expression node of the syntax tree. For the target expression node in the syntax tree that meets the preset conditions, convert the parameter type of the target expression node according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node to obtain the query tree of the statement.
8. An electronic device, characterized in that, It includes: A memory and a processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, causing the processor to execute the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, Stores computer-executable instructions, and when the computer-executable instructions are executed, the method according to any one of claims 1-6 is implemented.
10. A computer program product, characterized in that, Includes a computer program, and when the computer program is executed, the method according to any one of claims 1-6 is implemented.