A data query method and device, a storage medium and an electronic device

CN115391426BActive Publication Date: 2026-10-16ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211043590.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-29
Publication Date
2026-10-16
Estimated Expiration
2042-08-29

AI Technical Summary

Technical Problem

[0004]本说明书提供一种数据查询方法、装置、存储介质及电子设备,以解决现有技术存在的数据库查询数据效率低的问题

Benefits of technology

[0040]The data query method provided in this specification first obtains the query statement input by the user. The query statement is used to query data from the database. Based on the query statement, an execution plan corresponding to the query statement is generated. Based on the execution plan, the various query operations involved in the execution plan and the execution order of the various query operations are determined. Based on the execution order of the various query operations, the target operation is determined from the various query operations. The target operation is the operation other than the last query operation executed among the various query operations. When executing the execution plan, the duplicate results contained in the query results obtained by executing the target operation are deduplicated. Based on the deduplicated query results, the query data corresponding to the query statement is obtained.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115391426B_ABST
    Figure CN115391426B_ABST
Patent Text Reader

Abstract

The specification discloses a data query method and device, a storage medium and an electronic device. The method can determine which query results of query operations in an execution plan to deduplicate according to the order of execution of the query operations involved in the execution plan generated when a query statement is executed by a database, can reduce the amount of tasks when the database executes subsequent query operations, and can deduplicate the query results of the determined query operations, thereby improving the efficiency of database data query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of computer technology, and in particular to a data query method, apparatus, storage medium, and electronic device. Background Technology

[0002] Graph databases are a widely used type of database for storing data such as private information and business data. In a graph database, data is stored as nodes and edges, which facilitates the description of relationships between data entities. For example, if you need to save information about the employees of a company, you can save the information of each employee in the company to their respective nodes (one employee's information is saved to one node). The relationship between any two employees (e.g., colleague relationship, supervisor relationship, etc.) can be represented by the edge between the two nodes corresponding to those two employees.

[0003] However, currently, users often experience low efficiency when querying data in graph databases. Summary of the Invention

[0004] This specification provides a data query method, apparatus, storage medium, and electronic device to solve the problem of low efficiency in database data query in the prior art.

[0005] The following technical solution is adopted in this specification:

[0006] This manual provides a data query method, including:

[0007] Obtain the query statement input by the user, which is used to retrieve data from the database;

[0008] Based on the query statement, generate the execution plan corresponding to the query statement;

[0009] Based on the execution plan, determine each query operation involved in the execution plan and the order in which each query operation is executed;

[0010] Based on the order in which the query operations are executed, a target operation is determined from the query operations. The target operation is the operation other than the last query operation executed.

[0011] When executing the execution plan, duplicate results in the query results obtained from executing the target operation are deduplicated, and the query data corresponding to the query statement is obtained based on the deduplicated query results.

[0012] Optionally, based on the query statement, an execution plan corresponding to the query statement is generated, specifically including:

[0013] The query statement is parsed to obtain the syntax tree corresponding to the query statement;

[0014] Based on the syntax tree, an execution plan corresponding to the query statement is generated.

[0015] Optionally, the target operation is determined from the query operations according to the order in which they are executed, specifically including:

[0016] Determine whether there is a historical execution plan that matches the given execution plan among the historical execution plans;

[0017] If not, the target operation is determined from the query operations according to the order in which they are executed.

[0018] Optionally, the method further includes:

[0019] If it is determined that there is a historical execution plan that matches the execution plan among the historical execution plans, then the target operation is determined from each query operation based on the historical execution plan that matches the execution plan.

[0020] Optionally, the target operation is determined from the query operations according to the order in which they are executed, specifically including:

[0021] For each query operation involved in the execution plan, determine the query object corresponding to that query operation;

[0022] Based on the relationships between the query objects corresponding to each query operation and the order in which the query operations are executed, the target operation is determined from the query operations.

[0023] Optionally, before deduplicating duplicate results in the query results obtained from executing the target operation when executing the execution plan, the method further includes:

[0024] Based on the position of the operation instruction corresponding to the target operation in the execution plan, determine the position in the execution plan where the deduplication operation will be inserted, and use this position as the target position.

[0025] Based on the target location, a deduplication instruction is inserted into the execution plan to generate an optimized execution plan;

[0026] When executing the execution plan, duplicate results in the query results obtained from executing the target operation are deduplicated, specifically including:

[0027] When executing the optimized execution plan, the duplicate results contained in the query results obtained after executing the target operation are deduplicated according to the inserted deduplication operation instruction.

[0028] Optionally, based on the target location, a deduplication instruction is inserted into the execution plan, specifically including:

[0029] Determine the deduplication instructions already included in the execution plan;

[0030] Add the already included deduplication operation instruction to the target location.

[0031] This specification provides a data query device, including:

[0032] The acquisition module is used to acquire the query statement input by the user, which is used to retrieve data from the database;

[0033] The generation module is used to generate an execution plan corresponding to the query statement based on the query statement;

[0034] The determination module is used to determine, based on the execution plan, each query operation involved in the execution plan and the order in which the query operations are executed;

[0035] An optimization module is used to determine a target operation from the query operations according to the execution order of the query operations. The target operation is the operation other than the last query operation executed.

[0036] The query module is used to remove duplicate results from the query results obtained by executing the target operation when executing the execution plan, and to obtain the query data corresponding to the query statement based on the deduplicated query results.

[0037] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described data query method.

[0038] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described data query method.

[0039] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:

[0040] The data query method provided in this specification first obtains the query statement input by the user. The query statement is used to query data from the database. Based on the query statement, an execution plan corresponding to the query statement is generated. Based on the execution plan, the various query operations involved in the execution plan and the execution order of the various query operations are determined. Based on the execution order of the various query operations, the target operation is determined from the various query operations. The target operation is the operation other than the last query operation executed among the various query operations. When executing the execution plan, the duplicate results contained in the query results obtained by executing the target operation are deduplicated. Based on the deduplicated query results, the query data corresponding to the query statement is obtained.

[0041] As can be seen from the above method, by determining the order of execution of query operations involved in the execution plan generated when the query statement is executed by the database, it is possible to determine which query operations' results should be deduplicated in the execution plan. This can reduce the workload of the database when executing subsequent query operations, and by deduplicating the results of the determined query operations, the efficiency of database data retrieval can be improved. Attached Figure Description

[0042] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:

[0043] Figure 1 This is a flowchart illustrating a data query method provided in this specification;

[0044] Figure 2 A schematic diagram illustrating the process of executing query statements for the databases provided in this manual;

[0045] Figure 3 This is a schematic diagram of a data query device provided in this specification;

[0046] Figure 4 This specification provides a corresponding Figure 1 A schematic diagram of an electronic device. Detailed Implementation

[0047] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.

[0048] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.

[0049] Figure 1 This is a flowchart illustrating a data query method provided in this specification, including the following steps:

[0050] S100: Obtain the query statement input by the user, which is used to query data from the database.

[0051] In practical applications, the database can obtain the query statement entered by the user, generate an execution plan based on the query statement, and then query the corresponding data according to the generated execution plan. The query statement can be a query statement entered by the user through the terminal device used by the user.

[0052] In this specification, the executing entity used to implement the data query method can refer to a terminal device with a database deployed, such as a desktop computer or a laptop computer, or a designated device such as a server. For ease of description, the following description will only use a server as the executing entity to illustrate the data query method provided in this specification.

[0053] S102: Generate an execution plan corresponding to the query statement based on the query statement.

[0054] S104: Based on the execution plan, determine the query operations involved in the execution plan and the order in which the query operations are executed.

[0055] After receiving the query statement input by the user, the server can perform syntax parsing on the query statement to obtain the syntax tree corresponding to the query statement (that is, the result of inferring the meaning of the query statement based on its sentence structure). Then, through the execution plan generator (a component in the database), the server generates the execution plan corresponding to the query statement based on the parsed syntax tree. The execution plan is used to represent the various query operations involved in the database when executing the query statement and the order in which the query operations are executed.

[0056] For example, suppose the query is "to find the names of the books read by the friends of the friends of user A". The database will first query who the friends of user A are. Let's say the query result is B and C. Then the database will continue to query who the friends of B and C are, and then query who the friends of the friends of user A have read. Finally, it will get the names of these books. The database executes these query operations and the order in which these query operations are executed is an execution plan.

[0057] It should be noted that, in addition to representing the various query operations involved in the database's execution of query statements and the order in which these query operations are executed, the execution plan can also represent the path through which the database executes these query operations and the methods used to execute them, such as whether data is queried based on an index.

[0058] As can be seen from the above, after generating the execution plan corresponding to the query statement, the server can determine the various query operations involved in the execution plan, as well as the order in which the query operations are executed.

[0059] S106: Based on the order in which the query operations are executed, determine the target operation from among the query operations. The target operation is the operation other than the last query operation executed among the query operations.

[0060] After determining the various query operations involved in the execution plan and the order in which they are executed, the server can identify the target operation from among the query operations based on the order in which they are executed. The target operation is any operation involved in the execution plan other than the last query operation executed.

[0061] Specifically, for each query operation involved in the execution plan, the server can determine the query object corresponding to the query operation, and determine the target operation from each query operation based on the relationship between the query objects corresponding to each query operation and the order in which each query operation is executed.

[0062] In the above content, based on the relationship between the query objects corresponding to each query operation and the execution order of each query operation, the method to determine the target operation from each query operation can be as follows: For each query operation involved in the execution plan, based on the execution order of each query operation, determine the previous query operation executed before this query operation, and determine whether the query object of this query operation directly depends on the query object of the previous query operation. For example, suppose the query statement is "What books have the friends of the friend of person A read?", there are three query operations involved: the first is "What friends does person A have?", the second is "What friends does each friend of person A have?", and the third is "What books have the friends of each friend of person A read?". Among them, "What books have the friends of the friends of person A read?" is completely dependent on "What friends does the friend of person A have?". Therefore, it can be considered that the third query operation is completely dependent on the second query operation. That is, the first query operation and the second query operation have the direct dependency relationship mentioned above. In this case, the second query operation can be considered the target operation.

[0063] In the above content, there are many ways for the server to determine whether the query object of the current query operation directly depends on the query object of the previous query operation. For example, the server can determine whether the current query operation meets the preset conditions according to the pre-configured conditions. If so, it is considered that the query object of the current query operation directly depends on the query object of the previous query operation. Another example is that the server can perform lexical analysis on the query object of the current query operation and the query object of the previous query operation to determine whether the query object of the current query operation directly depends on the query object of the previous query operation.

[0064] In addition, the server can also determine the deduplication operations already included in the execution plan. Based on the relationship between the query objects corresponding to each query operation and the execution order of each query operation, it can determine the relationship between the query object of the previous query operation executed before the query operation corresponding to the aforementioned deduplication operation and the query object of the aforementioned deduplication operation, and determine whether the previous query operation executed before the query operation corresponding to the aforementioned deduplication operation is the target operation.

[0065] As can be seen from the above, the server can deduplicate the query results of all queries in the execution plan, excluding the last query operation executed in each query operation. Based on the deduplicated query results, the server can continue to perform queries to obtain the query data corresponding to the query statement. This reduces the workload of the database when executing query statements and improves the efficiency of data query execution.

[0066] S108: After executing the target operation based on the execution plan, perform a deduplication operation on the query results obtained after executing the target operation to obtain the query data corresponding to the query statement.

[0067] After determining the target operation, the server can remove duplicate results from the query results obtained from executing the target operation when executing the execution plan, and obtain the query data corresponding to the query statement based on the deduplicated query results.

[0068] Specifically, after determining the target operation, the server can determine the position to insert the deduplication operation in the execution plan based on the position of the operation instruction corresponding to the target operation in the execution plan. This position is then used as the target position. Based on the target position, the server can insert the deduplication operation instruction in the execution plan to generate an optimized execution plan. The optimized execution plan is then saved in the historical execution plan. When executing the optimized execution plan, the server can use the inserted deduplication operation instruction to remove duplicate results from the query results obtained after executing the target operation.

[0069] One method for the server to insert deduplication instructions into the execution plan is to determine whether the deduplication operation already included in the execution plan for deduplicating the query results of the query operation is a valid operation. This can be understood as follows: if it is, the deduplication operation already included in the execution plan will be copied to the target location; if not, the deduplication operation already included in the execution plan will be adjusted to the target location.

[0070] In addition, in order to utilize historical information on execution plan optimization to further improve the query efficiency of database execution, the database can first determine whether there is a historical execution plan that matches the current execution plan before determining the target operation. If not, the target operation is determined from the query operations based on the order in which they are executed. If there is a historical execution plan that matches the current execution plan, the target operation is determined from the query operations involved in the execution plan based on the historical execution plan that matches the current execution plan.

[0071] In the above content, the method to determine whether there is a historical execution plan that matches the execution plan in each historical execution plan can be to remove the parameters from the execution plan, and then determine whether there is a historical execution plan that matches the execution plan after removing the parameters. If so, the historical execution plan that matches the execution plan after removing the parameters is considered to be the execution plan that matches the execution plan.

[0072] For example: Suppose the execution plan is to query the friends of a user named A. Then, after removing the parameters, the execution plan is to query the friends of a certain user. Then, we search for "query the friends of a certain user" in each historical execution plan. If it exists, then we consider that the historical execution plan matches the execution plan.

[0073] To facilitate understanding, this manual also provides a schematic diagram of the execution plan optimization process, such as... Figure 2 As shown.

[0074] Figure 2 This is a schematic diagram illustrating the process of executing query statements for the database provided in this manual.

[0075] from Figure 2 As can be seen, after the database receives the query statement input by the user, it can generate an execution plan corresponding to the query statement. Then, it determines whether there is a historical execution plan that matches the generated execution plan. If so, it identifies the query operation that needs deduplication based on the historical execution plan, and uses it as the target operation. If not, it identifies the query operation that needs deduplication based on the execution order of the query operations involved in the execution plan, and uses it as the target operation. Then, it determines the position to insert the deduplication operation in the execution plan based on the position of the operation instruction corresponding to the target operation in the execution plan. The deduplication operation instruction can then be inserted into the execution plan to generate an optimized execution plan. The optimized execution plan is saved to the historical execution plan. When the optimized execution plan is executed, the duplicate results in the query results obtained after executing the target operation can be deduplicated according to the inserted deduplication operation instruction. Based on the deduplicated query results, the query data corresponding to the query statement can be obtained from the database.

[0076] As can be seen from the above, the server can determine the order of query operations executed in the execution plan generated when the query statement is executed by the database, and based on historical execution plans, which query operations in the execution plan corresponding to the user-input query statement will have their query results deduplicated. This can reduce the workload of the database when executing subsequent query operations, and improve the efficiency of database data retrieval by deduplicating the query results of the determined query operations.

[0077] The above describes one or more embodiments of the data query method provided in this specification. Based on the same idea, this specification also provides corresponding data query devices, such as... Figure 3 As shown.

[0078] Figure 3 A schematic diagram of a data query device provided in this specification includes:

[0079] The acquisition module 301 is used to acquire the query statement input by the user, which is used to query data from the database;

[0080] The generation module 302 is used to generate an execution plan corresponding to the query statement based on the query statement;

[0081] The first determining module 303 is used to determine, based on the execution plan, each query operation involved in the execution plan and the order in which each query operation is executed;

[0082] The second determining module 304 is used to determine the target operation from the query operations according to the order in which the query operations are executed. The target operation is the operation other than the last query operation executed among the query operations.

[0083] The query module 305 is used to remove duplicate results from the query results obtained by executing the target operation when executing the execution plan, and to obtain the query data corresponding to the query statement based on the deduplicated query results.

[0084] Optionally, the generation module 302 is specifically used to perform syntax parsing on the query statement to obtain a syntax tree corresponding to the query statement; and to generate an execution plan corresponding to the query statement based on the syntax tree.

[0085] Optionally, the second determining module 304 is specifically used to determine whether there is a historical execution plan that matches the execution plan in each historical execution plan; if not, then determine the target operation from each query operation according to the order in which each query operation is executed.

[0086] Optionally, the second determining module 304 is specifically used to determine the target operation from each query operation based on the historical execution plan that matches the execution plan if it is determined that there is a historical execution plan that matches the execution plan.

[0087] Optionally, the second determining module 304 is specifically used to: determine the query object corresponding to each query operation involved in the execution plan; and determine the target operation from each query operation based on the association between the query objects corresponding to each query operation and the order in which the query operations are executed.

[0088] Optionally, the query module 305 is specifically configured to: determine the position for inserting a deduplication operation in the execution plan based on the position of the operation instruction corresponding to the target operation in the execution plan, as the target position; insert a deduplication operation instruction in the execution plan based on the target position to generate an optimized execution plan; and when executing the optimized execution plan, deduplicate the duplicate results contained in the query results obtained after executing the target operation based on the inserted deduplication operation instruction.

[0089] Optionally, the query module 305 is specifically used to determine the deduplication operation instructions already included in the execution plan; and to add the already included deduplication operation instructions to the target position.

[0090] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1This provides a data query method.

[0091] This instruction manual also provides Figure 4 The one shown corresponds to Figure 1 A schematic diagram of the structure of an electronic device. (e.g.) Figure 4 At the hardware level, this electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then executes it to achieve the above. Figure 1 The data query method. Of course, in addition to the software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0092] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages ​​and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.

[0093] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0094] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.

[0095] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware components.

[0096] Those skilled in the art will understand that embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0097] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0098] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0099] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0101] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0102] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0103] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0104] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0105] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0106] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0107] The above are merely embodiments of this specification and are not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.

Claims

1. A data query method, comprising: Obtain the query statement input by the user, which is used to retrieve data from the database; Based on the query statement, generate the execution plan corresponding to the query statement; Based on the execution plan, determine each query operation involved in the execution plan and the order in which each query operation is executed; Based on the execution order of the query operations, the target operation is determined from the query operations, including: for each query operation involved in the execution plan, determining the query object corresponding to the query operation; based on the execution order of the query operations, determining the previous query operation executed before the current query operation, and determining whether the query object of the current query operation directly depends on the query object of the previous query operation; if so, the previous query operation is determined as the target operation; wherein, the target operation is the operation other than the last query operation executed among the query operations. When executing the execution plan, duplicate results in the query results obtained from executing the target operation are deduplicated, and the query data corresponding to the query statement is obtained based on the deduplicated query results.

2. The method as described in claim 1, wherein generating an execution plan corresponding to the query statement based on the query statement specifically includes: The query statement is parsed to obtain the syntax tree corresponding to the query statement; Based on the syntax tree, an execution plan corresponding to the query statement is generated.

3. The method as described in claim 1, wherein the target operation is determined from the query operations according to the order in which they are executed, specifically includes: Determine whether there is a historical execution plan that matches the given execution plan among the historical execution plans; If not, the target operation is determined from the query operations according to the order in which they are executed.

4. The method of claim 3, further comprising: If it is determined that there is a historical execution plan that matches the execution plan among the historical execution plans, then the target operation is determined from each query operation based on the historical execution plan that matches the execution plan.

5. The method of claim 1, further comprising, before deduplicating duplicate results contained in the query results obtained from executing the target operation when executing the execution plan: Based on the position of the operation instruction corresponding to the target operation in the execution plan, determine the position in the execution plan where the deduplication operation will be inserted, and use this position as the target position. Based on the target location, a deduplication instruction is inserted into the execution plan to generate an optimized execution plan; When executing the execution plan, duplicate results in the query results obtained from executing the target operation are deduplicated, specifically including: When executing the optimized execution plan, the duplicate results contained in the query results obtained after executing the target operation are deduplicated according to the inserted deduplication operation instruction.

6. The method as described in claim 5, wherein a deduplication operation instruction is inserted into the execution plan according to the target location, specifically including: Determine the deduplication instructions already included in the execution plan; Add the already included deduplication operation instruction to the target location.

7. A data query device, comprising: The acquisition module is used to acquire the query statement input by the user, which is used to retrieve data from the database; The generation module is used to generate an execution plan corresponding to the query statement based on the query statement; The determination module is used to determine, based on the execution plan, each query operation involved in the execution plan and the order in which the query operations are executed; An optimization module is used to determine a target operation from the query operations according to the execution order of each query operation, including: for each query operation involved in the execution plan, determining the query object corresponding to the query operation; determining the previous query operation executed before the current query operation according to the execution order of each query operation, and determining whether the query object of the current query operation directly depends on the query object of the previous query operation; if so, determining the previous query operation as the target operation; wherein, the target operation is the operation other than the last query operation executed among the query operations; The query module is used to remove duplicate results from the query results obtained from the execution of the target operation when the execution plan is executed, and to obtain the query data corresponding to the query statement based on the deduplicated query results.

8. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 6.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Execution plan optimization method and device, equipment, and storage medium

    CN111563101A

  • Data query method and device

    CN114265874A

  • Task processing method and device based on PostgreSQL, computer equipment and storage medium

    CN114637779A