SQL query processing method and device, computer equipment and storage medium

By converting SQL query statements into query trees and applying rewriting rules and cost evaluation, the performance degradation of traditional database SQL query optimization under data distribution changes and query mode diversification is solved, and more efficient query processing is achieved.

CN119621728APending Publication Date: 2025-03-14JINZHUAN INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411800393.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

Traditional database SQL query optimization relies on static rules and statistical information, and cannot effectively deal with changes in data distribution and diversification of query patterns, resulting in a decrease in query performance and processing efficiency.

Method used

By obtaining the pending SQL query statement, converting it into a query tree, determining the overwrite rule rewriting the query tree, generating the target query tree, and evaluating the target query tree at the cost. When the evaluation result satisfies the preset cost evaluation strategy, execute the corresponding SQL query statement.

Benefits of technology

The query performance and processing efficiency of the database are improved, and the query execution efficiency is optimized and resource consumption is reduced through precise cost estimation and intelligent query rewriting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621728A_ABST
    Figure CN119621728A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, and discloses an SQL query processing method and device, computer equipment and a storage medium, and the method comprises the steps: obtaining a to-be-processed SQL query statement, and converting the SQL query statement into a corresponding query tree; determining a rewriting rule, and performing rule rewriting on the query tree according to the rewriting rule to generate a target query tree; performing cost evaluation on the target query tree to generate an evaluation result; when the evaluation result meets a preset cost evaluation strategy, executing the SQL query statement according to the target query tree; therefore, the query performance and the processing efficiency of the database can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a SQL query processing method, device, computer equipment and computer-readable storage medium. Background Art

[0002] At present, with the development of database technology and the rapid increase in data volume, database SQL (Structured Query Language) query optimization has become a key technology in database management systems. At present, traditional database SQL query optimization mainly relies on static, pre-defined rules and statistical information, and the optimized SQL query is not cost-evaluated. This traditional method often performs poorly in situations where data distribution changes and query patterns are diversified, resulting in a decrease in database query performance and processing efficiency.

[0003] Based on this, how to provide a SQL query processing method, apparatus, computer device and computer-readable storage medium that can effectively improve the query performance and processing efficiency of the database is a problem that urgently needs to be solved by those skilled in the art. Summary of the invention

[0004] In view of the above-mentioned deficiencies in the prior art, the object of the present invention is to provide a SQL query processing method, apparatus, computer device and computer-readable storage medium, aiming to solve the problem of how to effectively improve the query performance and processing efficiency of the database.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] In a first aspect, the present invention provides a SQL query processing method, which includes:

[0007] Obtaining a SQL query statement to be processed, and converting the SQL query statement into a corresponding query tree;

[0008] Determine a rewriting rule, and rewrite the query tree according to the rewriting rule to generate a target query tree;

[0009] Performing cost evaluation on the target query tree to generate an evaluation result;

[0010] When the evaluation result satisfies the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree.

[0011] In a second aspect, the present invention provides a SQL query processing device, comprising:

[0012] A conversion module, used to obtain a SQL query statement to be processed and convert the SQL query statement into a corresponding query tree;

[0013] A rewriting module, used for determining a rewriting rule, and rewriting the query tree according to the rewriting rule to generate a target query tree;

[0014] An evaluation module, used to perform cost evaluation on the target query tree and generate an evaluation result;

[0015] An execution module is used to execute the SQL query statement according to the target query tree when the evaluation result satisfies a preset cost evaluation strategy.

[0016] In a third aspect, the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the SQL query processing method as described above when executing the computer program.

[0017] In a fourth aspect, the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program implements the SQL query processing method as described above when executed by a processor.

[0018] Compared with the prior art, the present invention provides a SQL query processing method, apparatus, computer device and computer-readable storage medium, wherein the SQL query statement to be processed is obtained and the SQL query statement is converted into a corresponding query tree; a rewriting rule is determined, and the query tree is rewritten according to the rewriting rule to generate a target query tree; a cost evaluation is performed on the target query tree to generate an evaluation result; when the evaluation result meets the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree; thereby the present invention can effectively improve the query performance and processing efficiency of the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 A schematic diagram of an application environment of a SQL query processing method provided by an embodiment of the present invention.

[0021] Figure 2A flowchart of a SQL query processing method provided by an embodiment of the present invention.

[0022] Figure 3 A schematic diagram of program modules of a SQL query processing device provided by an embodiment of the present invention.

[0023] Figure 4 A schematic diagram of the structure of a computer device provided by an embodiment of the present invention.

[0024] Figure 5 Another structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0027] It should also be understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0028] As used in the present specification and the appended claims, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0029] In addition, in the description of the present specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0030] References to "one embodiment" or "some embodiments" etc. described in the present specification mean that one or more embodiments of the present invention include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0031] It should be understood that the order of execution of the steps in the following embodiments does not imply a precedence of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0032] In order to illustrate the technical solution of the present invention, specific embodiments are provided below for illustration.

[0033] An SQL query processing method provided by an embodiment of the present invention can be applied in Figure 1 In the application environment shown, the client and the server communicate through the network. The client includes but is not limited to PDAs, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, cloud computing devices, personal digital assistants (PDAs) and other computer devices. The server can be an independent server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0034] See also Figure 2 An embodiment of the present invention provides a SQL query processing method, wherein the method comprises the following steps:

[0035] S100, obtaining a SQL query statement to be processed, and converting the SQL query statement into a corresponding query tree;

[0036] S200, determining a rewriting rule, and rewriting the query tree according to the rewriting rule to generate a target query tree;

[0037] S300, performing cost evaluation on the target query tree to generate an evaluation result;

[0038] S400: When the evaluation result satisfies a preset cost evaluation strategy, the SQL query statement is executed according to the target query tree.

[0039] In specific implementation, this embodiment systematically optimizes the performance and processing efficiency of database queries through a series of refined steps; first, by converting the SQL query statement to be processed into a query tree (step S100), the logical structure of the query can be deeply understood, providing a basis for subsequent rewriting; then, by applying the rewriting rules to rewrite the query tree (step S200), it is possible to explore a more efficient query plan while keeping the query semantics unchanged, which helps to reduce the resource consumption and time required for query execution; then, the target query tree is cost evaluated (step S300), allowing the cost of different query plans to be quantified, so as to select the execution plan with the lowest cost; finally, only when the evaluation result meets the preset cost evaluation strategy (step S400), the corresponding query plan will be executed, which ensures that the executed query plan is the best choice under the current database state. Overall, the method of this embodiment improves the efficiency of query execution and reduces resource consumption through accurate cost estimation and intelligent query rewriting, thereby effectively improving the query performance and processing efficiency of the database.

[0040] Furthermore, in one embodiment, the SQL query processing method, wherein the step S100, obtaining the SQL query statement to be processed and converting the SQL query statement into a corresponding query tree, specifically comprises the steps of:

[0041] Obtain the SQL query statement to be processed, and parse the SQL query statement into a plurality of tags;

[0042] Based on the several tags, the query tree corresponding to the SQL query statement is constructed.

[0043] In specific implementation, this embodiment converts high-level, text-based SQL query statements into low-level, structured query tree representations by parsing the SQL query statements to be processed into a number of tags and then constructing corresponding query trees based on these tags. This conversion not only makes the logical structure and semantics of the query statements clearer, but also provides an internal data structure that is easy to operate and analyze for subsequent query optimization and execution plan generation, thereby laying a foundation for the database system to understand and efficiently process complex SQL queries and improving the accuracy and efficiency of query processing.

[0044] The specific implementation process of the steps in this embodiment is roughly as follows:

[0045] 1. Lexical analysis

[0046] In this step, the SQL query statement to be processed is decomposed into a series of tokens, which are the smallest grammatical units that constitute the SQL query statement, such as keywords (SELECT, FROM, etc.), identifiers (table names, column names), operators (=, <, etc.) and other symbols (commas, brackets, etc.); the lexical analyzer is responsible for identifying these tokens and assigning them corresponding grammatical categories;

[0047] 2. Syntax analysis

[0048] Once the tokens are obtained, the parser will organize them into a hierarchical structure, namely the syntax tree, according to the syntax rules of the database. This tree structure can accurately represent the syntax structure of the SQL query statement. Each node represents a syntax element, and the connections between nodes represent the dependency and combination relationship between syntax elements.

[0049] 3. Semantic analysis

[0050] While or after building the syntax tree, the semantic analyzer checks the semantic correctness of the tokens to ensure that all identifiers (such as table names and column names) exist in the database and that the operations in the query comply with the semantic rules of the database. This step ensures the logical correctness of the query tree.

[0051] 4. Query tree construction

[0052] Based on the results of syntax tree and semantic analysis, the database system will build a query tree, which is a tree structure closer to the internal representation of the database. The query tree not only contains the syntax structure of the SQL query statement, but also contains semantic information, such as table connection methods, query conditions, etc., which provides a basis for subsequent query optimization.

[0053] Through the above process, this embodiment can convert a human-readable SQL query statement into a structured, semantically rich query tree, providing a solid foundation for subsequent query optimization and execution.

[0054] Further, in one embodiment, the SQL query processing method, wherein the step S200, determining a rewriting rule, and rewriting the query tree according to the rewriting rule to generate a target query tree, specifically comprises the steps of:

[0055] Selecting the rewriting rule from a preset rule library according to the structure and content of the query tree;

[0056] Rewrite the query tree according to the rewriting rule to generate an intermediate query tree;

[0057] The structure and content of the intermediate query tree are verified, and the target query tree is obtained when the verification passes.

[0058] Furthermore, the SQL query processing method, wherein the structure and content of the intermediate query tree are verified, and the target query tree is obtained when the verification passes, further comprises:

[0059] When the verification fails, the intermediate query tree is rewritten several times according to the rewriting rules until the verification passes or the number of rewriting times reaches a threshold, thereby obtaining the target query tree.

[0060] In specific implementation, this embodiment selects appropriate rewriting rules from a preset rule base, performs a series of rule rewriting on the query tree, generates an intermediate query tree, and verifies the correctness of the structure and content of the rewritten query tree, thereby achieving query optimization. This process not only improves query efficiency, but also ensures the optimality and accuracy of the query tree through an iterative rewriting and verification mechanism until a preset threshold is reached or verification is passed, thereby generating a high-quality target query tree and providing an execution plan with better performance for subsequent query execution.

[0061] The specific implementation process of the steps in this embodiment is roughly as follows:

[0062] 1. Rule base retrieval and matching

[0063] In this step, the possibly applicable rewriting rules are retrieved from the preset rule base according to the structure and content of the query tree; the rule base contains a variety of optimization strategies, such as selective derivation, connection order adjustment, subquery expansion, etc.; by analyzing the query tree, determine which rules may be effective for the current query tree;

[0064] 2. Apply rewrite rules

[0065] Once the applicable rewriting rules are determined, they will be applied to the query tree to perform rule rewriting. This process may involve modifying the structure of the query tree, adding or deleting nodes, etc. The purpose is to generate one or more new intermediate query trees, which are logically equivalent to the original query trees, but may be more efficient in execution.

[0066] 3. Intermediate query tree verification

[0067] After each rule rewrite, it is necessary to verify whether the structure and content of the intermediate query tree are correct; this includes checking the syntax correctness, semantic consistency, and compliance with database constraints of the intermediate query tree; if the verification passes, the intermediate query tree becomes the target query tree;

[0068] 4. Iterative rewriting and verification

[0069] If the verification of the intermediate query tree fails, it will be rewritten again according to the rewriting rules and then re-verified; this process will be iterated until the verification passes or the preset rewriting number threshold is reached; the iterative process ensures that even if the initial rewriting fails to generate a valid target query tree, there is a chance to find the correct solution through further rule rewriting;

[0070] 5. Determine the target query tree

[0071] Finally, when the intermediate query tree passes verification or the number of rewrites reaches a threshold, the final target query tree will be determined; this target query tree will be used for subsequent cost evaluation and query execution, and it represents the best query execution plan that can be found under the current database instance and conditions;

[0072] Through the above process, this embodiment ensures that the rewriting of the query tree not only complies with logical equivalence, but also provides better performance in actual execution, thereby improving the overall efficiency and effect of database query.

[0073] Furthermore, in one embodiment, the SQL query processing method, wherein the step S300, performing cost evaluation on the target query tree to generate an evaluation result, specifically comprises the steps of:

[0074] Construct cost assessment model;

[0075] The target query tree is used as input, and the evaluation result is generated through the cost evaluation model.

[0076] In specific implementation, this embodiment implements cost-effectiveness analysis of different execution plans by constructing a cost evaluation model and taking the target query tree as input. This process can quantify the expected cost of each possible execution plan in terms of resource consumption (such as CPU, memory, disk I / O, etc.) and generate detailed evaluation results. Through this quantitative analysis, the database system can identify which execution plan is most cost-effective under the current database state, thereby selecting a query execution strategy that is both fast and resource-saving, effectively improving query performance and overall resource utilization of the database.

[0077] The specific implementation process of the steps in this embodiment is roughly as follows:

[0078] 1. Collect statistical information

[0079] Before building a cost evaluation model, you need to collect database statistics, including the number of rows in the table, the selectivity of the index, the distribution of columns, etc. These statistics are crucial for accurately estimating the query cost because they provide data about the actual characteristics of the data and database objects.

[0080] 2. Build a cost assessment model

[0081] Based on the collected statistics, a cost evaluation model is constructed. This model usually contains a series of algorithms and formulas to estimate the cost of different query operations (such as table scans, index lookups, join operations, etc.). The model takes into account various resource consumption, including CPU time, memory usage, and disk I / O operations.

[0082] 3. Define cost assessment parameters

[0083] Define the cost parameters of various query operations in the cost evaluation model. These parameters may include I / O cost, CPU processing cost, network transmission cost, etc. The setting of these parameters is crucial to the accuracy of the model. They are usually based on the performance characteristics and historical statistical data of the database system.

[0084] 4. Enter the target query tree

[0085] Pass the target query tree as input to the cost evaluation model; the target query tree represents the optimized query logic and contains all necessary operations and data access paths, which is the basis for cost evaluation;

[0086] 5. Generate evaluation results

[0087] The cost evaluation model calculates the expected total cost of executing the target query tree based on the input target query tree and the defined cost parameters. This cost is a comprehensive indicator that reflects the various resource consumption required to execute the query. Finally, the model generates an evaluation result that can be used to compare the cost-effectiveness of different query plans.

[0088] Through the above process, this embodiment can provide a quantitative query cost evaluation for the database system, and help the database system select the best execution plan to optimize query performance and resource usage.

[0089] Further, in one embodiment, the SQL query processing method, wherein the step S400, when the evaluation result satisfies a preset cost evaluation strategy, executes the SQL query statement according to the target query tree, specifically comprises the steps of:

[0090] Comparing the evaluation result with the preset cost evaluation strategy, and when the evaluation result satisfies the cost evaluation strategy, executing the SQL query statement according to the target query tree;

[0091] The query results generated after executing the SQL query statement are output or displayed.

[0092] In specific implementation, this embodiment compares the evaluation results with the preset cost evaluation strategy to ensure that the corresponding SQL query statement is executed only when the evaluation results show that the cost-effectiveness of the execution plan meets expectations. This mechanism optimizes the decision-making process of query execution, improves the efficiency of query execution and the rationality of resource utilization. At the same time, by outputting or displaying query results, it also ensures the accessibility and visualization of query results, enhances the user experience, and enables the database system to respond to user query requests in a controllable and efficient manner and provide accurate data feedback.

[0093] The specific implementation process of the steps in this embodiment is roughly as follows:

[0094] 1. Comparison of evaluation results and strategies

[0095] In this step, the evaluation results generated by the cost evaluation model need to be compared with the cost evaluation strategies preset by the database administrator or the system. These strategies may include the maximum allowable cost, performance target, or other business logic-related considerations.

[0096] 2. Decision-making and execution plan

[0097] If the evaluation result meets the preset cost evaluation strategy, that is, the cost is within an acceptable range, the target query tree will be used as the execution plan; if the evaluation result does not meet the cost evaluation strategy, it may be necessary to re-optimize the query or select other alternative execution plans;

[0098] 3. Execute SQL query statements

[0099] Once the execution plan is determined, the database execution engine will execute the SQL query statement according to the instructions in the target query tree; this includes operations such as data retrieval, sorting, and joining, as well as possible index lookups and table scans;

[0100] 4. Generate query results

[0101] After executing a SQL query statement, the database will generate query results; these results may include data rows retrieved from the database, or the results of calculations and aggregation operations involved in the query;

[0102] 5. Output or display query results

[0103] Finally, the query results are output or displayed to the user; this may involve formatting the result set into a table, chart, or other user-readable format and displaying it through a user interface, or returning the result set to the caller in the form of an API response;

[0104] Through the above process, this embodiment ensures that the SQL query statement is executed only when the evaluation result meets the expected cost-effectiveness, and the result can be fed back to the user in a timely manner after the query is executed, thereby improving the efficiency of database query and user experience.

[0105] It can be seen from the above method embodiments that the SQL query processing method provided by the present invention includes: obtaining the SQL query statement to be processed, and converting the SQL query statement into a corresponding query tree; determining the rewriting rule, and rewriting the query tree according to the rewriting rule to generate a target query tree; performing cost evaluation on the target query tree to generate an evaluation result; when the evaluation result meets the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree. In this way, the query performance and processing efficiency of the database can be effectively improved through the method of the present invention.

[0106] It should be understood that, although the present application provides method operation steps as described in the embodiments or flowcharts, more or less operation steps may be included based on conventional or non-creative labor, and these operation steps are not necessarily performed in sequence according to the embodiment or flowchart. The order of steps listed in the embodiment or flowchart is only one way of executing the order of many steps, and does not represent the only execution order. It should be noted that there is not necessarily a certain order between the above steps. A person of ordinary skill in the art can understand from the description of the embodiment of the present invention that in different embodiments, the above steps may have different execution orders, that is, they may be executed in parallel, or they may be executed in exchange, etc. Moreover, at least a part of the steps in the embodiment or flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but may be executed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but may be executed in turn, alternately or synchronously with other steps or at least a part of the sub-steps or stages of other steps.

[0107] Based on the above method embodiment, please refer to Figure 3 Another embodiment of the present invention further provides a SQL query processing device, wherein the device comprises:

[0108] The conversion module 11 is used to obtain the SQL query statement to be processed and convert the SQL query statement into a corresponding query tree;

[0109] A rewriting module 12, used for determining a rewriting rule, and rewriting the query tree according to the rewriting rule to generate a target query tree;

[0110] An evaluation module 13, used to perform cost evaluation on the target query tree and generate an evaluation result;

[0111] The execution module 14 is used to execute the SQL query statement according to the target query tree when the evaluation result satisfies a preset cost evaluation strategy.

[0112] Furthermore, in one embodiment, the SQL query processing device, wherein the conversion module 11 is specifically used for:

[0113] Obtain the SQL query statement to be processed, and parse the SQL query statement into a plurality of tags;

[0114] Based on the several tags, the query tree corresponding to the SQL query statement is constructed.

[0115] Furthermore, in one embodiment, the SQL query processing device, wherein the rewriting module 12 is specifically used for:

[0116] Selecting the rewriting rule from a preset rule library according to the structure and content of the query tree;

[0117] Rewrite the query tree according to the rewriting rule to generate an intermediate query tree;

[0118] The structure and content of the intermediate query tree are verified, and the target query tree is obtained when the verification passes.

[0119] Furthermore, the SQL query processing device, wherein the structure and content of the intermediate query tree are verified, and the target query tree is obtained when the verification passes, further comprises:

[0120] When the verification fails, the intermediate query tree is rewritten several times according to the rewriting rules until the verification passes or the number of rewriting times reaches a threshold, thereby obtaining the target query tree.

[0121] Furthermore, in one embodiment, in the SQL query processing device, the evaluation module 13 is specifically used to:

[0122] Construct cost assessment model;

[0123] The target query tree is used as input, and the evaluation result is generated through the cost evaluation model.

[0124] Furthermore, in one embodiment, the SQL query processing device, wherein the execution module 14 is specifically used for:

[0125] Comparing the evaluation result with the preset cost evaluation strategy, and when the evaluation result satisfies the cost evaluation strategy, executing the SQL query statement according to the target query tree;

[0126] The query results generated after executing the SQL query statement are output or displayed.

[0127] It should be noted that in the embodiment of the device of the present invention, the information interaction, execution process and other contents between the above-mentioned modules are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the aforementioned method embodiment part and will not be repeated here.

[0128] Based on the above method embodiment, another embodiment of the present invention further provides a computer device, which may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the functions or steps of the SQL query processing method server side in any of the above method embodiments are implemented.

[0129] Based on the above method embodiment, another embodiment of the present invention further provides a computer device, which may be a client, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the functions or steps of the client side of the SQL query processing method in any of the above method embodiments are implemented.

[0130] Those skilled in the art will understand that Figure 4 and Figure 5 The structural schematic diagram shown in the figure is only a schematic diagram of a partial structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0131] The processor may be a CPU, or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor, or the processor may be any conventional processor, etc.

[0132] Among them, the memory includes a readable storage medium, an internal memory, etc., wherein the internal memory can be the memory of a computer device, and the internal memory provides an environment for the operation of an operating system and computer-readable instructions in the readable storage medium. The readable storage medium can be a hard disk of a computer device, and in other embodiments, it can also be an external storage device of a computer device, for example, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on a computer device. Further, the memory can also include both an internal storage unit of a computer device and an external storage device. The memory is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of a computer program, etc. The memory can also be used to temporarily store data that has been output or is to be output.

[0133] Based on the above method embodiments, another embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the SQL query processing method in any of the above method embodiments is implemented. The computer-readable storage medium may be non-volatile or volatile.

[0134] It should be noted that the above-mentioned functions or steps that can be implemented by the computer-readable storage medium or computer device, and the technical effects brought about by the functions / steps, can be found in the relevant descriptions in the aforementioned method embodiments. To avoid repetition, they will not be described one by one here.

[0135] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM). The disclosed memory components or memories of the operating environments described herein are intended to comprise one or more of these and / or any other suitable types of memory.

[0136] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, in the embodiment of the device of the present invention, only the division of the above-mentioned functional units and modules is used as an example. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned device can refer to the corresponding process in the above-mentioned method embodiment, which will not be repeated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0137] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0138] In the embodiments provided by the present invention, it should be understood that the disclosed devices / computer equipment and methods can be implemented in other ways. For example, the device / computer equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0139] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] It should be noted that if software tools or components other than those of the Company appear in the embodiments of the present application, they are only used for illustration and do not represent actual use. The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the above embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the above embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. A SQL query processing method, characterized in that: include: Obtaining a SQL query statement to be processed, and converting the SQL query statement into a corresponding query tree; Determine a rewriting rule, and rewrite the query tree according to the rewriting rule to generate a target query tree; Performing cost evaluation on the target query tree to generate an evaluation result; When the evaluation result satisfies the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree.

2. The SQL query processing method according to claim 1, characterized in that: The step of obtaining a SQL query statement to be processed and converting the SQL query statement into a corresponding query tree includes: Obtain the SQL query statement to be processed, and parse the SQL query statement into a plurality of tags; Based on the several tags, the query tree corresponding to the SQL query statement is constructed.

3. The SQL query processing method according to claim 1, characterized in that: The determining of the rewriting rules and rewriting the query tree according to the rewriting rules to generate a target query tree includes: Selecting the rewriting rule from a preset rule library according to the structure and content of the query tree; Rewrite the query tree according to the rewriting rule to generate an intermediate query tree; The structure and content of the intermediate query tree are verified, and the target query tree is obtained when the verification passes.

4. The SQL query processing method according to claim 3, characterized in that: The verifying the structure and content of the intermediate query tree and obtaining the target query tree when the verification passes, further comprises: When the verification fails, the intermediate query tree is rewritten several times according to the rewriting rules until the verification passes or the number of rewriting times reaches a threshold, thereby obtaining the target query tree.

5. The SQL query processing method according to claim 1, characterized in that: The performing cost evaluation on the target query tree to generate an evaluation result includes: Construct cost assessment model; The target query tree is used as input, and the evaluation result is generated through the cost evaluation model.

6. The SQL query processing method according to any one of claims 1 to 5, characterized in that: When the evaluation result satisfies the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree, including: The evaluation result is compared with the preset cost evaluation strategy, and when the evaluation result satisfies the cost evaluation strategy, the SQL query statement is executed according to the target query tree.

7. The SQL query processing method according to claim 6, characterized in that: When the evaluation result satisfies the preset cost evaluation strategy, the SQL query statement is executed according to the target query tree, further comprising: The query results generated after executing the SQL query statement are output or displayed.

8. A SQL query processing device, characterized in that: include: A conversion module, used to obtain a SQL query statement to be processed and convert the SQL query statement into a corresponding query tree; A rewriting module, used for determining a rewriting rule, and performing rule rewriting on the query tree according to the rewriting rule to generate a target query tree; An evaluation module, used to perform cost evaluation on the target query tree and generate an evaluation result; An execution module is used to execute the SQL query statement according to the target query tree when the evaluation result satisfies a preset cost evaluation strategy.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the SQL query processing method according to any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the SQL query processing method according to any one of claims 1 to 7 is implemented.