Query optimization method, electronic equipment, storage medium and program product
By transforming the database table join order optimization problem into a QUBO problem and utilizing quantum solution methods, the problem of high computational resource consumption in existing technologies is solved, achieving efficient and fast processing of database query optimization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD
- Filing Date
- 2026-03-23
- Publication Date
- 2026-04-21
AI Technical Summary
In existing database query optimization techniques, optimizing the table join order requires a large amount of classical computing resources, which is particularly inefficient when processing large-scale data. Furthermore, classical algorithms such as dynamic programming and genetic algorithms have bottlenecks in terms of computational complexity and memory utilization.
The optimization problem of table join order in the database is transformed into a quadratic unconstrained binary optimization (QUBO) problem and solved using quantum solution methods. By utilizing the principles of quantum superposition, quantum interference, and quantum entanglement, the consumption of classical computer resources is reduced. Quantum annealing, quantum approximation optimization algorithms, or variable quantum characteristic solution methods are used to determine the optimized table join order.
Quantum computing significantly reduces computational resource consumption, provides exponential speed improvements, solves the problems of high computational complexity and low efficiency in large-scale table join order problems, and improves query optimization efficiency and system performance.
Smart Images

Figure CN121901274A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of database querying, and more particularly to a query optimization method, electronic device, storage medium, and program product. Background Technology
[0002] In database query optimization, optimizing the table join order is a problem that all databases face when executing queries. Choosing the appropriate table join order to minimize query execution cost is a problem that every query optimizer must address. While some related technologies have proposed solutions based on classical computation to find the optimal table join order, these solutions all consume significant computational resources. Summary of the Invention
[0003] This application provides a query optimization method, an electronic device, a storage medium, and a program product.
[0004] The technical solution of this application embodiment is implemented as follows: This application provides a query optimization method, the method including: Based on the left deep tree, the optimization problem of table join order in the database is transformed into a quadratic unconstrained binary optimization (QUBO) problem; the relations in the left deep tree are the tables in the database. The QUBO problem is solved using quantum solving methods to obtain the connection relationships of the tables in the left deep tree; Based on the connection relationships of the tables in the left deep tree, the optimized table connection order is determined.
[0005] This application also provides an electronic device, which includes a processor and a memory for storing a computer program that can run on the processor; wherein the processor is used to run the computer program to perform any of the query optimization methods described above.
[0006] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements any of the query optimization methods described above.
[0007] This application also provides a computer program product, including a computer program or computer executable instructions, which, when executed by a processor, implements any of the above-described query optimization methods.
[0008] As can be seen, in this embodiment, the optimization problem of table join order in the database can be transformed into a QUBO problem that can be solved by quantum solution methods based on left deep trees. By solving the QUBO problem by quantum solution methods, the optimized table join order can be determined. Compared with the solution of finding the optimal table join order based on classical computing in related technologies, this can reduce the consumption of classical computer computing resources. Attached Figure Description
[0009] Figure 1 This is a schematic diagram of the framework of the database query optimization and acceleration system according to an embodiment of this application; Figure 2 A schematic diagram of the program execution logic of the quantum access layer provided in the embodiments of this application; Figure 3 This is a flowchart of the query optimization method according to an embodiment of this application; Figure 4 This is a schematic diagram of a left-hand deep tree structure according to an embodiment of this application; Figure 5 This is a flowchart illustrating a quantum solution method for solving the QUBO problem in an embodiment of this application. Figure 6 This is a flowchart illustrating the solution of the QUBO problem using another quantum solution method in an embodiment of this application; Figure 7 This is a schematic diagram of the query optimization device according to an embodiment of this application; Figure 8 This is a schematic diagram of the composition structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0010] In related technologies, database query optimization can be performed using a database query optimizer. Generally, the database query optimization process mainly includes several steps: parsing the query statement, query optimization, execution plan generation, and query execution. Parsing the query statement involves parsing the query syntax, converting it into an internal data structure so that the database system can understand the meaning of the query. Next, the query optimizer selects the best execution plan to execute the query most efficiently. Then, the execution plan generator generates a plan for actually executing the query based on the optimizer's selection. Finally, the generated execution plan is passed to the storage engine, which is responsible for actually executing the query and returning the results to the client.
[0011] When performing join operations on multiple tables in a database, the choice of join order can significantly impact query performance. Therefore, optimizing the table join order is a crucial optimization problem faced by all databases when executing queries. Choosing the appropriate join order to minimize query execution cost is a problem every query optimizer must address. Database query optimizers can solve this problem using various methods, aiming to find the join order with the lowest execution cost, thereby improving query efficiency. In practical applications, the database query optimizer needs to determine the table join order to minimize query execution time and resource consumption. For a database with n tables, the number of possible join orders is n!. As the number of tables increases, the number of possible join order combinations increases rapidly, making exhaustive search impractical.
[0012] When optimizing table join order involves more than two relations, the final result must consist of a tree of join steps, each with two inputs. The planner examines different possible join sequences to find the one with the lowest cost. Common optimization methods for table join order include dynamic programming, genetic algorithms, heuristic algorithms, cost estimation-based optimization methods, and machine learning. Dynamic programming finds the optimal solution by traversing all possible combinations of table join orders; Genetic Query Optimizer (GEQO) iteratively optimizes the query execution plan by simulating natural selection and genetic mutation to find the lowest-cost table join order; heuristic algorithms find approximate optimal solutions using empirical rules. Cost estimation-based optimization methods build cost models based on database statistics and system resource utilization to estimate the cost of each join order; machine learning algorithms build cost models through extensive training on multiple datasets, but even with large datasets, it's impossible to fully adapt to different scenarios and database types while maintaining high accuracy. Other authors have proposed other methods to optimize table join order, but these are all implemented on classical computers using classical algorithms or machine learning.
[0013] The first technical solution of the related technology discloses a quantum database query method, encryption / decryption method, and system. In this solution, the query data index value is encrypted using quantum key distribution technology and sent to a key encryption storage module. A quantum key generated in the key encryption storage module, based on quantum key distribution technology, is used to encrypt the stored quantum random number corresponding to the query data index value using a classical encryption algorithm as the decryption key, and then sent to a data encryption storage module. The encrypted data corresponding to the query data index value is obtained, and the encrypted data is decrypted using the decryption key to obtain the data corresponding to the data query request. Applying this solution improves the efficiency of quantum key management. This solution mainly uses quantum encryption or decryption technology to process the database query method.
[0014] The technical solutions offered by related technologies have several technical problems. While dynamic programming can guarantee global optimality when solving table join order problems, its computational complexity grows exponentially. As the number of tables increases, the consumption of computational resources and time costs increase dramatically. This is particularly evident when dealing with large-scale data, making the algorithm potentially infeasible in practical applications. Moreover, because it needs to store all possible subqueries and their costs, dynamic programming often consumes a large amount of memory resources, resulting in low resource utilization and potentially leading to system performance bottlenecks, especially when dealing with large datasets.
[0015] GEQO's planning process uses standard planner code to generate a plan for scanning individual relationships. A genetic approach is then used to develop the connection plan. Each candidate connection plan is represented as a sequence of basic relationships. Initially, some possible connection sequences are simply generated randomly. For each connection sequence considered, the standard planner code is invoked to estimate the cost of executing a query using that sequence. Connection sequences with lower estimated costs are considered better. The genetic algorithm discards the least fit candidates. New candidates are then generated by combining genes from better-fitting candidates, even by randomly selecting fragments from known low-cost connection sequences to create new sequences for consideration. This process is repeated until the number of connection sequences considered reaches a preset value. The best one found at any point in the search is then used to generate the final plan. In the current implementation, the fitness of each candidate connection sequence is estimated from zero by running the standard planner's connection selection and cost estimation code. Even if similar connection subsequences are used in different candidates, a significant amount of work is still required. Preserving the cost estimates of sub-connections could save considerable time in this case. However, the problem lies in avoiding unreasonably excessive memory consumption to preserve such a state.
[0016] It can be seen that the technical solutions of related technologies are all based on classical computation to find the optimal solution for table join order. These solutions inevitably consume resources such as memory and central processing unit (CPU) of classical computers, which can affect the normal execution of other processes when the computer is running multi-process tasks. Secondly, in scenarios involving large-scale table join order problems, classical computation methods still have certain disadvantages in terms of processing efficiency.
[0017] In view of the technical problems existing in related technologies, this application proposes technical solutions based on its embodiments.
[0018] In this embodiment, the optimization problem of table connection order can be solved based on quantum technology. This can be used to solve problems that are difficult to solve or have extremely high computational complexity using classical algorithms and machine learning. Quantum technology, based on principles such as quantum superposition, quantum interference, and quantum entanglement, can provide exponential speed improvements. Furthermore, solving problems using quantum computers reduces the consumption of computational resources on classical computers. Here, quantum computing, as a technology based on quantum theory, has become a prominent research field, attracting considerable attention across various sectors due to its potential to solve complex problems far exceeding the capabilities of classical computers. In related technologies, the field of quantum computing is divided into two main methods or architectures: quantum annealing and gate-based quantum computing. Quantum annealing computers (also known as adiabatic quantum computers) utilize quantum effects in physics for optimization calculations. A typical example is the quantum computer from D-Wave Corporation, which addresses specific domain problems by transforming them into annealing optimization problems and finding the optimal solution through quantum effects. General-purpose gate-based quantum computers are currently the focus of many companies' efforts, aiming to realize general-purpose quantum computers that can replace or collaborate with classical computers, achieving faster computing speeds and lower energy consumption, solving problems that classical computers cannot solve or compute.
[0019] The embodiments of this application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the embodiments provided herein are merely illustrative of the embodiments of this application and are not intended to limit the embodiments of this application. Furthermore, the embodiments provided below are some embodiments for implementing this application, and not all embodiments for implementing this application. Unless otherwise specified, the technical solutions described in the embodiments of this application can be implemented in any combination.
[0020] It should be noted that, in the embodiments of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a method or apparatus that includes a list of elements includes not only the elements expressly described, but also other elements not expressly listed, or elements inherent to implementing the method or apparatus. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other related elements (e.g., steps in the method or units in the apparatus, such as portions of circuitry, processors, programs, or software, etc.) in the method or apparatus that includes that element.
[0021] This application provides a query optimization method that can be implemented using a database query optimization acceleration system based on quantum technology. This system can offer a new solution to the problem of optimizing the table join order in databases. (Refer to...) Figure 1 The database query optimization and acceleration system includes a client module, a database service module, and a quantum acceleration service module. The quantum acceleration service module includes a data processing submodule and a quantum optimization submodule.
[0022] The client module is a tool for users to access the database service module. Its main functions are to facilitate users in performing database management, querying, data import / export, backup, and recovery operations. In the database query optimization and acceleration system, the client's role is to provide users with the functionality to execute query commands.
[0023] The database service module provides users with data storage, query, and retrieval functions. After users input query commands in Structured Query Language (SQL) on the client side, the database service module mainly performs steps such as parsing the query statement, query optimization, execution plan generation, and query execution during query processing and execution. The query optimization step can be implemented with the query optimizer. This system is mainly designed for the query optimization process, introducing a quantum access layer in the query optimization stage. The quantum access layer is integrated into the database service module as a submodule of the query optimizer. On the one hand, it is responsible for obtaining key information about query optimization issues in the database service module. On the other hand, it is responsible for connecting with the quantum acceleration service module, sending key information about query optimization issues to the quantum acceleration service module, and obtaining the sorting results of the table join order in the quantum acceleration service module, returning the sorting results to the query optimizer.
[0024] After the table join order problem in query optimization within the database service is generated, it is automatically transferred to the quantum access layer and solved by the quantum acceleration service module. The functionality of the quantum access layer can be implemented programmatically. (Refer to...) Figure 2In the program execution logic of the quantum access layer, the quantum access layer determines whether a connection can be established with the data processing submodule. If a connection cannot be established, the program exits and determines that the sorting result of the table join order cannot be returned. If a connection can be established with the data processing submodule, key information about the query optimization problem can be obtained from the query optimizer. In practical applications, the program can first create a socket and attempt to establish a connection with the data processing submodule (i.e., the data preparation end of the quantum acceleration service module). If the connection with the data processing submodule fails, the program exits and determines that the sorting result of the table join order cannot be returned. If a connection is successfully established with the data processing submodule, key information about the query optimization problem can be obtained.
[0025] For example, key information for query optimization may include table cardinality, join predicates, and predicate selectivity. Here, table cardinality can be the size of the table, such as the number of rows; join predicates define the connection between tables; and predicate selectivity can be the ratio of rows that satisfy the predicate conditions to the number of rows before filtering. In practical applications, table cardinality, join predicates, and predicate selectivity can be obtained sequentially.
[0026] After obtaining key information about the query optimization problem, the quantum access layer sends this information to the data processing submodule and waits for the submodule to return the sorting result of the table join order. Here, the quantum access layer can send the key information to the data processing submodule in the form of data packets. If the quantum access layer does not receive the sorting result of the table join order within a set time period, it exits the program and determines that it cannot return the sorting result. If the sorting result of the table join order is received within the set time period, the program exits and returns the sorting result to the query optimizer, which then hands it over to the execution plan generator for further processing.
[0027] In the program execution logic of the quantum access layer, when it is determined that the sorting result cannot be returned for the table join order, information indicating that the returned sorting result is empty can be sent to the query optimizer. In this case, a classic algorithm (such as dynamic programming algorithm) can be selected in the database service module for query optimization.
[0028] The data processing submodule of the quantum acceleration service module is responsible for modeling the quadratic unconstrained binary optimization (QUBO) of the query optimization problem, while the quantum optimization submodule of the quantum acceleration service module is responsible for solving the problem through quantum computing, thereby obtaining the sorting result of the table join order based on the solution result.
[0029] The query optimization method provided in this application includes a series of steps, but the query optimization method provided in this application is not limited to the steps described. Similarly, the query optimization device provided in this application includes a series of modules, but the device provided in this application is not limited to the modules explicitly described, and may also include modules that need to be set for obtaining relevant information or processing based on information.
[0030] Figure 3 This is a flowchart of the query optimization method according to an embodiment of this application, such as... Figure 3 As shown, the process includes: Step 301: Based on the left deep tree, the optimization problem of table join order in the database is transformed into a QUBO problem; the relations in the left deep tree are the tables in the database.
[0031] For example, this step can be implemented by the data processing submodule. In practical applications, when the data processing submodule is idle as a server, it waits for the quantum access layer to establish a connection. After the data processing submodule establishes a connection with the quantum access layer and obtains the data packets sent by the quantum access layer, it first parses the data packets to obtain the table cardinality information, join predicates, and predicate selectivity. Then, based on the parsed data, it transforms the optimization problem of the table join order in the database into a QUBO problem.
[0032] In this embodiment of the application, a left deep tree can be constructed based on tables in a database. A left deep tree is defined as having... A relationship and Based on the structure of the left deep tree, we can see that there are several connections. In a left-deep tree, the index of a relation can be used This indicates that the sequence number of the connection can be used. express. Figure 4 A structural diagram of an exemplary left-hand deep tree provided for embodiments of this application, referring to... Figure 4 Tables 1, 2, 3, and 4 represent four relationships. Figure 4 The left deep tree in the diagram includes connection 1, connection 2, and connection 3. A result set can be generated through connection 3.
[0033] Step 302: Solve the QUBO problem using quantum solving methods to obtain the connection relationships of the tables in the left deep tree.
[0034] Step 303: Determine the optimized table join order based on the join relationships of the tables in the left deep tree.
[0035] Here, the optimized table join order can be determined based on the join order between different tables in the left deep tree. For example, if table 1 is represented by relation A, table 2 by relation B, and table 3 by relation C, and if relation A is connected to relation C in the left deep tree, and the intermediate result (which could be a new relation) generated by connecting relation A and relation C is connected to relation B, then the optimized table join order can be considered to be table 1, table 3, and table 2.
[0036] In practical applications, steps 101 to 103 can be implemented based on a processor and a communication interface. The processor can be at least one of the following: Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), CPU, controller, microcontroller, and microprocessor.
[0037] As can be seen, in this embodiment, the optimization problem of table join order in the database can be transformed into a QUBO problem that can be solved by quantum solution methods based on left deep trees. By solving the QUBO problem by quantum solution methods, the optimized table join order can be determined. Compared with the solution of finding the optimal table join order based on classical computing in related technologies, this can reduce the consumption of classical computer computing resources.
[0038] For an implementation method that transforms the optimization problem of table join order in a database into a QUBO problem based on a left deep tree, in some embodiments, it is possible to determine the variables to be solved for each relation and each join in the left deep tree, where each variable is used to characterize whether the relation is a leaf node of the join; then, based on the variables to be solved, the optimization problem of table join order in the database is transformed into a QUBO problem.
[0039] Accordingly, solving the QUBO problem using quantum solving methods to obtain the connection relationships of the tables in the left deep tree can include: solving the QUBO problem using quantum solving methods to obtain the solution results of the variables to be solved, and using the solution results to represent the connection relationships of the tables in the left deep tree.
[0040] It can be seen that when each variable in the variables to be solved is used to characterize whether a relation is a leaf node of a connection, the variables to be solved can reflect the relationship between the relation and the connection. Therefore, after transforming the optimization problem of the table join order in the database into a QUBO problem based on the variables to be solved, the QUBO problem can be solved by quantum solution method, and the solution result reflecting the join relationship of the tables in the left deep tree can be obtained. Thus, the optimized table join order can be determined more accurately.
[0041] For an implementation that transforms the optimization problem of table join order in a database into a QUBO problem based on the variables to be solved, in some embodiments, the encoding cost of a left deep tree can be constructed based on the variables to be solved; then, based on the encoding cost of the left deep tree, the optimization problem of table join order in a database can be transformed into a QUBO problem.
[0042] Here, the variables to be solved can include ,variable Used to characterize relationships Is it a connection? The leaf nodes in the relation It is a connection In the case of leaf nodes, In relation Not a connection In the case of leaf nodes, .
[0043] For a join order to be encoded as a valid left-deep tree model, the left child variable assignment must satisfy the following two validity conditions: condition a and condition b. Condition a includes: the bottom join in the left-deep tree has 2 leaf nodes, and other joins have only one leaf node. For example, for Figure 4 In the left-deep tree, connection 3 has two leaf nodes, namely table 1 and table 2. Connections 2 and 1 each have only one leaf node: the leaf node of connection 2 is table 3, and the leaf node of connection 1 is table 4. Condition b includes: each relation in the left-deep tree can only be used as... A leaf node of one of the connections.
[0044] Energy values can be constructed based on condition a. , The expression for is formula (1).
[0045] (1) Among them, when hour, ;when hour, In order to achieve the energy value Minimize, In the expression The interior and must correspond to Only then can condition a be satisfied, at which point the energy value... The value is 0, which shows that in order to achieve the energy value Minimization requires activating the correct number of variables. .
[0046] In order to achieve energy value Minimizing the relation ensures that each connection has the correct number of relations; however, condition a does not guarantee that each relation belongs to only one leaf node of a connection. For example, a relation may be a leaf node of two connections simultaneously. In this case, energy values can be encoded according to condition b. , The expression for is formula (2).
[0047] (2) It is evident that in order to achieve the energy value Minimizing this will force each relation to only be a leaf node in a connection, based on one-hot encoding, requiring... The inner term of the expression is 0, otherwise The calculated results of the inner terms are all greater than 0, and their contribution to the total energy is positive.
[0048] according to and The coding cost of constructing a left-deep tree , The expression for is formula (3).
[0049] (3) It can be seen that when each variable in the variables to be solved is used to characterize whether a relation is a leaf node of a connection, the variables to be solved can reflect the relationship between relations and connections. Thus, the encoding cost of the left deep tree constructed based on the variables to be solved can reflect the relationship between relations and connections in the left deep tree. Therefore, based on the encoding cost of the left deep tree, the optimization problem of table join order in the database can be reasonably transformed into a QUBO problem.
[0050] For implementations that transform the optimization problem of table join order in a database into a QUBO problem based on a left deep tree, in some embodiments, the encoding cost of the left deep tree can be constructed, and the encoding cost based on the join predicate can be determined; then, based on the encoding cost of the left deep tree and the encoding cost based on the join predicate, the optimization problem of table join order in the database can be transformed into a QUBO problem.
[0051] As can be seen, the relations in the left deep tree are tables in the database, and the join predicate is used to define the relationship between the tables. Therefore, based on the encoding cost of the left deep tree and the encoding cost based on the join predicate, the relationship between the tables in the database can be determined relatively accurately. That is, based on the encoding cost of the left deep tree and the encoding cost based on the join predicate, the optimization problem of the table join order in the database can be transformed into a QUBO problem relatively accurately.
[0052] In some embodiments, the encoding cost based on the join predicate can be determined after obtaining the join predicate, based on the two relations associated with the join predicate.
[0053] When cost-encoding the join relationships between tables in a database, information about the join relationships and join predicates is needed; the former is already defined by variables. The following example illustrates how to determine the encoding cost based on information from the connection predicate.
[0054] Define variables ,variable and variables .variable Indicates connecting predicates (connecting predicates) Whether it can be applied to the connection can be determined based on the predicate returned by the quantum access layer. .variable Representational Relationship Is it a connection? operands, if relation It is a connection The operands, then If the relationship Not a connection The operands, then For variables ,relation It can be a leaf node in the left-hand graph, or a new relation (i.e., an intermediate result) generated by joining two relations; when the relation It is a connection When the leaf node is, the relationship It is a connection Operands, in addition, connections Operands can also include new relations created by joining two relations, for example, for Figure 4 In the left deep tree shown, the new relation generated by join 3 between Tables 1 and 2 is also an operand of join 2. Variables subscript The value can be 1 or 2. Indicates the conjunction of predicates The associated first A relationship.
[0055] To ensure variables The validity of the clause is enforced only when it is used with a connecting predicate. Both related relations are joins. Only when operands are used can this be achieved. This constraint can be defined by the constraint terms. In practice, the encoding cost based on connect predicates can include constraint terms. Constraints The expression can be formula (4).
[0056] (4) According to the constraints It can be seen that without activation and In this case, set This will result in punishment.
[0057] Understandably, the two relations associated with a join predicate can further reflect the relationships between tables in the database. Therefore, based on the two relations associated with a join predicate, the encoding cost based on the join predicate can be determined reasonably.
[0058] For the implementation of determining the encoding cost based on the join predicate for two relations associated with the join predicate, in some embodiments, the encoding cost based on the join predicate can be determined based on the two relations associated with the join predicate, the pre-acquired table cardinality information, and the pre-acquired predicate selectivity; wherein, the table cardinality information is used to characterize the size of the table.
[0059] As can be seen, the embodiments of this application can more accurately determine the encoding cost based on join predicates by considering the size of the tables in the database, the encoding cost based on join predicates, and the predicate selectivity from multiple dimensions.
[0060] For example, based on variables and variables You can get a connection. logarithmic intermediate base , The expression for is formula (5).
[0061] (5) in, It is a relationship The base number, It is a connecting predicate The selectivity can be determined based on the predicate selectivity returned by the quantum access layer. Indicates the number of connecting predicates. For relationship The logarithmic cardinality, For connecting predicates The coefficient of logarithmic selectivity.
[0062] Define variables ,variable Indicates connection The first Does the logarithm of each intermediate result exceed the logarithmic threshold? Log threshold Indicates the first Threshold The logarithm of . If connected The first The logarithm of the intermediate results exceeds the logarithmic threshold. ,but If the connection The first The logarithm of each intermediate result did not exceed the logarithmic threshold. ,but ,here, , .
[0063] If connected The first The logarithm of the intermediate results exceeds the logarithmic threshold. Then the corresponding threshold term will be... Add to total energy. Threshold item. The expression for is formula (6).
[0064] (6) By using the inequality constraint shown in formula (7), it is ensured that if the connection... The first The logarithm of the intermediate results exceeds the logarithmic threshold. Time makes .
[0065] (7) if Greater than The only way to satisfy the inequality constraint is to activate the variable. , in constant When large enough minus By adding continuous variables, the above inequality can be transformed into the equation shown in formula (8).
[0066] (8) Since QUBO only supports binary variables and not continuous variables, it is necessary to convert the variables... It is represented by the binary expression shown in formula (9).
[0067] (9) in, For two variables, in formula (9) The value ranges from 1 to , Represents the number of binary bits. (Used...) It can be used for continuous variables Discrete representation is performed. Equals 0.1 , indicating discrete precision. It refers to the allowed number of decimal places.
[0068] Based on formula (8), it can be seen that in order to better control the activation variable The value of has constraints. Constraints The expression can be formula (10). (10) The encoding cost based on connective predicates can include .
[0069] The total energy can be constructed based on the encoding cost of the left deep tree and the encoding cost based on the connection predicate. The expression for total energy. The expression can be formula (11).
[0070] (11) in, This represents the penalty coefficient. It can be seen that the total energy... The expression is made up of user-defined variables. , , , ,as well as The QUBO formula is composed of these components.
[0071] After modeling the QUBO problem based on the QUBO formula, the QUBO matrix can be passed into the quantum optimization submodule for solving.
[0072] After obtaining the solution results, the quantum optimization submodule can retrieve each binary variable from the solution results. The value is then used to generate the sorted results of the relations. For example, the relations in the left deep tree include relation A, relation B, relation C, join 1, and join 2. If , , , , , It can be seen that relation A connects to relation C, and the intermediate result generated after connecting relation A and relation C connects to relation B. Therefore, the sorting result of the relations is relation A, relation C and relation B.
[0073] In some embodiments, the QUBO problem can be solved using quantum methods to obtain the connectivity relationships of the left-side deep tree table. This can be achieved by employing at least one of the following methods: quantum annealing, quantum approximate optimization (AQOA), and variational quantum eigensolver (VQE). Therefore, accurate solutions to the QUBO problem can be obtained by using quantum annealing, quantum approximate optimization, or variational quantum eigensolver methods.
[0074] In practical applications, the quantum optimization submodule is responsible for solving the QUBO matrix transmitted from the data processing module using a quantum solution method within the quantum computer. (Refer to...) Figure 1 The quantum optimization module is designed with three quantum solution services: quantum annealing solution service, QAOA algorithm solution service, and VQE algorithm solution service. Among them, the quantum annealing solution service is implemented based on a quantum annealing computer, while the QAOA algorithm solution service and VQE algorithm solution service are implemented based on classical computers and general-purpose gate quantum computers.
[0075] The following examples illustrate the quantum annealing solution service, the QAOA algorithm solution service, and the VQE algorithm solution service.
[0076] When using the quantum annealing solution service, the input parameter of the quantum annealing computer is the QUBO matrix. Therefore, the QUBO problem can be directly input into the quantum annealing computer to solve the QUBO problem and return the binary solution of the QUBO variables, and finally return it to the data processing submodule. A typical quantum annealing computer can be D-Wave or other computers.
[0077] The QAOA algorithm solution service is a method for solving the QUBO model of the join-sorting problem based on the QAOA algorithm. (Refer to...) Figure 5It can be seen that the quantum computing process is implemented based on a universal gate-based quantum computer. The process of solving the QUBO problem using the QAOA algorithm solution service includes: first, preparing an initial state, and then initializing the parameters, including parameters β and γ. After initializing the parameters, a quantum circuit is generated. Here, the angle parameters in the quantum circuit can be determined based on the initialized parameters, thus generating the quantum circuit. Then, the quantum state is measured after running the quantum circuit. In the classical computer processing flow, the expected value can be calculated. For example, based on the measurement results of the quantum state and the connection ordering problem, the expected energy value of the QUBO problem energy formula can be solved and summed. After calculating the expected value, the current expected value is passed to the classical optimizer for optimization to obtain a new set of parameters. Finally, the quantum computing process and the classical computer processing flow are repeated until the termination condition is met (for example, the expected energy value can converge, i.e., the minimum energy state). After the termination condition is met, the result of the quantum measurement at the minimum energy state is output. This result is the binary solution to the QUBO problem, and the solution is finally returned to the data processing submodule.
[0078] VQE Algorithm Solution Service: The VQE algorithm implementation provides a method for solving the QUBO model of the join sorting problem. (Refer to...) Figure 6 It can be seen that the quantum computing process is implemented based on a universal gate quantum computer. The process of solving the QUBO problem using the QAOA algorithm solution service includes: first, initial state preparation, and then test state preparation based on the ansatz selected in VQE. After test state preparation, the average energy of the test state is measured. In the classical computer processing flow, the expected energy value of the QUBO problem can be solved and summed based on the measurement result and the connection ordering problem. It is then determined whether the difference between the current calculated expected energy value and the previous calculated expected energy value is less than the energy difference threshold. If not, the parameters are optimized using the optimizer (i.e., a new set of parameters is generated), and the process returns to the test state preparation step. The quantum computing process and the classical computer processing flow are repeated until the difference of the expected energy value is less than the energy difference threshold. This means that the expected energy has converged, i.e., reached the minimum state. At this point, the quantum measurement result at the minimum energy state can be output, which is the binary solution to the QUBO problem. Finally, the solution result is returned to the data processing submodule.
[0079] In related technologies, handling large-scale join ordering problems in database query optimizers requires significant computational resources. To address this issue, this application proposes a quantum acceleration system for database query optimization based on quantum technology. In the QUBO problem modeling method for join ordering proposed in this application, during the QUBO modeling stage, a new QUBO modeling approach is defined to satisfy an efficient left-deep tree structure. This approach not only supports quantum computer solutions but also guarantees the generation of an efficient ordering solution.
[0080] Compared with the technical solutions of related technologies, the solutions of this application have at least the following advantages: 1) While related technologies offer solutions for optimizing table join order, these solutions often suffer from high computational complexity when dealing with large-scale join sorting problems, potentially leading to excessively long solution times and low query efficiency. However, this application's embodiment addresses the difficulty in determining table join order or the extremely high computational complexity inherent in related technologies. Quantum technology, based on principles such as quantum superposition, quantum interference, and quantum entanglement, can provide exponential speed improvements. Furthermore, solving the problem using quantum computers reduces the consumption of computational resources on classical computers.
[0081] 2) Compared to heuristic algorithms, the embodiments of this application are based on quantum annealing technology and quantum tunneling effect. By controlling the Hamiltonian of the system, interactions are established between qubits, enabling the qubits to tunnel through energy barriers and search for optimal solutions in the solution space. This overcomes the shortcoming of heuristic algorithms in guaranteeing global optimality. Moreover, quantum annealing does not depend on specific rules or data distributions and can provide stable optimization performance under different datasets and query scenarios, thereby improving the overall reliability of the system.
[0082] 3) Compared to machine learning algorithms, in this embodiment, the parallel processing capability of a quantum computer enables it to handle large-scale database join problems and directly evaluate the optimality of table join order with less reliance on cost models. Machine learning algorithms, on the other hand, may require more computing resources and time when processing large-scale data.
[0083] The embodiments of this application have broad application prospects. For example, they can be applied in the following scenarios: 1) Integrating quantum technology into database products to enhance performance. The application of quantum technology in the database field helps database products adapt to market demands more quickly, develop new products and services, meet ever-changing customer needs, save users time and costs, and improve user experience.
[0084] 2) Promote among frontline operations and maintenance personnel. Provide it to database operations and maintenance engineers as a database plugin product to assist them in handling complex database query problems and greatly improve their work efficiency.
[0085] 3) Reduced computational resource consumption. Solving database problems using quantum computers reduces reliance on traditional computing resources, helping users optimize resource utilization. Processing complex queries using classical computing may require significant computational resources and time, while quantum accelerators can complete the same task in a shorter time, thus reducing hardware costs and energy consumption, and saving resource costs.
[0086] 4) Enhance enterprise competitiveness. Database optimization directly impacts the performance of core enterprise applications, such as e-commerce, financial transactions, and real-time data analysis. The solution adopted in this application embodiment can achieve faster and more efficient query optimization, thereby improving user satisfaction.
[0087] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0088] Based on the query optimization method proposed in the foregoing embodiments, this application also proposes a query optimization device, such as... Figure 7 As shown, the device includes: The first processing module 701 is used to transform the optimization problem of table join order in the database into a QUBO problem based on a left deep tree; the relations in the left deep tree are the tables in the database. The second processing module 702 is used to solve the QUBO problem using a quantum solution method to obtain the connection relationship of the tables in the left deep tree; and to determine the optimized table connection order based on the connection relationship of the tables in the left deep tree.
[0089] In some embodiments, the first processing module 701, based on a left-deep tree, transforms the optimization problem of table join order in the database into a QUBO problem, including: Determine the variables to be solved for each relation and each connection in the left deep tree, where each variable is used to characterize whether the relation is a leaf node of the connection; Based on the variables to be solved, the optimization problem of table join order in the database is transformed into a QUBO problem; The second processing module 702 solves the QUBO problem using a quantum solution method to obtain the connection relationships of the tables in the left deep tree, including: The QUBO problem is solved using quantum solving methods to obtain the solution results for the variables to be solved. These solution results are used to represent the connection relationships of the tables in the left deep tree.
[0090] In some embodiments, the first processing module 701, based on the variables to be solved, transforms the optimization problem of table join order in the database into a QUBO problem, including: Based on the variables to be solved, construct the encoding cost of the left deep tree; Based on the encoding cost of the left deep tree, the optimization problem of table join order in the database is transformed into a QUBO problem.
[0091] In some embodiments, the first processing module 701, based on a left-deep tree, transforms the optimization problem of table join order in the database into a QUBO problem, including: Construct the encoding cost of the left deep tree and determine the encoding cost based on the join predicate; the join predicate is used to define the association relationship between tables; Based on the encoding cost of the left deep tree and the encoding cost based on the join predicate, the optimization problem of table join order in the database is transformed into a QUBO problem.
[0092] In some embodiments, the first processing module 701 determines the encoding cost based on the join predicate, including: after obtaining the join predicate, determining the encoding cost based on the two relations associated with the join predicate.
[0093] In some embodiments, the first processing module 701 determines the encoding cost based on the connection predicate based on the two relations associated with the connection predicate, including: The encoding cost based on the two relations associated with the join predicate, the pre-acquired table cardinality information, and the pre-acquired predicate selectivity is determined; wherein the table cardinality information is used to characterize the size of the table.
[0094] In some embodiments, the second processing module 702 solves the QUBO problem using a quantum solution method to obtain the connection relationships of the tables in the left deep tree, including: The QUBO problem is solved by employing at least one of the following methods: quantum annealing, quantum approximation optimization, and variable quantum characteristic solving, thereby obtaining the connection relationships of the tables in the left deep tree.
[0095] In practical applications, the first processing module 701 and the second processing module 702 can be implemented based on a processor and a communication device.
[0096] It should be noted that the descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0097] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a terminal, server, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0098] Correspondingly, this application embodiment further provides a computer program product, the computer program product including computer executable instructions, which are used to implement any of the query optimization methods provided in this application embodiment.
[0099] Accordingly, this application embodiment further provides a computer storage medium storing computer-executable instructions, which are used to implement any of the query optimization methods provided in the above embodiments.
[0100] This application also provides an electronic device. Figure 8 This is a schematic diagram of the composition structure of an electronic device provided in an embodiment of this application, as shown below. Figure 8 As shown, the electronic device 80 may include: Memory 801 is used to store executable instructions; The processor 802 is used to implement any of the above-mentioned query optimization methods when executing executable instructions stored in the memory 801.
[0101] The processor 802 mentioned above can be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor.
[0102] The aforementioned computer-readable storage medium and memory 801 may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM), etc.; or it may be various terminals including one or any combination of the above-mentioned memories, such as mobile phones, computers, tablet devices, personal digital assistants, etc.
[0103] In some embodiments, the functions or modules of the apparatus provided in this application can be used to perform the methods described in the above method embodiments. The specific implementation can be referred to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0104] The description of the various embodiments above tends to emphasize the differences between the various embodiments. The similarities or similarities between them can be referred to, and for the sake of brevity, they will not be repeated here.
[0105] The methods disclosed in the various method embodiments provided in this application can be arbitrarily combined to obtain new method embodiments without conflict.
[0106] The features disclosed in the various product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0107] The features disclosed in the various method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0108] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0109] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims. All of these forms are within the protection scope of this application.
Claims
1. A query optimization method, characterized in that, The method includes: Based on the left deep tree, the optimization problem of table join order in the database is transformed into a quadratic unconstrained binary optimization (QUBO) problem; the relations in the left deep tree are the tables in the database. The quadratic unconstrained binary optimization QUBO problem is solved using quantum solving methods to obtain the connection relationships of the tables in the left deep tree; Based on the connection relationships of the tables in the left deep tree, the optimized table connection order is determined.
2. The method according to claim 1, characterized in that, The method based on left-deep trees transforms the optimization problem of table join order in the database into a quadratic unconstrained binary optimization (QUBO) problem, including: Determine the variables to be solved for each relation and each connection in the left deep tree, where each variable is used to characterize whether the relation is a leaf node of the connection; Based on the variables to be solved, the optimization problem of the table join order in the database is transformed into the quadratic unconstrained binary optimization QUBO problem; The process of solving the quadratic unconstrained binary optimization QUBO problem using quantum solving methods yields the connection relationships of the tables in the left deep tree, including: The quadratic unconstrained binary optimization QUBO problem is solved using a quantum solution method to obtain the solution results for the variables to be solved. These solution results are used to represent the connection relationships of the tables in the left deep tree.
3. The method according to claim 2, characterized in that, The process of transforming the optimization problem of table join order in the database into the quadratic unconstrained binary optimization (QUBO) problem based on the variables to be solved includes: Based on the variables to be solved, construct the encoding cost of the left deep tree; Based on the encoding cost of the left deep tree, the optimization problem of the table join order in the database is transformed into the quadratic unconstrained binary optimization (QUBO) problem.
4. The method according to claim 1, characterized in that, The optimization problem of table join order in the database based on left deep trees is transformed into the quadratic unconstrained binary optimization (QUBO) problem, including: Construct the encoding cost of the left deep tree and determine the encoding cost based on the join predicate; the join predicate is used to define the association relationship between tables; Based on the encoding cost of the left deep tree and the encoding cost based on the join predicate, the optimization problem of the table join order in the database is transformed into the quadratic unconstrained binary optimization (QUBO) problem.
5. The method according to claim 4, characterized in that, The determination of the encoding cost based on the join predicate includes: after obtaining the join predicate, determining the encoding cost based on the two relations associated with the join predicate.
6. The method according to claim 5, characterized in that, Determining the encoding cost based on the two relations associated with the join predicate includes: The encoding cost based on the two relations associated with the join predicate, the pre-acquired table cardinality information, and the pre-acquired predicate selectivity is determined; wherein the table cardinality information is used to characterize the size of the table.
7. The method according to any one of claims 1 to 6, characterized in that, The process of solving the quadratic unconstrained binary optimization QUBO problem using quantum solving methods yields the connection relationships of the tables in the left deep tree, including: The quadratic unconstrained binary optimization (QUBO) problem is solved by employing at least one of the following methods: quantum annealing, quantum approximation optimization, and variable quantum characteristic solving, thereby obtaining the connection relationships of the tables in the left deep tree.
8. An electronic device, characterized in that, The electronic device includes a processor and a memory for storing computer programs capable of running on the processor; wherein, The processor is used to run the computer program to perform the method according to any one of claims 1 to 7.
9. A computer storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the method described in any one of claims 1 to 7.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Quantum method and device for processing database multi-query optimization and storage medium
CN121681591A
System for implementing a data driven channel for query executions using quantum computing
US20230244663A1
Cited By
A single-path traffic transmission optimization method and system for complex network
CN122137773A
A single-path traffic transmission optimization method and system for complex network
CN122137773B