Statement execution method, statement execution device, query method and query system
By constructing and removing statement execution paths from index nodes, and selecting paths with lower resource consumption, the problem of slow speed and resource waste caused by indexes in database queries is solved, thus achieving efficient querying.
Patent Information
- Application Number
- CN202410635730.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2025-11-21
AI Technical Summary
In database queries, blindly using indexes can lead to excessive scanning of data by global secondary indexes, resulting in slower query speeds and wasted resources.
By constructing a statement syntax tree, removing the target index node, generating a first statement execution path that does not contain an index and a second statement execution path that does not contain the target index, and selecting the execution path with less resource consumption based on the path selection strategy.
It improves query efficiency, reduces resource consumption, and avoids the problem of table lookups caused by global secondary indexes.
Smart Images

Figure CN120994679A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification relate to the technical field of computer technology, and particularly relate to a statement execution method and device, a query method and system. BACKGROUND
[0002] With the advent of the big data era, a large amount of data is usually stored in a database. When performing data query and other operations in the database through a SQL statement, since the database can correspond to multiple indexes, the existence of indexes can improve the query efficiency, and the SQL statement usually contains multiple types of operators such as filtering, aggregation, and sorting, so that one SQL statement can plan multiple execution paths containing indexes. In actual execution, an execution path containing an index is preferentially selected. However, due to the blind use of indexes, the use of indexes may lead to the problem of excessive scanning of data caused by global secondary indexes, thereby slowing down the query speed and causing resource waste. Therefore, an effective method is urgently needed to solve the above problems. SUMMARY
[0003] Therefore, the embodiments of the present specification provide a statement execution method. One or more embodiments of the present specification also relate to a statement execution device, a query method, a query device, a query system, a computing device, a computer-readable storage medium, and a computer program to solve the technical defects in the prior art.
[0004] According to a first aspect of the embodiments of the present specification, a statement execution method is provided, comprising:
[0005] constructing a statement syntax tree based on a statement execution path corresponding to a target statement, wherein the target statement is associated with a target database;
[0006] in a case where a reference syntax tree preset in the target database matches a structure of the statement syntax tree, and the statement syntax tree contains a target index node, eliminating the index node for the statement execution path, generating a first statement execution path, and eliminating the target index node, generating a second statement execution path;
[0007] selecting a target statement execution path from the statement execution path, the first statement execution path, and the second statement execution path according to a path selection strategy and executing the target statement execution path.
[0008] According to a second aspect of the embodiments of the present specification, a statement execution device is provided, comprising:
[0009] a construction module configured to construct a statement syntax tree based on a statement execution path corresponding to a target statement, wherein the target statement is associated with a target database;
[0010] The generating module is configured to, in a case where the reference syntax tree preset by the target database matches the syntax tree structure of the statement and the syntax tree of the statement contains a target index node, generate a first statement execution path by removing the index node for the statement execution path, and generate a second statement execution path by removing the target index node.
[0011] The selecting module is configured to select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy and perform the target statement execution path.
[0012] According to a third aspect of the embodiments of the present specification, a query method is provided, applied to a cloud side, comprising:
[0013] receiving a query request submitted by an end side, and determining a target statement based on the query request;
[0014] constructing a statement syntax tree based on a statement execution path corresponding to the target statement, wherein the target statement is associated with a target database;
[0015] in a case where a reference syntax tree preset by the target database matches the syntax tree structure of the statement and the syntax tree of the statement contains a target index node, generating a first statement execution path by removing the index node for the statement execution path, and generating a second statement execution path by removing the target index node;
[0016] selecting a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy;
[0017] executing the target statement execution path to obtain query information, and sending the query information as feedback of the query request to the end side.
[0018] According to a fourth aspect of the embodiments of the present specification, a query device is provided, applied to a cloud side, comprising:
[0019] The receiving module is configured to receive a query request submitted by an end side, and determine a target statement based on the query request;
[0020] The constructing module is configured to construct a statement syntax tree based on a statement execution path corresponding to the target statement, wherein the target statement is associated with a target database;
[0021] The generating module is configured to, in a case where the reference syntax tree preset by the target database matches the syntax tree structure of the statement and the syntax tree of the statement contains a target index node, generate a first statement execution path by removing the index node for the statement execution path, and generate a second statement execution path by removing the target index node.
[0022] The selecting module is configured to select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy.
[0023] The sending module is configured to execute the target statement execution path to obtain query information, and send the query information as feedback of the query request to the terminal side.
[0024] According to a fifth aspect of the embodiments of the present specification, a query system is provided, including a cloud side and a terminal side;
[0025] The terminal side is configured to submit a query request to the cloud side.
[0026] The cloud side is configured to determine a target statement based on the query request, construct a statement syntax tree based on a statement execution path corresponding to the target statement, wherein the target statement is associated with a target database, in a case that a reference syntax tree pre-set in the target database matches a structure of the statement syntax tree, and the statement syntax tree contains a target index node, remove the index node for the statement execution path to generate a first statement execution path, and remove the target index node to generate a second statement execution path, select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy, execute the target statement execution path to obtain query information, and send the query information as feedback of the query request to the terminal side.
[0027] According to a sixth aspect of the embodiments of the present specification, a computing device is provided, including:
[0028] a memory and a processor;
[0029] The memory is configured to store computer executable instructions, and the processor is configured to execute the computer executable instructions, and the computer executable instructions, when executed by the processor, implement the steps of the above statement execution method.
[0030] According to a seventh aspect of the embodiments of the present specification, a computer readable storage medium is provided, which stores computer executable instructions, and the instructions, when executed by a processor, implement the steps of the above statement execution method.
[0031] According to an eighth aspect of the embodiments of the present specification, a computer program product is provided, including a computer program or instructions, and the computer program or instructions, when executed by a processor, implement the steps of the above statement execution method.
[0032] In one embodiment of the present specification, when a target statement is executed, a statement syntax tree is constructed based on a statement execution path corresponding to the target statement. In the case that a reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed, a second statement execution path is generated. Thus, the first statement execution path not containing the index node is generated, and the second statement execution path not containing only the target index node is generated. The evolution of the statement execution path for the index node is realized, and the statement execution path containing different index nodes is obtained. Then, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path and the second statement execution path according to the path selection strategy, so as to execute, thereby improving the execution speed and reducing the resource consumption. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 is a processing process schematic diagram of a statement execution method provided by one embodiment of the present specification;
[0034] Figure 2 is a flowchart of a statement execution method provided by one embodiment of the present specification;
[0035] Figure 3 is a matching schematic diagram of a statement execution method provided by one embodiment of the present specification;
[0036] Figure 4 is a processing process flowchart of a statement execution method provided by one embodiment of the present specification;
[0037] Figure 5 is a statement processing schematic diagram of a statement execution method provided by one embodiment of the present specification;
[0038] Figure 6 is a structural schematic diagram of a statement execution device provided by one embodiment of the present specification;
[0039] Figure 7 is a flowchart of a query method provided by one embodiment of the present specification;
[0040] Figure 8 is a structural schematic diagram of a query device provided by one embodiment of the present specification;
[0041] Figure 9 is a structural schematic diagram of a query system provided by one embodiment of the present specification;
[0042] Figure 10 is a structural block diagram of a computing device provided by one embodiment of the present specification. DETAILED DESCRIPTION
[0043] In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present description. However, the present description can be practiced without the specific details, which are not intended to limit the present description. Accordingly, it will be understood that the present description is not limited to the embodiments described herein and / or illustrated herein but can be practiced with modification and alteration.
[0044] The terminology used in this description is for the purpose of describing particular embodiments only and is not intended to limit the one or more embodiments of the present description. As used in this description and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0045] It will be understood that, although the terms first, second, etc. can be used herein to describe various information, these terms are not intended to denote a temporal or chronological order. Rather, these terms are used solely to distinguish one from another only. For example, a first can be termed a second, and, similarly, a second can be also termed a first, without departing from the scope of the one or more embodiments of the present description. As used herein, the term "if' can be construed to mean "when" or "upon" or "in response to determining" terms denoting the occurrence of stated events or actions.
[0046] In addition, it should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the one or more embodiments of the present description are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of the relevant data need to comply with the relevant laws, regulations and standards of the country and region, and provide corresponding operation portal for the user to choose authorization or refusal.
[0047] First, the nomenclature involved in the one or more embodiments of the present description is explained.
[0048] SQL (Structured Query Language): a standard programming language for managing and querying relational databases.
[0049] Global secondary index / GSI: Global secondary index is an important feature in PolarDB-X. Compared with local secondary index, the data in global secondary index is distributed on each storage node according to the specified splitting method. Through global secondary index, users can increase the splitting dimension on demand, provide global unique constraints, etc.
[0050] PolarDB-X: A high-performance cloud-native distributed database product that supports centralized and distributed integrated forms, with capabilities such as financial-grade data high availability, distributed horizontal expansion, mixed load, low-cost storage, and extreme elasticity.
[0051] Index selection: Specifically refers to global index selection, using global indexes. When the query condition does not contain the partition key, the query data needs to scan all partitions on the partition table, which will cause obvious read amplification problems, and the more partitions, the more serious the read amplification. By selecting a global index, the number of partitions accessed can be reduced.
[0052] Plan Cache: Execution plan cache. For each SQL, the optimizer generates a corresponding execution plan.
[0053] SPM: Execution plan management. Each SQL corresponds to a baseline, and each baseline contains one or more execution plans. The execution plan with the minimum cost is selected according to the current parameters to execute.
[0054] BKA join: A commonly used equal join algorithm, the process is as follows: 1. Traverse the outer table (left table, usually the smaller side) data, for each batch (for example, 1000 rows) of data in the outer table. 2. Join the JOIN Key of this batch of data into an IN(....) condition and add it to the inner table query. 3. Execute the inner table query to get the JOIN matching rows. 4. Use a hash table to find the matching inner table rows for each row of the outer table, combine and output.
[0055] Figure 1 is a processing process schematic diagram of a statement execution method provided by an embodiment of the present specification; as Figure 1As shown, the target statement is path planned to obtain a statement execution path. A statement syntax tree is constructed based on the statement execution path corresponding to the target statement. In a case where a reference syntax tree preset in the target database matches a structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is pruned for the statement execution path to generate a first statement execution path, and the target index node is pruned to generate a second statement execution path, so as to generate the first statement execution path containing no index node and the second statement execution path containing only the target index node, implement evolution of the execution path for the statement execution path with respect to the index node, and obtain statement execution paths containing different index nodes. Further, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path and the second statement execution path according to resource consumption of each statement execution path, and a table lookup query problem caused by execution of the statement execution path in a case where the statement execution path contains a global secondary index node can be avoided. Thus, the target statement execution path with less resource consumption can be selected from multiple statement execution paths, and the purposes of reducing resource consumption and improving execution efficiency are achieved.
[0056] In the specification, a statement execution method is provided, and the specification also relates to a statement execution device, a query method, a query device, a query system, a computing device, and a computer readable storage medium, which are described in detail one by one in the following embodiments.
[0057] Referring to Figure 2 , Figure 2 A flowchart of a statement execution method provided according to one embodiment of the specification is shown, and specifically includes the following steps.
[0058] Step 202: Constructing a statement syntax tree based on a statement execution path corresponding to a target statement, wherein the target statement is associated with a target database.
[0059] Specifically, the target statement can be a SQL statement for querying, modifying, deleting or the like of data in the database; the statement execution path is an execution path obtained by path planning of the target statement based on filtering operators, sorting operators, aggregation operators, projection operators or the like of scanning operators corresponding to the target statement; the statement execution path can be at least one execution path obtained by constructing an execution plan for the target statement, and the execution order of scanning operators in each execution path is different. The syntax tree represents the execution order of each operator in the statement execution path, and a tree structure of the statement execution path is constructed according to the execution order of each operator. The target database is the operation object of the target statement, and the target statement is executed for the target database to realize querying, modifying, deleting or the like of data in the target database.
[0060] Based on this, the target statement can use global index, global secondary index or not use index during execution as a SQL statement. Therefore, the path planning can be performed for the target statement first, and then the statement syntax tree is constructed based on the statement execution path corresponding to the target statement, which is used for subsequent structure matching with the reference syntax tree. The target statement is associated with the target database, which is used for query, modification, deletion and other operations on the target database.
[0061] In actual application, the statement execution path corresponding to the target statement can be at least one. In the case that the statement execution path corresponding to the target statement is two or more, the statement syntax tree of the statement execution path can be constructed respectively, and then each statement syntax tree is matched with the reference syntax tree respectively. More comprehensive statement execution path analysis is realized. In addition, during the use of the target database, the execution plan cache can be started. For each SQL statement, the optimizer generates a corresponding execution plan. The start of the execution plan cache can make the user use the global index without feeling, and improve the query speed. The execution plan cache included in the target database contains a statement execution path set, and the statement execution path set includes one or more statement execution paths.
[0062] Step 204: In the case that the reference syntax tree preset in the target database is matched with the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed, a second statement execution path is generated.
[0063] Specifically, after the above construction of the statement syntax tree based on the statement execution path corresponding to the target statement, in the case that the reference syntax tree preset in the target database is matched with the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed, a second statement execution path is generated. The reference syntax tree is a syntax tree containing basic operators, and the reference syntax tree can contain a global secondary index scan operator, a scan operator of a main table and a BKA join operator. The target index node is an index node corresponding to the global secondary index scan operator; the first statement execution path refers to a statement execution path not containing any index node; and the second statement execution path refers to a statement execution path not containing only the target index node.
[0064] Based on this, after the above statement execution path based on the corresponding statement of the target statement is constructed, it is judged whether the reference syntax tree preset by the target database matches the structure of the statement syntax tree, and whether the statement syntax tree contains the target index node. In the case where the reference syntax tree preset by the target database matches the structure of the statement syntax tree, it means that the tree structure of the statement syntax tree contains the tree structure of the reference syntax tree, and in the case where the statement syntax tree contains the target index node, it means that the target index node contained in the statement syntax tree corresponds to the global secondary index, and the global secondary index causes a large number of back table rows in the process of executing the statement execution path corresponding to the target statement. Therefore, in the case where the reference syntax tree preset by the target database matches the structure of the statement syntax tree, and the statement syntax tree contains the target index node, the index node is removed from the statement execution path, a first statement execution path is generated, and the target index node is removed, and a second statement execution path is generated.
[0065] Further, the target index node can be a global secondary index. The existence of the global secondary index can cause a back table operation, resulting in a large number of back table rows. Therefore, the pre-execution back table row number of the target statement can be calculated through the statement execution path, and whether the statement execution path contains the target index node is determined through the judgment of the pre-execution back table row number. The specific implementation is as follows:
[0066] According to the statement execution path, the target statement is pre-executed to obtain target statement execution information; in the case where it is determined based on the target statement execution information that the pre-execution back table row number of the target statement is greater than a preset back table row number threshold, the index node to be tested in the statement syntax tree is taken as the target index node.
[0067] Specifically, the target statement execution information is execution information generated in the execution process of the target statement, and the target statement execution information includes but is not limited to scanning row number information when scanning the data table in the pre-execution process of the target statement according to the statement execution path; the pre-execution back table row number refers to the back table row number in the execution process of the target statement, which is estimated according to the scanning operator contained in the statement execution path without actually executing the target statement; and the preset back table row number threshold is a threshold preset for the back table row number, which is used for comparison with the pre-execution back table row number.
[0068] Based on this, the target statement is pre-executed according to the statement execution path to obtain target statement execution information, without actually executing the target statement, and only the back table row number in the execution process of the target statement is estimated. In the case where it is determined based on the target statement execution information that the pre-execution back table row number of the target statement is greater than a preset back table row number threshold, it means that the back table row number corresponding to the target statement is large, and problems such as slow execution speed and excessive resource consumption can occur. The index node to be tested in the statement syntax tree is taken as the target index node.
[0069] For example, when pre-executing a target statement according to a statement execution path, the number of back table rows is estimated according to the filter condition '2023-12-0114:10:05' and (c_text_long = '1' or id = 1) of the target statement. If the estimated number of back table rows is greater than a preset back table row threshold of 10,000 rows, it is determined that the global secondary index included in the statement execution path is the target index, and accordingly, the global secondary index node included in the statement execution path is the target index node.
[0070] In summary, by setting the preset back table row threshold, it can be determined whether the statement execution path contains a global secondary index node that causes a large number of back table rows, and accordingly, the problem of a large number of back table rows in the execution of the target statement can be solved, thereby improving the query efficiency.
[0071] Further, considering that the pre-execution back table row number is related to the execution condition (filter condition) and logical operation identifier included in the statement execution path, the pre-execution back table row number can be determined according to the execution condition and logical operation identifier, and the specific implementation is as follows:
[0072] At least one execution condition node included in the statement execution path is determined, and the logical operation identifier associated with the at least one execution condition node is determined. Based on a preset logical operation rule, the target statement execution information of the target statement is determined according to the at least one execution condition node and the logical operation identifier, and the pre-execution back table row number is extracted in the target statement execution information.
[0073] Specifically, the execution condition node is a filter condition node, which is used to filter the scanned data in the execution of the target statement. The execution condition can be time, date, text length, character type, etc. The logical operation identifier includes but is not limited to selection calculation identifier, judgment identifier, numerical calculation identifier, and type derivation identifier.
[0074] Based on this, at least one execution condition node contained in the statement execution path is determined, and a logical operation identifier associated with the at least one execution condition node is determined. A preset logical operation rule corresponds to a selection calculation identifier, a judgment identifier, a numerical calculation identifier, and a type derivation identifier. Based on the preset logical operation rule, the at least one execution condition node and the logical operation identifier determine target statement execution information of a target statement, and a pre-execution back table row number is extracted from the target statement execution information. The logical operation rule corresponds to an upper bound estimation algorithm, which is used to determine a target index node based on the pre-execution back table row number. The selection calculation identifier corresponds to selectivity(FREE)=1, selectivity(BOUND)=BOUND, and selectivity(UNKNOWN)=0; the judgment identifier includes FREE, BOUND, and UNKNOWN, and FREE indicates that the upper bound can be infinite or infinitesimal. A question mark represents a calculable constant, including: a<?; a<=?; a>?; a>=?; a<>?; a not in(?); a between?and?; a not between?and?; a is distinct from?; and a like?. BOUND indicates that there is an upper bound, including: a=?; a in(?); a is not distinct from?; a is null; and a is not null. UNKNOWN indicates unknown. The remaining ones that cannot be estimated are, for example, a=b, (a,b)in((?,?)), cast(a as int)=?; select*from cest_full_table_big where c_float_pr<=1+3.
[0075] The numerical calculation identifier corresponds to numerical calculation that can call a function to implement, for example, a=? calls getFrequencyUpperLimit; a in(?) calls getFrequencyUpperLimit*200; a is not distinct from? calls getFrequencyUpperLimit; a is null calls getNullCount; and a is not null calls 1-getNullCount.
[0076] Type deduction identifies include NOT, OR and AND. Among them, NOT includes NOT(UNKNOWN)=UNKNOWN; NOT(FREE)=FREE; NOT(BOUND)=FREE. OR includes: for n judgment identifiers, OR(A1, A2..., An), n=0, the result is 1; if there is FREE, then OR(A1, A2,... An)=FREE. If there are k BOUND(k>0), without loss of generality, A1, A2..., Ak are BOUND, Ak+1,..., An are UNKNOWN, If there is only UNKNOWN, then OR(A1, A2,... An)=UNKNOWN. AND includes: for n judgment identifiers, AND(A1, A2..., An), n=0, the result is 1; if there are k BOUND(k>0), without loss of generality, sort these BOUND from small to large as A1, A2..., Ak, Special cases: there are primary keys or uk equivalence in A1, A2..., directly return 1 / rowcount; if k=0, if there is no FREE, then AND(A1, A2,... An)=UNKNOWN, otherwise OR(A1, A2,... An)=FREE.
[0077] For example, for the filter condition c_timestamp_3='2023-12-01 14:10:05' and(c_text_long='1' or id=1) on the table cest_full_table_big with 10 million rows, UpperSelectivity(c_timestamp_3='2023-12-01 14:10:05')=207608.95 / rows=0.02; UpperSelectivity(c_text_long='1')=750389.44 / rows=0.07; UpperSelectivity(id=1)=1 / rows=1e-8; UpperSelectivity(c_text_long='1' or id=1)=max(0.07,1e-8)=0.07; UpperSelectivity(c_timestamp_3='2023-12-01 14:10:05' and(c_text_long='1' or id=1))=0.02*0.27=0.0054; so the final filter selectivity is selectivity(Free)=0.0054, and the pre-execution back table row number is 0.0054*rows=54000.
[0078] In addition, for the filter condition on the cest_full_table_big (not (c_bigint_64 in (16))) or c_bigint_64 = 1; UpperSelectivity (c_bigint_64 in (16)) = 1005 * 2000 / rows = 201000 / rows = 0.02; UpperSelectivity (not (c_bigint_64 in (16))) = FREE; UpperSelectivity (c_bigint_64 = 1) = 1005 / rows = 1e-4; UpperSelectivity (not (c_bigint_64 in (16))) or c_bigint_64 = 1) = FREE; so the final filter is selectivity (Free) = 1, and the pre-execution back table row number is 1 * rows = 10000000.
[0079] In summary, based on the preset logical operation rule, the at least one execution condition node and the logical operation identifier determine the target statement execution information of the target statement, and the pre-execution back table row number is extracted in the target statement execution information, so as to facilitate the determination of the target index node.
[0080] Further, considering that the arrangement mode of the tree node (execution node) in the statement syntax tree is relatively flexible, therefore, after determining that the statement syntax tree matches the reference syntax tree structure, the subsequent steps are continued to be executed, and the specific implementation is as follows:
[0081] Determine the statement tree structure of the statement syntax tree and the reference tree structure of the reference syntax tree preset by the target database; in the case that the statement tree structure contains the reference tree structure, it is determined that the reference syntax tree preset by the target database matches the structure of the statement syntax tree.
[0082] Specifically, the statement tree structure is a tree structure representation of the statement execution path, which is constructed according to the execution nodes contained in the statement execution path and the relationship between the execution nodes.
[0083] Based on this, the statement tree structure of the statement syntax tree and the reference tree structure of the reference syntax tree preset by the target database are determined. In the case that the statement tree structure contains the reference tree structure, it is indicated that the reference tree structure can be obtained by eliminating the tree nodes in the statement tree structure, and it is determined that the reference syntax tree preset by the target database matches the structure of the statement syntax tree.
[0084] For example, as Figure 3As shown, the reference syntax tree includes a BKA join algorithm node, a global secondary index node, and a main table A node; in the case of the statement tree structure including a sorting operator node, an aggregation operator node, a BKA join algorithm node, a global secondary index node, and a main table A node, and being as shown in Figure 3 In the case of the tree structure as shown in "structure mismatch" in the middle of the "structure matching", the reference syntax tree cannot be obtained by eliminating the tree nodes, and thus the structures of the two do not match. Figure 3
[0085] In summary, in the case of the statement tree structure including the reference tree structure, it is determined that the structure of the reference syntax tree preset by the target database matches the syntax tree of the statement, thereby simplifying the matching process of the tree structure.
[0086] Further, considering that the existence of the index node can cause the execution speed of the statement execution path to be slow, the index node can be eliminated to generate a first statement execution path that does not include the index node, and the specific implementation is as follows:
[0087] The execution nodes included in the statement execution path are determined, and the index node is eliminated in the execution nodes to obtain a first target execution node; a first statement execution path is generated based on the statement semantics of the target statement and the first target execution node.
[0088] Specifically, the first target execution node is an execution node present in the statement execution path after the index node; the statement semantics of the target statement correspond to the meaning of the execution nodes in the statement execution path and the execution order of the execution nodes.
[0089] Based on this, the execution nodes included in the statement execution path are determined, and the index node is eliminated in the execution nodes to obtain a first target execution node. The first target execution node is supplemented based on the statement semantics of the target statement to obtain a first supplemented execution node. The first statement execution path is generated based on the first supplemented execution node and the first target execution node.
[0090] For example, in the case where the statement execution path includes an index node corresponding to an index, the index node corresponding to the index is eliminated, and the path planning is performed again for the target statement to generate a statement execution path that does not include the index node corresponding to the index.
[0091] In summary, after eliminating the index node included in the statement execution path, a first statement execution path is generated, thereby a first statement execution path that does not include the index node can be generated, and the diversity of path generation is improved.
[0092] Further, considering that the slow execution speed of the statement execution path is caused by the target index node, the target index node can be removed to generate a second statement execution path, and the implementation is as follows:
[0093] The execution nodes included in the statement execution path are determined, and the target index node is removed from the execution nodes to obtain a second target execution node; the second statement execution path is generated based on the statement semantics of the target statement and the second target execution node.
[0094] Specifically, the second target execution node is an execution node present in the statement execution path after the target index node.
[0095] Based on this, the execution nodes included in the statement execution path are determined, and the target index node is removed from the execution nodes to obtain a second target execution node. The second target execution node is supplemented based on the statement semantics of the target statement to obtain a second supplemented execution node. The second statement execution path is generated based on the second supplemented execution node and the second target execution node.
[0096] For example, in the case where the statement execution path includes a target index node corresponding to a global secondary index, the target index node corresponding to the global secondary index is removed, and the path planning is performed again for the target statement to generate a statement execution path that does not include the target index node corresponding to the global secondary index.
[0097] As described above, after the target index node included in the statement execution path is removed, the second statement execution path is generated, so that the second statement execution path that does not include the target index node can be generated, and the diversity of path generation is improved.
[0098] Step 206: selecting a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy and executing.
[0099] Specifically, in the case where the reference syntax tree preset in the target database matches the statement syntax tree structure, and the statement syntax tree includes the target index node, after the index node is removed from the statement execution path to generate the first statement execution path, and the target index node is removed to generate the second statement execution path, the target statement execution path can be selected from the statement execution path, the first statement execution path and the second statement execution path according to the path selection strategy and executed, wherein the path selection strategy provides a selection basis for selecting the target statement execution path, and the selection basis can be the amount of resources consumed in the execution process of the statement execution path, including but not limited to time, computing resources, storage resources, etc.
[0100] Based on this, in the case that the reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains the target index node, after the index node is removed from the statement execution path, the first statement execution path is generated, and the target index node is removed to generate the second statement execution path, the path selection strategy is used to select the statement execution path with less resource consumption from the statement execution path, the first statement execution path, and the second statement execution path as the target statement execution path and execute it.
[0101] In practical applications, after the target statement execution path is executed, the target statement execution path can be marked according to the number of rows scanned during execution. Further, the reuse of the target statement execution path is facilitated.
[0102] Further, considering that different statement execution paths have different execution nodes and corresponding execution logic, the resource consumption of the statement execution path during execution is also different. Therefore, in the selection process of the target statement execution path, the resource consumption information of each statement execution path can be used as a basis for selection, and the specific implementation is as follows:
[0103] The resource consumption information corresponding to the statement execution path, the first statement execution path, and the second statement execution path is calculated; and the target statement execution path is selected from the statement execution path, the first statement execution path, and the second statement execution path according to the resource consumption information of each statement execution path and executed.
[0104] Specifically, the resource consumption information refers to the amount of resources consumed during the execution of each statement execution path, including but not limited to time resources, computing resources, and storage resources.
[0105] Based on this, the resource consumption information corresponding to the statement execution path, the resource consumption information corresponding to the first statement execution path, and the resource consumption information corresponding to the second statement execution path are calculated. The statement execution path with less resource consumption is selected as the target statement execution path from the statement execution path, the first statement execution path, and the second statement execution path according to the resource consumption amount corresponding to the resource consumption information of each statement execution path.
[0106] For example, the statement execution path contains a global secondary index node, the first statement execution path does not contain an index node, and the second statement execution path does not contain a global secondary index node but may contain other index nodes. The resource consumption amount of each statement execution path during execution is calculated. The statement execution path with less resource consumption is selected as the target statement execution path.
[0107] In summary, according to the resource consumption information, a statement execution path with less resource consumption is selected as a target statement execution path in the statement execution path, the first statement execution path and the second statement execution path, so that when the target statement execution path is executed, less resources can be consumed, and resource waste can be avoided.
[0108] Further, considering that there may be a difference between the estimated number of back table rows and the actual number of back table rows in the actual execution process when determining the pre-execution number of back table rows, the actual number of scanned rows can be calculated after the target statement execution path is executed, and then it is determined whether the target statement execution path can be reused subsequently, and the specific implementation is as follows:
[0109] The execution information corresponding to the target statement execution path is obtained, and the number of scanned rows is determined according to the execution information; in the case where the number of scanned rows is greater than a preset row threshold, the statement selection state of the target statement execution path is updated.
[0110] Specifically, the execution information includes but is not limited to the data row scanning information and resource consumption information generated by the target statement execution path in the execution process. The number of scanned rows is the number of rows of the scanned data table; the preset row threshold can be a pre-set number of rows. The statement selection state can be an unusable state, i.e., an unselectable state, or an available state, i.e., a selectable state.
[0111] Based on this, the execution information corresponding to the target statement execution path is obtained, and the number of scanned rows is determined according to the execution information. In the case where the number of scanned rows is greater than a preset row threshold, it indicates that the number of rows of the data table scanned in the execution process of the target statement execution path is large, which causes the problem of slow execution speed and large resource consumption. The statement selection state of the target statement execution path can be updated, and the statement selection state of the target statement execution path is updated to an unusable state, indicating that the target statement execution path will not be reused subsequently.
[0112] In summary, based on the preset row threshold, the statement selection state of the target statement execution path is updated, so that the number of scanned rows is calculated again after the target statement execution path is executed, and then it is determined whether the target statement execution path can be used subsequently, and the target statement execution path with large resource consumption is disabled in time.
[0113] Further, considering that a plurality of statement execution paths such as the target statement, the first statement execution path and the second statement execution path are generated for the target statement, and the path set is used for storage, it is convenient to manage each statement execution path, and the specific implementation is as follows:
[0114] store the first statement execution path and the statement execution path to a path set; eliminate the target inode, generate a second statement execution path, and store the second statement execution path to the path set in a case where a reference syntax tree preset by the target database matches a second statement syntax tree structure of the second statement execution path; and select a third statement execution path from the path set according to a path selection strategy and execute the third statement execution path.
[0115] Based on this, after the first statement execution path is generated, the first statement execution path and the statement execution path are stored to the path set. If the number of statement execution paths contained in the path set reaches a path quantity threshold, storage is not possible any more. The target inode is eliminated, a second statement execution path is generated, and the second statement execution path is stored to the path set in a case where a reference syntax tree preset by the target database matches a second statement syntax tree structure of the second statement execution path. Similarly, if the number of statement execution paths contained in the path set reaches the path quantity threshold, storage is not possible any more. After the second statement execution path is stored to the path set, it is judged whether the target inode is contained in the second statement execution path. If yes, the target inode is eliminated again, and the second statement execution path is generated. A third statement execution path is selected from the path set according to a path selection strategy and executed.
[0116] For example, a first statement execution path not containing an inode is generated for a target statement, and the first statement execution path is stored to an SPM. A second statement execution path not containing an inode corresponding to a global secondary index is generated for the target statement. The second statement execution path is stored to the SPM. If storage is successful, it is judged whether the second statement execution path contains an inode corresponding to the target global secondary index. If yes, a second statement execution path not containing an inode corresponding to the global secondary index is generated again for the target statement, and stored to the SPM.
[0117] In summary, the statement execution path, the generated first statement execution path, and the second statement execution path are stored to the path set. Further, each statement generation path can be stored and managed based on the path set. This facilitates selection of a target statement execution path subsequently.
[0118] In one embodiment of the present specification, when a target statement is executed, a statement syntax tree is constructed based on a statement execution path corresponding to the target statement. In the case that a reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed, a second statement execution path is generated. Thus, the first statement execution path not containing the index node and the second statement execution path not containing only the target index node are generated, the evolution of the statement execution path for the index node is implemented, and the statement execution path containing different index nodes is obtained. Then, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path and the second statement execution path according to the path selection strategy, so as to improve the execution speed and reduce the resource consumption.
[0119] The following description is made in conjunction with the accompanying Figure 4 The statement execution method provided in the present specification is further described by taking the application of the statement execution method in data query as an example. Wherein, Figure 4 A processing process flow diagram of a statement execution method provided in one embodiment of the present specification is shown, which specifically includes the following steps.
[0120] Step 402: constructing an execution plan of a target statement to obtain a statement execution path of the target statement.
[0121] In the data query scenario, the global secondary index needs to do a table lookup. If the data volume of the table lookup is large, the query speed will be very slow. The database estimates the data volume of the table lookup using the global secondary index through cardinality estimation, and does not use the index when the data volume is large. PolarDB-X has a default Plan Cache, and there is a frequent problem online: for the same SQL and two groups of parameters A and B, A uses the global index quickly but B uses the global index slowly. If the user first uses parameter A to query, a Plan Cache using the global index is generated, and then parameter B is used to query, the Plan using the global index cached is directly reused, resulting in slow speed, which needs manual intervention. The present embodiment follows the framework of SPM, optimizes the capture evolution mechanism therein, and increases the feedback capability.
[0122] In actual application, after determining a target statement to be executed, an execution plan is constructed for the target statement to obtain a statement execution path.
[0123] Step 404: constructing a statement syntax tree of the statement execution path.
[0124] Step 406: Match the statement syntax tree and the template syntax tree. If the statement syntax tree and the template syntax tree structure match and the statement execution path contains the target index, add the index evolution task corresponding to the statement execution path to the task queue.
[0125] Whether the statement execution path contains the target index can be determined using an upper bound estimation algorithm.
[0126] like Figure 5 As shown, the global secondary index is captured for the target statement, where the target index is the global secondary index. It checks if the statement syntax tree matches the template (template syntax tree). If they match, it further checks if the statement execution path contains the target index. If it does, an evolution task is generated for the target index. If the statement syntax tree does not match the template syntax tree, the capture operation ends; conversely, if the statement execution path does not contain the target index, the capture operation also ends.
[0127] Step 408: Determine and execute the index evolution tasks to be executed in the task queue, turn off index selection, and generate the first statement execution path corresponding to the target statement.
[0128] Step 410: Store the statement execution path and the first statement execution path into the execution plan set.
[0129] Step 412: Ignore the target index, generate the second statement execution path corresponding to the target statement, and store the second statement execution path in the execution plan set.
[0130] Step 414: Determine whether the execution path of the second statement contains the target index. If yes, proceed to step 412; otherwise, proceed to step 416.
[0131] During the evolution task execution, index selection is disabled, and the first execution path corresponding to the target statement is generated. It is then determined whether the first execution path has been successfully added to the plan set. If not, the evolution task ends; if successful, the target index is ignored, and a second execution plan is generated. The second execution plan is then checked to see if it matches the template (template syntax tree). If it matches, the second execution plan is successfully added to the plan set; if not, the evolution task ends. If successful, the second execution plan is checked to see if it contains the target index. If it does, the step of ignoring the target index and generating the second execution plan is executed; if not, the evolution task ends. If the second execution plan does not match the template (template syntax tree), the evolution task ends.
[0132] Step 416: Select the target statement execution path with the lower execution cost from the execution plan set and execute it.
[0133] Step 418: determine the scan row number corresponding to the target statement execution path, and in the case that the scan function is greater than the scan row number threshold, add a disable identifier to the target statement execution path.
[0134] After the evolution task is completed, the selected target plan with smaller execution cost is executed, and it is determined whether the scan row number of the target plan exceeds the scan row number threshold. If yes, the target plan is disabled; if no, the feedback process is ended.
[0135] In the evolution process, active evolution is performed, and the hotspot global secondary index found by the upper bound estimation algorithm is continuously disabled, a new execution plan is generated, and the execution plan no longer uses the hotspot global secondary index. By detecting the scan row number, the index selection is actively closed when the scan row number exceeds the threshold, thereby reducing the error rate.
[0136] In summary, in one embodiment of the present specification, when executing a target statement, a statement syntax tree is constructed based on a statement execution path corresponding to the target statement. In the case that a reference syntax tree preset by a target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path to generate a first statement execution path, and the target index node is removed to generate a second statement execution path. Thus, the first statement execution path not containing the index node and the second statement execution path only not containing the target index node are generated, the evolution of the statement execution path for the index node is implemented, and the statement execution path containing different index nodes is obtained. Further, the target statement execution path with less resource consumption can be selected in the statement execution path, the first statement execution path, and the second statement execution path according to the path selection strategy for execution, thereby improving the execution speed and reducing the resource consumption.
[0137] Corresponding to the above method embodiment, the present specification also provides a statement execution device embodiment, Figure 6 The structure of a statement execution device provided by one embodiment of the present specification is shown. As shown in the figure, Figure 6 The device includes:
[0138] The construction module 602 is configured to construct a statement syntax tree based on a statement execution path corresponding to a target statement, wherein the target statement is associated with a target database;
[0139] The generation module 604 is configured to, in the case that a reference syntax tree preset by the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, remove an index node for the statement execution path to generate a first statement execution path, and remove the target index node to generate a second statement execution path;
[0140] The selecting module 606 is configured to select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy and perform the target statement execution path.
[0141] In an optional embodiment, the generating module 604 is further configured to:
[0142] pre-execute the target statement according to the statement execution path to obtain target statement execution information;
[0143] In a case where it is determined based on the target statement execution information that a pre-execution back table row number of the target statement is greater than a preset back table row number threshold, an index node to be tested in the statement syntax tree is taken as the target index node.
[0144] In an optional embodiment, the generating module 604 is further configured to:
[0145] determine at least one execution condition node contained in the statement execution path and a logical operation identifier associated with the at least one execution condition node;
[0146] determine target statement execution information of the target statement based on a preset logical operation rule, the at least one execution condition node and the logical operation identifier, and extract the pre-execution back table row number from the target statement execution information.
[0147] In an optional embodiment, the generating module 604 is further configured to:
[0148] determine a statement tree structure of the statement syntax tree and a reference tree structure of a reference syntax tree preset by the target database;
[0149] In a case where the statement tree structure contains the reference tree structure, it is determined that the reference syntax tree preset by the target database matches the structure of the statement syntax tree.
[0150] In an optional embodiment, the generating module 604 is further configured to:
[0151] determine an execution node contained in the statement execution path, and remove an index node from the execution node to obtain a first target execution node;
[0152] generate a first statement execution path based on a statement semantic of the target statement and the first target execution node.
[0153] In an optional embodiment, the generating module 604 is further configured to:
[0154] determine an execution node included in the statement execution path, and eliminate a target index node in the execution node to obtain a second target execution node;
[0155] generate a second statement execution path based on a statement semantic of the target statement and the second target execution node.
[0156] In an optional embodiment, the selection module 606 is further configured to:
[0157] calculate resource consumption information corresponding to the statement execution path, the first statement execution path and the second statement execution path respectively;
[0158] select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to the resource consumption information of each statement execution path and execute the target statement execution path.
[0159] In an optional embodiment, the selection module 606 is further configured to:
[0160] obtain execution information corresponding to the target statement execution path, and determine a scan row number according to the execution information;
[0161] update a statement selection state of the target statement execution path in a case where the scan row number is greater than a preset row number threshold.
[0162] In an optional embodiment, the selection module 606 is further configured to:
[0163] store the first statement execution path and the statement execution path to a path set;
[0164] eliminate the target index node to generate a second statement execution path, and store the second statement execution path to the path set in a case where a second statement syntax tree structure of the second statement execution path matches a preset reference syntax tree of the target database;
[0165] select a third statement execution path from the path set according to a path selection strategy and execute the third statement execution path.
[0166] In summary, in an embodiment of the present specification, when executing a target statement, a statement syntax tree is constructed based on a statement execution path corresponding to the target statement. In the case that a reference syntax tree preset by a target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path to generate a first statement execution path, and the target index node is removed to generate a second statement execution path. Thus, the first statement execution path not containing the index node and the second statement execution path not containing only the target index node are generated, the evolution of the statement execution path for the index node is implemented, and the statement execution path containing different index nodes is obtained. Then, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path and the second statement execution path according to the path selection strategy for execution, so as to improve the execution speed and reduce the resource consumption.
[0167] The above is a schematic scheme of a statement execution device according to an embodiment of the present specification. It should be noted that the technical scheme of the statement execution device belongs to the same concept as the technical scheme of the statement execution method described above. The details of the technical scheme of the statement execution device that are not described in detail can be referred to the description of the technical scheme of the statement execution method.
[0168] Referring to Figure 7 , Figure 7 A flowchart of a query method according to an embodiment of the present specification is shown. The query method is applied to the cloud side and specifically includes the following steps.
[0169] Step 702: receiving a query request submitted by an end side and determining a target statement based on the query request;
[0170] Step 704: constructing a statement syntax tree based on a statement execution path corresponding to the target statement, wherein the target statement is associated with a target database;
[0171] Step 706: in the case that a reference syntax tree preset by the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, removing the index node for the statement execution path to generate a first statement execution path, and removing the target index node to generate a second statement execution path;
[0172] Step 708: selecting a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy;
[0173] Step 710: executing the target statement execution path to obtain query information, and sending the query information as feedback of the query request to the end side.
[0174] In actual application, the cloud side can receive the query request submitted by the end side, and determine a target statement according to the query request. When the target statement is executed, a statement syntax tree is constructed based on the statement execution path corresponding to the target statement. In the case that the structure of the reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed, a second statement execution path is generated, so as to generate the first statement execution path not containing the index node, and the second statement execution path not containing only the target index node, so as to realize the evolution of the statement execution path for the index node, and obtain the statement execution path containing different index nodes. Then, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path and the second statement execution path according to the path selection strategy, and the query information obtained by executing the target statement execution path is sent to the end side. The execution speed can be improved, and the resource consumption can be reduced.
[0175] Corresponding to the method embodiments, the specification also provides query device embodiments, Figure 8 The structure of a query device provided by one embodiment of the specification is shown. As shown in Figure 8 The query device is applied to the cloud side, and the device comprises:
[0176] The receiving module 802 is configured to receive the query request submitted by the end side, and determine a target statement based on the query request.
[0177] The construction module 804 is configured to construct a statement syntax tree based on the statement execution path corresponding to the target statement, wherein the target statement is associated with a target database.
[0178] The generation module 806 is configured to remove the index node for the statement execution path, generate a first statement execution path, and remove the target index node, generate a second statement execution path, in the case that the structure of the reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node.
[0179] The selection module 808 is configured to select a target statement execution path from the statement execution path, the first statement execution path and the second statement execution path according to a path selection strategy.
[0180] The sending module 810 is configured to execute the target statement execution path to obtain query information, and send the query information as feedback of the query request to the end side.
[0181] An optional embodiment, the generation module 806 is further configured to:
[0182] pre-executing the target statement according to the statement execution path, obtaining target statement execution information;
[0183] in a case where it is determined based on the target statement execution information that the pre-execution back table row number of the target statement is greater than a preset back table row number threshold, taking the to-be-tested index node in the statement syntax tree as the target index node.
[0184] An optional embodiment, the generation module 806 is further configured to:
[0185] determining at least one execution condition node contained in the statement execution path, and a logical operation identifier associated with the at least one execution condition node;
[0186] determining target statement execution information of the target statement based on a preset logical operation rule, the at least one execution condition node and the logical operation identifier, and extracting the pre-execution back table row number in the target statement execution information.
[0187] An optional embodiment, the generation module 806 is further configured to:
[0188] determining a statement tree structure of the statement syntax tree, and a reference tree structure of a reference syntax tree preset by the target database;
[0189] in a case where the statement tree structure contains the reference tree structure, determining that the reference syntax tree preset by the target database matches the structure of the statement syntax tree.
[0190] An optional embodiment, the generation module 806 is further configured to:
[0191] determining an execution node contained in the statement execution path, and removing an index node in the execution node to obtain a first target execution node;
[0192] generating a first statement execution path based on the statement semantics of the target statement and the first target execution node.
[0193] An optional embodiment, the generation module 806 is further configured to:
[0194] determining an execution node contained in the statement execution path, and removing a target index node in the execution node to obtain a second target execution node;
[0195] generating a second statement execution path based on the statement semantics of the target statement and the second target execution node.
[0196] An optional embodiment, the selection module 808 is further configured to:
[0197] Calculate the execution path of the statement, and the resource consumption information corresponding to the first execution path and the second execution path, respectively;
[0198] Based on the resource consumption information of each statement execution path, the target statement execution path is selected and executed from the statement execution paths, the first statement execution path, and the second statement execution path.
[0199] In an optional embodiment, the selection module 808 is further configured to:
[0200] Obtain the execution information corresponding to the execution path of the target statement, and determine the number of lines to scan based on the execution information;
[0201] If the number of scanned lines exceeds a preset line count threshold, update the statement selection status of the target statement execution path.
[0202] In an optional embodiment, the selection module 808 is further configured to:
[0203] Store the first statement execution path and the statement execution path into a path set;
[0204] Remove the target index node, generate a second statement execution path, and if the reference syntax tree preset in the target database matches the second statement syntax tree structure of the second statement execution path, store the second statement execution path in the path set;
[0205] According to the path selection strategy, the third statement execution path is selected from the path set and executed.
[0206] In summary, the cloud side can receive query requests submitted by the client side and determine the target statement based on the query request. When executing the target statement, it constructs a statement syntax tree based on the execution path corresponding to the target statement. If the target database's preset reference syntax tree matches the statement syntax tree structure and the statement syntax tree contains the target index node, it removes the index node from the statement execution path to generate a first statement execution path, and removes the target index node to generate a second statement execution path. This generates a first statement execution path without index nodes and a second statement execution path that only lacks the target index node, thus achieving the evolution of the statement execution path based on index nodes to obtain statement execution paths containing different index nodes. Furthermore, it can select the target statement execution path with lower resource consumption from the statement execution path, the first statement execution path, and the second statement execution path according to the path selection strategy, and send the query information obtained from executing the target statement execution path to the client side. This improves execution speed and reduces resource consumption.
[0207] The above is a schematic scheme of the query device of the embodiment. It should be noted that the technical scheme of the query device and the technical scheme of the query method described above belong to the same concept. The details of the technical scheme of the query device that are not described in detail can be referred to the description of the technical scheme of the query method.
[0208] Figure 9 A structural schematic diagram of a query system according to one embodiment of the present specification is shown. As shown in the figure, the query system 900 includes a cloud side 910 and an end side 920; the end side 920 is configured to submit a query request to the cloud side 910; the cloud side 910 is configured to determine a target statement based on the query request; construct a statement syntax tree based on a statement execution path corresponding to the target statement, wherein the target statement is associated with a target database; in a case where a reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, remove the index node for the statement execution path, generate a first statement execution path, and remove the target index node to generate a second statement execution path; select a target statement execution path from the statement execution path, the first statement execution path, and the second statement execution path according to a path selection strategy; execute the target statement execution path to obtain query information, and send the query information as feedback of the query request to the end side 920. Figure 9
[0209] In actual application, the end side submits a query request to the cloud side, the cloud side determines a target statement according to the query request, and constructs a statement syntax tree based on a statement execution path corresponding to the target statement when executing the target statement. In a case where a reference syntax tree preset in the target database matches the structure of the statement syntax tree, and the statement syntax tree contains a target index node, the index node is removed for the statement execution path, a first statement execution path is generated, and the target index node is removed to generate a second statement execution path. Thus, the first statement execution path not containing the index node is generated, and the second statement execution path not containing only the target index node is generated. The evolution of the statement execution path for the index node is realized, and the statement execution path containing different index nodes is obtained. Further, the target statement execution path with less resource consumption can be selected from the statement execution path, the first statement execution path, and the second statement execution path according to the path selection strategy, and the query information obtained by executing the target statement execution path is sent to the end side. The execution speed can be improved, and the resource consumption can be reduced.
[0210] The above is a schematic scheme of the query system of the embodiment. It should be noted that the technical scheme of the query system and the technical scheme of the query method described above belong to the same concept. The details of the technical scheme of the query system that are not described in detail can be referred to the description of the technical scheme of the query method.
[0211] Figure 10 A structural block diagram of a computing device 1000 is shown, according to one embodiment of the present specification. The components of the computing device 1000 include, but are not limited to, a memory 1010 and a processor 1020. The processor 1020 is connected with the memory 1010 through a bus 1030, and a database 1050 is used to save data.
[0212] The computing device 1000 also includes an access device 1040, which enables the computing device 1000 to communicate via one or more networks 1060. Examples of these networks include the Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 1040 can include one or more of any type of network interface (e.g., a network interface card (NIC)), wired or wireless, such as an IEEE 802.11 Wireless Local Area Network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, Near Field Communication (NFC).
[0213] In one embodiment of the present specification, the above-mentioned components of the computing device 1000 and other components not shown in the Figure 10 may be connected with each other, for example, through a bus. It should be understood that Figure 10 The structural block diagram of the computing device shown is only for the purpose of example, and is not a limitation on the scope of the present specification. Other components can be added or replaced as needed by those skilled in the art.
[0214] The computing device 1000 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 1000 can also be a mobile or stationary server.
[0215] The processor 1020 is configured to execute computer-executable instructions to perform the steps of the above method.
[0216] The above is a schematic solution of the computing device of the embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above method belong to the same concept, and the details of the technical solution of the computing device that are not described in detail can be referred to the description of the technical solution of the above method.
[0217] An embodiment of the present specification further provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the steps of the above method.
[0218] The above is a schematic solution of the computer-readable storage medium of the embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the above method belong to the same concept, and the details of the technical solution of the storage medium that are not described in detail can be referred to the description of the technical solution of the above method.
[0219] An embodiment of the present specification further provides a computer program product, which includes a computer program or instructions, and the computer program or instructions are executed by a processor to implement the steps of the above method.
[0220] The above is a schematic solution of the computer program product of the embodiment. It should be noted that the technical solution of the computer program product and the technical solution of the above method belong to the same concept, and the details of the technical solution of the computer program product that are not described in detail can be referred to the description of the technical solution of the above method.
[0221] The above-described embodiments of the application have several aspects, no single one of which is solely responsible for the application's desirable attributes. Without limiting the scope of the application as expressed by the claims which follow, some further embodiments make these aspects even more useful. Other embodiments can result in less desirable attributes.
[0222] The computer readable medium can include any entity or apparatus capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, software distribution medium, etc. It should be noted that the computer readable medium can include appropriate contents according to the requirements of patent practice, for example, according to the patent practice in some regions, the computer readable medium does not include electrical carrier signals and telecommunication signals.
[0223] It should be noted that for the foregoing method embodiments, the acts described can be performed in a different order from that described, and that various embodiments can be combined in different ways. Further, it should be noted that the embodiments described are preferred embodiments, and that not all of the acts described are necessary to achieve the desired results. It should also be noted that the described embodiments are merely exemplary and that a person of ordinary skill in the art can devise other embodiments that are within the scope and spirit of the described embodiments.
[0224] In the above embodiments, the description of each embodiment is focused on different aspects, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0225] The preferred embodiments of the present specification disclosed above are only used to help explain the present specification. The alternative embodiments do not describe all the details and do not limit the application to the specific embodiments described. Obviously, according to the content of the embodiments of the present specification, many modifications and changes can be made. The present specification selects and describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present specification, so that those skilled in the art can well understand and use the present specification. The present specification is limited by the claims and their full scope and equivalents.
Claims
1. A statement execution method, comprising: A statement syntax tree is constructed based on the statement execution path corresponding to the target statement, wherein the target statement is associated with the target database; If the preset reference syntax tree of the target database matches the statement syntax tree structure, and the statement syntax tree contains the target index node, then the index node is removed from the statement execution path to generate a first statement execution path, and the target index node is removed to generate a second statement execution path. According to the path selection strategy, the target statement execution path is selected from the statement execution path, the first statement execution path, and the second statement execution path, and then executed.
2. The statement execution method according to claim 1, wherein determining the target index node in the statement syntax tree includes: Pre-execute the target statement according to the execution path to obtain the target statement execution information; If, based on the execution information of the target statement, it is determined that the number of rows to be returned to the table before execution of the target statement is greater than a preset threshold for the number of rows to be returned to the table, the index node to be tested in the statement syntax tree is taken as the target index node.
3. The statement execution method according to claim 2, wherein determining the number of rows to be returned to the target statement includes: Determine at least one execution condition node contained in the statement execution path, and the logical operation identifier associated with the at least one execution condition node; Based on preset logical operation rules, the at least one execution condition node and the logical operation identifier determine the target statement execution information of the target statement, and extract the number of pre-execution back table rows from the target statement execution information.
4. The statement execution method according to claim 1, wherein the structure of the preset reference syntax tree of the target database is matched with that of the statement syntax tree, including: Determine the statement tree structure of the statement syntax tree, and the reference tree structure of the preset reference syntax tree of the target database; If the statement tree structure contains the reference tree structure, it is determined that the structure of the target database's preset reference syntax tree matches that of the statement syntax tree.
5. The statement execution method according to claim 1, wherein removing index nodes from the statement execution path to generate a first statement execution path comprises: Determine the execution nodes included in the statement execution path, and remove the index nodes from the execution nodes to obtain the first target execution node; A first statement execution path is generated based on the statement semantics of the target statement and the first target execution node.
6. The statement execution method according to claim 1, wherein removing the target index node from the statement execution path to generate a second statement execution path comprises: Determine the execution nodes included in the statement execution path, and remove the target index node from the execution nodes to obtain the second target execution node; A second statement execution path is generated based on the statement semantics of the target statement and the second target execution node.
7. The statement execution method according to claim 1, wherein selecting and executing the target statement execution path according to the statement execution path, the first statement execution path, and the second statement execution path according to the path selection strategy comprises: Calculate the execution path of the statement, and the resource consumption information corresponding to the first execution path and the second execution path, respectively; Based on the resource consumption information of each statement execution path, the target statement execution path is selected and executed from the statement execution paths, the first statement execution path, and the second statement execution path.
8. The statement execution method according to claim 1, further comprising, after selecting and executing the target statement execution path according to the path selection strategy in the statement execution path, the first statement execution path, and the second statement execution path: Obtain the execution information corresponding to the execution path of the target statement, and determine the number of lines to scan based on the execution information; If the number of scanned lines exceeds a preset line count threshold, update the statement selection status of the target statement execution path.
9. The statement execution method according to claim 1, wherein the method after removing the index node from the statement execution path and generating the first statement execution path further includes: Store the first statement execution path and the statement execution path into a path set; Remove the target index node, generate a second statement execution path, and if the reference syntax tree preset in the target database matches the second statement syntax tree structure of the second statement execution path, store the second statement execution path in the path set; According to the path selection strategy, the third statement execution path is selected from the path set and executed.
10. A query method applied to the cloud side, comprising: The system receives query requests submitted by the receiving end and determines the target statement based on the query requests. A statement syntax tree is constructed based on the statement execution path corresponding to the target statement, wherein the target statement is associated with the target database; If the preset reference syntax tree of the target database matches the statement syntax tree structure, and the statement syntax tree contains the target index node, then the index node is removed from the statement execution path to generate a first statement execution path, and the target index node is removed to generate a second statement execution path. According to the path selection strategy, the target statement execution path is selected from the statement execution path, the first statement execution path and the second statement execution path; The target statement execution path is executed to obtain query information, and the query information is sent to the endpoint as feedback of the query request.
11. A statement execution device, comprising: The construction module is configured to construct a statement syntax tree based on the statement execution path corresponding to the target statement, wherein the target statement is associated with the target database; The generation module is configured to, when the preset reference syntax tree of the target database matches the statement syntax tree structure and the statement syntax tree contains the target index node, remove the index node for the statement execution path to generate a first statement execution path, and remove the target index node to generate a second statement execution path. The selection module is configured to select and execute a target statement execution path from the first statement execution path and the second statement execution path according to a path selection strategy.
12. A query system, comprising a cloud side and a terminal side; The endpoint is used to submit query requests to the cloud side; The cloud-side is used to determine the target statement based on the query request; and to construct a statement syntax tree based on the statement execution path corresponding to the target statement, wherein... The target statement is associated with the target database; If the preset reference syntax tree of the target database matches the statement syntax tree structure, and the statement syntax tree contains the target index node, then the index node is removed from the statement execution path to generate a first statement execution path, and the target index node is removed to generate a second statement execution path. A target statement execution path is selected from the statement execution path, the first statement execution path, and the second statement execution path according to a path selection strategy. The target statement execution path is executed to obtain query information, and the query information is sent to the endpoint as feedback to the query request.
13. A computing device, comprising: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions, which, when executed by the processor, implement the steps of the method according to any one of claims 1 to 10.
14. A computer-readable storage medium storing a computer program or instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 10.
15. A computer program product comprising a computer program or instructions which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 10.