Database data query method and related product

By constructing a reconstructed query tree in the database, the limitation of the existing database on the scope of use of FOR XML clauses is solved, and the use of FOR XML clauses in subquery statements is realized, which improves the accuracy and applicability of data queries.

CN120123359APending Publication Date: 2025-06-10CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510193081.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

The existing database has strict restrictions on the use of clauses in the query statement, which limits the scope of use of FOR XML clauses and reduces its applicability.

Method used

By obtaining the subquery statement in the target query statement, build the initial query tree, and determine whether the FOR XML clause exists. If present, perform aggregation processing and build a refactoring query tree to expand the scope of use of FOR XML clauses.

Benefits of technology

The use of FOR XML clause in subquery statements is implemented, which expands its scope of use, improves applicability, and improves the accuracy and reliability of data queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120123359A_ABST
    Figure CN120123359A_ABST
Patent Text Reader

Abstract

The invention provides a data query method of a database and a related product. The method comprises the steps of obtaining a target query statement, and obtaining a sub-query statement in the target query statement; constructing an initial query tree of the sub-query statement, and judging whether an OR XML clause exists in the sub-query statement or not; if yes, aggregating non-OR XML clauses in the sub-query statements according to the OR XML clauses, and constructing a reconstructed query tree of the sub-query statements according to an aggregation result and the initial query tree; and performing data query according to the reconstructed query tree to obtain a query result of the target query statement. According to the technical scheme, the application range of the OR XML clauses can be expanded, and the purpose of improving the applicability of the OR XML clauses is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of databases, and particularly to a method for querying data in a database and related products. Background Art

[0002] A relational database is a data storage system based on a relational model. This relational model can organize data into a series of tables, where each row in the table represents a record and each column represents a field. These tables are interconnected through specific relationships (such as primary keys and foreign keys) to express complex data structures and relationships.

[0003] Querying data in a relational database can obtain relational data. If a FOR XML clause is set in the query statement, the relational data queried according to the query statement can be converted into XML data. However, some databases have strict usage restrictions on the clauses in the query statement, requiring that the FOR XML clause be allowed to be used when the SELECT statement is the main query statement, while not allowing the FOR XML clause to be used when the SELECT statement is a subquery statement. This restricts the usage scope of the FOR XML clause and reduces the applicability of the FOR XML clause. Summary of the Invention

[0004] The present invention provides a method for querying data in a database and related products, which is used to expand the usage scope of the FOR XML clause and achieve the purpose of improving the applicability of the FOR XML clause.

[0005] A further object of the present invention is to improve the accuracy and reliability of data querying.

[0006] Specifically, in a first aspect, the present invention provides a method for querying data in a database, including:

[0007] Obtaining a target query statement and obtaining a subquery statement in the target query statement;

[0008] Constructing an initial query tree of the subquery statement and determining whether there is a FOR XML clause in the subquery statement;

[0009] If there is, aggregating non-FOR XML clauses in the subquery statement according to the FOR XML clause, and constructing a reconstructed query tree of the subquery statement according to the aggregation result and the initial query tree;

[0010] Performing data query according to the reconstructed query tree to obtain a query result of the target query statement.

[0011] Further, the step of aggregating the non-FOR XML clauses in the subquery statement according to the FOR XML clause includes:

[0012] Construct a preset aggregation function according to the FOR XML clause, and construct an aggregation projection column according to the preset aggregation function;

[0013] Obtain the projection columns of the non-FOR XML clause, and fill the aggregation projection column according to the projection columns of the non-FOR XML clause to aggregate the non-FOR XML clause.

[0014] Further, the step of constructing the initial query tree of the subquery statement includes:

[0015] Perform syntax parsing on the subquery statement to construct a syntax parsing tree of the subquery statement;

[0016] Construct the initial query tree of the subquery statement according to the syntax parsing tree.

[0017] Further, after the step of constructing the syntax parsing tree of the subquery statement, it further includes:

[0018] Attach the FOR XML clause as an independent clause to the syntax parsing tree.

[0019] Further, after the step of determining whether there is a FOR XML clause in the subquery statement, it further includes:

[0020] If not, perform a query operation according to the initial query tree to obtain the query result.

[0021] Further, the step of performing data query according to the reconstructed query tree to obtain the query result of the target query statement includes:

[0022] Construct a main query tree of the target query statement according to each of the reconstructed query trees, and generate an execution plan of the target query statement according to the main query tree;

[0023] Perform a data query operation according to the execution plan to obtain the query result.

[0024] Further, the step of generating the execution plan of the target query statement according to the main query tree includes:

[0025] Use the optimizer of the database to generate the execution plan according to the main query tree.

[0026] In a second aspect, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data query method described in any one of the above are implemented.

[0027] In a third aspect, the present invention further provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the data query method described in any one of the above are implemented.

[0028] In a fourth aspect, the present invention further provides a computer device, including a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to implement the steps of the data query method described in any one of the above.

[0029] In the technical solution of the present invention, during the process of performing a data query on a database, if there is a FOR XML clause in the subquery statement of the target query statement, after constructing the initial query tree of the subquery statement, the non-FOR XML clauses in the subquery statement are aggregated according to the FOR XML clause to reconstruct the reconstructed query tree of the subquery statement. Thus, during the process of performing the data query, not only can the relational data obtained by the subquery statement be converted into XML data, but also it can be ensured that the reconstructed query tree of the subquery statement can be applied to the main query function of the target query statement. Therefore, the technical solution of the present invention can enable the FOR XML clause to be applied to the subquery statement of the target query statement, so as to achieve the purpose of expanding the usage range of the FOR XML clause and improving the applicability of the FOR XML clause.

[0030] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more clearly aware of the above and other objects, advantages, and features of the present invention. Description of the Drawings

[0031] Hereinafter, some specific embodiments of the present invention will be described in detail with reference to the accompanying drawings in an exemplary and non-limiting manner. The same reference numerals in the drawings denote the same or similar components or parts. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:

[0032] Figure 1 is a schematic flowchart of a data query method for a database according to an embodiment of the present invention;

[0033] Figure 2 is a schematic flowchart of aggregating non-FOR XML clauses in a subquery statement according to an embodiment of the present invention;

[0034] Figure 3Schematic flowchart of constructing an initial query tree for a subquery statement according to an embodiment of the present invention;

[0035] Figure 4 Schematic flowchart of performing a query operation according to a reconstructed query tree of a subquery statement according to an embodiment of the present invention;

[0036] Figure 5 Schematic flowchart of a data query method for a database according to another embodiment of the present invention;

[0037] Figure 6 Schematic diagram of a computer program product according to an embodiment of the present invention;

[0038] Figure 7 Schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and

[0039] Figure 8 Schematic diagram of a computer device according to an embodiment of the present invention. Detailed implementation manners

[0040] In the query statement of a database, the role of the FOR XML clause is to convert the queried relational data into XML data. For example, the framework of the query statement is:

[0041] SELECT targetlist FROM table_clause[where_clause][group_by_clause][having_clause][order_by_clause][for_xml_clause];

[0042] Among them, the SELECT keyword is used to specify the columns or expressions to be retrieved from the database. The targetlist is a list of column names or expressions to be retrieved, and multiple column names or expressions are separated by commas; the FROM keyword is used to specify the table from which to retrieve data; the table_clause can be the name of one or more tables. If there are multiple tables, it usually means a join operation is to be performed; the where_clause is the WHERE clause, which is used to specify the conditions for retrieving data, and only the rows that meet the conditions will be included in the result set; the group_by_clause is the GROUP BY clause, which is used to group the rows in the result set and is usually used together with aggregate functions to perform calculations on each group; the having_clause is the HAVING clause, which is used to specify the conditions for filtering the grouped data; the order_by_clause is the ORDER BY clause, which is used to specify the sorting order of the result set; the for_xml_clause is the FOR XML clause, which is used to return the query result in XML format.

[0043] The query statement constructed according to the above query statement framework will convert the retrieved data into a piece of data in XML format. In the above query statement, the FOR XML clause is located in the main query statement. The SQL syntax of the database allows query nesting, that is, a main query statement can have one or more sub-query statements. However, some databases have strict usage restrictions on the clauses in the query statement, requiring that the FOR XML clause is allowed to be used when the SELECT statement is the main query statement, while it is not allowed to be used when the SELECT statement is a sub-query statement. This restricts the usage range of the FOR XML clause and reduces the applicability of the FOR XML clause.

[0044] The following refers to Figures 1 to 8 to describe a database-based data query method and related products according to an embodiment of the present invention. In the description of this embodiment, it should be understood that the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features, that is, include one or more of such features. In the description of the present invention, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise specifically defined. When a certain feature "includes or contains" a certain or certain features it covers, unless otherwise specifically described, this indicates that other features are not excluded and other features may be further included.

[0045] Please refer to Figure 1 , Figure 1The figure shows a schematic flowchart of a data query method for a database according to an embodiment of the present invention. The data query method can implement the function of using the FOR XML clause in a subquery statement, and can achieve the purpose of improving the applicability of FOR XML.

[0046] As Figure 1 shown, the data query method for the database in this embodiment includes the following steps:

[0047] Step S102: Obtain a target query statement, and obtain the subquery statement in the target query statement;

[0048] Step S104: Construct an initial query tree for the subquery statement, and determine whether there is a FOR XML clause in the subquery statement;

[0049] If there is, execute step S106;

[0050] Step S106: Aggregate the non-FOR XML clauses in the subquery statement according to the FOR XML clause, and construct a reconstructed query tree for the subquery statement according to the aggregation result and the initial query tree of the subquery statement;

[0051] Step S108: Execute a data query operation according to the reconstructed query tree of the subquery statement to obtain the query result of the target query statement.

[0052] In the above step S102, the commonly used query statements in the database are SQL statements, such as SELECT statements, INSERT statements, UPDATE statements, or DELETE statements. Therefore, the target query statement in this embodiment is also an SQL statement. In SQL syntax, query nesting is allowed. For example, the first query statement can be nested in the second query statement, then the second query statement is the main query statement of the first query statement, and the first query statement is the subquery statement of the second query statement, where the subquery statement can be a SELECT statement.

[0053] After obtaining the target query statement, the fields in the target query statement can be traversed to obtain the subquery statement in the target query statement.

[0054] In the above step S104, a query tree is a structure for representing an SQL query. In this structure, the query is divided into multiple nodes, and each node represents a part of the query. The query tree helps the database management system understand and optimize the query.

[0055] Each node in the query tree represents a component of the query, such as a table name, a column name, a join condition, or a filter condition, etc. The root node in the query tree usually represents the entire query of the query statement, and the child nodes represent each query part of the query statement. Therefore, the query tree can clearly display the logical structure of the query through a hierarchical structure.

[0056] After obtaining the subquery statements in the target query statement, each subquery statement can be parsed to decompose the subquery statement into multiple components, and then a corresponding node is generated for each component, and these nodes are organized according to the hierarchical structure to form the query tree of the subquery statement.

[0057] In this embodiment, it is possible to identify each clause in the subquery statement to determine whether there is a FOR XML clause in the subquery statement. For example, if it is detected that there is a for_xml_clause in the subquery statement, it can be determined that there is a FOR XML clause in the subquery statement.

[0058] In the above step S106, aggregating the non-FOR XML clauses in the subquery statement means taking the data type conversion of the FOR XML clause as a data query, that is, pushing down the subquery statement. Through one data query, the query results of the non-FOR XML clauses in the subquery statement are converted into XML data. Therefore, in this embodiment, the query result of the subquery tree is used as the query object, and the query operation for the query object is constructed with the goal of aggregating and converting the query object into XML data. At this time, the non-FOR XML clauses in the subquery statement are the subqueries of the query operation. Then, a query tree is constructed according to the query operation, and this query tree is the reconstructed query tree of the subquery statement, and the initial query tree of the subquery statement is the subquery tree of the reconstructed query tree.

[0059] For example, if there are multiple non-FOR XML clauses in the subquery statement, and the query results obtained by each non-FOR XML clause include at least one row and multiple columns of data, aggregating the non-FOR XML clauses can aggregate the query results of each non-FOR XML clause into a relational data with multiple rows and multiple columns. Then, a query operation is constructed with the goal of converting the relational data into XML data. In this query operation, the queries of each non-FOR XML clause are the subqueries of the query operation, and after constructing the reconstructed query tree according to the query operation, the initial query tree of the subquery statement is the subquery tree of the reconstructed query tree.

[0060] In the above step S108, during the execution of the target query statement, the reconstructed query tree of the subquery statement can be used as the subquery tree in the target query statement and applied to the main query tree of the target query statement. And query operations are performed according to the reconstructed query tree of the subquery statement, and the query result of the subquery statement obtained is XML data. Then, according to the query logic of the target query statement, the query result of the subquery statement is queried to obtain the query result of the target query statement.

[0061] According to the above content, it can be known that in this embodiment, during the process of querying data from the database, if there is a FOR XML clause in the subquery statement of the target query statement, after the initial query tree of the subquery statement is constructed, the non-FOR XML clauses in the subquery statement are aggregated according to the FOR XML clause to reconstruct the reconstructed query tree of the subquery statement. Thus, during the process of performing data query, not only can the relational data obtained by the subquery statement be converted into XML data, but also it can be ensured that the reconstructed query tree of the subquery statement can be applied to the main query function of the target query statement. Therefore, this embodiment can make the FOR XML clause be applied to the subquery statement of the target query statement to achieve the purpose of expanding the usage range of the FOR XML clause and improving the applicability of the FOR XML clause.

[0062] In some embodiments of the present invention, in the above step S106, the method for aggregating the non-FOR XML clauses in the subquery statement according to the FOR XML clause is as Figure 2 shown and includes the following steps:

[0063] Step S112: Construct a preset aggregation function according to the FOR XML clause and construct an aggregation projection column according to the preset aggregation function;

[0064] Step S114: Obtain the projection columns of the non-FOR XML clauses in the subquery statement and fill the above aggregation projection columns according to the projection columns of the non-FOR XML clauses to aggregate the non-FOR XML clauses in the subquery statement.

[0065] In this embodiment, a preset aggregation function can be used as the projection column to save the information in the projection columns of the non-FOR XML clauses in the subquery statement. Then, taking the projection column of the preset aggregation function as the query object, a new query tree is constructed with the goal of converting the query object into XML data, and this new query tree is the reconstructed query tree of the subquery statement.

[0066] In this embodiment, the projection columns of the non-FOR XML clause refer to the data columns constructed based on the query results of the non-FOR XML clause. The method for constructing the aggregated projection columns includes: first obtaining the number of non-FOR XML clauses and using this number as the number of rows for the aggregated projection, and using the number of query results of the non-FOR XML clause as the number of columns for the aggregated projection column, so as to construct the aggregated projection column.

[0067] The preset aggregation function in this embodiment is a function used to convert relational data into XML data, that is, the function that implements the for_xml_clause clause. The aggregated projection column constructed in this embodiment is a relational data with multiple rows and multiple columns. After constructing this aggregated projection column, the query results of each non-FOR XML clause can be filled into the data columns of the corresponding data rows in the aggregated projection column respectively. Then, using the preset aggregation function, the data in the aggregated projection column can be converted into XML data.

[0068] Through the technical solution of this embodiment, the preset aggregation function can be used to implement the aggregation of the projection columns of the non-FOR XML clauses in the subquery statement, so as to reconstruct the subquery tree of the subquery statement, thereby improving the reliability and accuracy of reconstructing the subquery tree of the subquery statement.

[0069] In some embodiments of the present invention, the method for constructing the initial query tree of the subquery statement in step S104 is as Figure 3 shown and includes the following steps:

[0070] Step S122: Perform syntax parsing on the subquery statement of the target query statement to construct the syntax parsing tree of this subquery statement;

[0071] Step S126: Construct the initial query tree of the subquery statement according to the syntax parsing tree of the subquery statement.

[0072] In this embodiment, performing syntax parsing on the subquery statement means decomposing the query statement into multiple statement units, such as keywords, identifiers, or operators, etc., and then classifying and parsing each statement unit to generate a data structure according to the syntax rules.

[0073] After generating the syntax parsing tree of the subquery statement, the subquery statement can be semantically recognized according to this syntax parsing tree, and the subquery tree of this subquery statement can be constructed according to the recognition result.

[0074] In this embodiment, by performing syntax recognition on the subquery statement, the accuracy and reliability of constructing the subquery tree can be improved.

[0075] In some embodiments of the present invention, as Figure 3As shown, after constructing the syntax parse tree of the subquery statement in step S122, it further includes:

[0076] Step S124: Attach the FOR XML clause as an independent clause to the syntax parse tree of the subquery statement.

[0077] In this embodiment, attaching the FOR XML clause as an independent clause to the syntax parse tree of the subquery statement means setting the FOR XML clause separately in the syntax parse tree without establishing a logical connection before the non-FOR XML clauses.

[0078] In this embodiment, by attaching the FOR XML clause as an independent clause to the syntax parse tree of the subquery statement, after constructing the subquery tree of the subquery statement, it is possible to quickly and accurately determine whether there is a FOR XML clause in the subquery statement according to the syntax parse tree, so as to improve the accuracy and timeliness of data query.

[0079] In some embodiments of the present invention, after determining whether there is a FOR XML clause in the subquery statement in the above step S104, it further includes:

[0080] If there is no FOR XML clause in the subquery statement, perform data query according to the initial query tree of the subquery statement to obtain the query result of the target query statement.

[0081] In this embodiment, if there is no FOR XML clause in the subquery statement, it can be determined that it is not necessary to convert the query result of the subquery statement from relational data to XML data. Therefore, only need to construct the main query tree of the target query statement according to the initial query tree of the subquery statement, and then perform data query according to the main query tree to obtain the query result of the target query statement.

[0082] In this embodiment, since the subquery statement is a part of the main query statement, performing data query according to the initial query tree of the subquery statement means using the query result of the subquery statement as the object to be queried, and further querying the object to be queried in the main query according to the query logic of the target query statement, so as to obtain the query result of the target query statement.

[0083] The technical solution of this embodiment can obtain the query result of the target query statement according to the initial query tree of the subquery statement when there is no FOR XML clause in the subquery statement, so as to improve the reliability of data query in the database.

[0084] In some embodiments of the present invention, the method of performing the query operation according to the reconstructed query tree of the subquery statement in the above step S104 is as Figure 4As shown in the figure, it includes the following steps:

[0085] Step S202: Construct the main query tree of the target query statement according to the reconstructed query tree of the subquery statement, and generate an execution plan for the target query statement based on this main query tree;

[0086] Step S204: Execute a data query operation according to the execution plan of the target query statement to obtain the query result of the target query statement.

[0087] In step S202, since the subquery statement is a part of the target query statement, therefore, the query logic of the target query statement can be obtained according to the syntax parsing result of the target query statement, and then according to this query logic, the reconstructed query tree of the subquery statement is used as the subquery tree of the main query tree of the target query statement to construct the main query tree of the target query statement.

[0088] In step S204, an execution plan can be generated according to the main query tree of the target query statement, and the query operation is executed by the executor of the database according to this query plan to obtain the query result of the target query statement.

[0089] The executor of the database is the core component in the database management system responsible for executing the query plan. Its main task is to execute the query operation according to the query plan to generate a query result. The executor of the database is the layer that executes statements in the database system, responsible for calling the storage engine to obtain data and processing the data according to the operations in the query plan.

[0090] In this embodiment, the method of using the executor to execute the query operation according to the query plan includes:

[0091] First, parse the query plan to obtain the query operations to be executed and the execution order of the query operations; then, call the corresponding storage engine interface according to the execution plan to obtain the required data; finally, perform operations such as filtering, sorting, grouping, and aggregation on the obtained data to generate a query result that meets the query requirements.

[0092] In this embodiment, the main query tree of the target query statement is constructed according to the reconstructed query tree of the subquery statement, and the query operation is executed according to this main query tree, which can accurately and quickly obtain

[0093] In some embodiments of the present invention, as Figure 4 shown, in the above step S202, the method of generating a query plan according to the main query tree of the target query statement includes:

[0094] Use the optimizer of the database to generate a query plan for the target query statement according to the main query tree of the target query statement.

[0095] The optimizer is one of the core components of a relational database management system. Its role is to perform internal optimizations on the user's query requests to generate an execution plan for data queries.

[0096] Database query optimizers are mainly divided into two types: rule-based optimizers and cost-based optimizers. Among them, rule-based optimizers select an execution plan according to the built-in rules of the database. The memory rules of the database are hard-coded in the database. When the database executes a query statement, the rule-based optimizer follows these rules to determine the execution process. Cost-based optimizers generate a set of possible execution plans based on the query statement, estimate the cost of each execution plan, and then select the execution plan with the lowest cost as the final execution plan. Here, the cost represents the resource consumption such as IO and CPU required to execute the query. The optimizer in this embodiment uses a rule-based optimizer or a cost-based optimizer.

[0097] The optimization work of the optimizer is usually divided into two stages: logical optimization and physical optimization. Among them, logical optimization is achieved through equivalent substitution of relational expressions and heuristic rules of the query tree (such as giving priority to selection and projection, eliminating subqueries, etc.) to reduce disk IO operations and improve query efficiency. Physical optimization is based on heuristic rules, cost-based algorithms, and different optimization strategies for single tables, two tables, and multiple tables (such as selecting single-table scan methods, two-table join methods, multi-table join orders, etc.) to select the most efficient access path and operation algorithm to reduce resource consumption and improve query speed.

[0098] In this embodiment, using the optimizer of the database to generate the query plan for the target query statement can improve the reliability and accuracy of executing the target query statement.

[0099] In some embodiments of the present invention, the data query method of the database of the present invention is as Figure 5 shown and includes the following steps:

[0100] Step S302: Obtain the target query statement and obtain the subquery statement in the target query statement;

[0101] Step S304: Parse the syntax of the subquery statement to obtain the syntax parse tree of the subquery statement, and attach the FOR XML clause as an independent clause to the syntax parse tree;

[0102] Step S306: Aggregate the non-FOR XML clauses in the subquery statement according to the FOR XML clause, and construct a reconstructed query tree for the subquery statement based on the aggregation result and the initial query tree of the subquery statement;

[0103] Step S308: Determine whether there is a FOR XML clause in the subquery statement of the target query statement;

[0104] If there is, execute Step S310; if not, execute Step S316;

[0105] Step S310: Construct a preset aggregation function according to the FOR XML clause, and construct an aggregation projection column according to the preset aggregation function;

[0106] Step S312: Obtain the projection columns of the subquery statement other than the FOR XML clause, and fill the above aggregation projection columns according to the projection columns of the subquery statement other than the FOR XML clause to aggregate the subquery statement other than the FOR XML clause;

[0107] Step S314: Construct a reconstructed query tree of the subquery statement according to the aggregation result of the subquery statement other than the FOR XML clause and the initial query tree of the subquery statement, and construct a main query tree of the target query statement according to the reconstructed query tree;

[0108] Step S316: Construct a main query tree of the target query statement according to the initial query tree of the subquery statement;

[0109] Step S318: Use the optimizer of the database to generate an execution plan of the target query statement according to the main query tree of the target query statement;

[0110] Step S320: Use the executor of the database to perform a data query operation according to the execution plan of the target query statement to obtain the query result of the target query statement.

[0111] Since this embodiment can apply the FOR XML clause to the subquery statement of the target query statement, the usage range of the FOR XML clause can be expanded, and the applicability of the FOR XML clause can be improved.

[0112] The flowchart provided in this embodiment is not intended to indicate that the operations of the method will be executed in any specific order, or that all operations of the method are included in every case. In addition, the above methods may include additional operations. Within the scope of the technical idea provided by the method of this embodiment, additional changes can be made to the above methods.

[0113] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.

[0114] This embodiment also provides a computer program product 10, a computer-readable storage medium 20, and a computer device 30.Figure 6 Schematic diagram of a computer program product 10 according to an embodiment of the present invention Figure 7 Schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention Figure 8 Schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, and when the computer program 11 is executed by a processor 32, it implements the steps of any one of the above-mentioned database data query methods. The computer-readable storage medium 20 stores the above-mentioned computer program 11, and when the computer program 11 is executed by a processor 32, it implements the steps of the database data query method of any one of the above-mentioned embodiments. The computer device 30 may include a memory 31, a processor 32, and a computer program 11 stored on the memory 31 and running on the processor 32.

[0115] The computer program 11 for performing the operations of the present invention may be assembly instructions, instruction set architecture (InstructionSet Architecture, abbreviated as ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, status setting data, configuration data of an integrated circuit, or source code or object code written in any combination of one or more programming languages and procedural programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, executed 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 latter case, the remote computer may be connected to the user's computer through any type of network (including a local area network (Local Area Network, abbreviated as LAN) or a wide area network (Wide Area Network, abbreviated as WAN)), or may be connected to an external computer (for example, using an Internet service provider through the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field-programmable gate array (Field-Programmable Gate Array, abbreviated as FPGA), or a programmable logic array (ProgrammableLogic Array, abbreviated as PLA) may execute computer-readable program instructions by using the status information of the computer-readable program instructions to personalize the electronic circuit.

[0116] For the description of this embodiment, the computer program product 10 is a related product including the computer program 11.

[0117] For the description of this embodiment, the computer-readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which can be any device that can contain, store, communicate, propagate, or use the computer program 11 for an instruction execution system, apparatus, or device, or in combination with these instruction execution systems, apparatuses, or devices. More specific examples (non-exhaustive list) of the computer-readable storage medium 20 include the following: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanically encoded device, and any suitable combination of the above.

[0118] The computer device 30 can be, for example, a server, a desktop computer, a laptop computer, a tablet computer, or a smartphone. In some examples, the computer device 30 can be a cloud computing node. The computer device 30 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 can be implemented in a distributed cloud computing environment where tasks are executed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.

[0119] The computer device 30 can include a processor 32 adapted to execute stored instructions and a memory 31 that provides temporary storage space for the operation of the instructions during operation. The processor 32 can be a single-core processor, a multi-core processor, a computing cluster, or any other number of other configurations. The memory 31 can include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.

[0120] The computer device 30 can also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that can be connected to the computer device. The network adapter / interface can provide communication between the computer device and a network, which is usually shown as a communication network.

[0121] At this point, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived from the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and determined to cover all these other variations or modifications.

Claims

1. A method for querying data in a database, characterized in that: include: Obtain a target query statement, and obtain a subquery statement in the target query statement; Constructing an initial query tree of the subquery statement, and determining whether there is a FOR XML clause in the subquery statement; If yes, aggregate the non-FOR XML clauses in the sub-query statement according to the FOR XML clause, and construct a reconstructed query tree of the sub-query statement according to the aggregation result and the initial query tree; Data query is performed according to the reconstructed query tree to obtain a query result of the target query statement.

2. The data query method according to claim 1, characterized in that: The step of aggregating the non-FOR XML clauses in the subquery statement according to the FOR XML clause comprises: Constructing a preset aggregate function according to the FOR XML clause, and constructing an aggregate projection column according to the preset aggregate function; The projection column of the non-FOR XML clause is obtained, and the aggregate projection column is filled according to the projection column of the non-FOR XML clause, so as to aggregate the non-FOR XML clause.

3. The data query method according to claim 1, characterized in that: The step of constructing the initial query tree of the sub-query statement includes: Performing syntax parsing on the sub-query statement to construct a syntax parsing tree of the sub-query statement; An initial query tree of the sub-query statement is constructed according to the syntax parse tree.

4. The data query method according to claim 3, characterized in that: After the step of constructing the syntax parse tree of the sub-query statement, the method further includes: The FOR XML clause is appended to the grammar parse tree as an independent clause.

5. The data query method according to claim 1, characterized in that: After the step of determining whether the subquery statement contains a FOR XML clause, the method further includes: If not, a query operation is performed according to the initial query tree to obtain the query result.

6. The data query method according to claim 1, characterized in that: The step of performing data query according to the reconstructed query tree to obtain the query result of the target query statement includes: Constructing a main query tree of the target query statement according to each of the reconstructed query trees, and generating an execution plan of the target query statement according to the main query tree; The data query operation is performed according to the execution plan to obtain the query result.

7. The data query method according to claim 6, characterized in that: The step of generating an execution plan for the target query statement according to the main query tree includes: The execution plan is generated according to the main query tree using the optimizer of the database.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the data query method according to any one of claims 1 to 7 are implemented.

9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the data query method described in any one of claims 1 to 7 are implemented.

10. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the data query method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Query optimization method and device for structured query language

    CN120448417A

  • Target query statement execution method and device and electronic equipment

    CN121166717A