Partition-based query method and device, electronic equipment, storage medium and product
By updating the filter conditions when the partition column and the target column are the same, the query statement is optimized, which solves the problem of low efficiency in partition column filtering queries and achieves a more efficient query process.
Patent Information
- Application Number
- CN202510906631.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-02
- Publication Date
- 2025-10-17
AI Technical Summary
In the prior art, when performing a partition column filtering query, the query processing load increases due to the inability to predict data written to the partition, which affects query efficiency.
By determining the target column and the partition column of the target table based on the filtering conditions in the query statement, and updating the filtering conditions when the partition column is the same as the target column, the query statement is optimized to improve query efficiency.
By optimizing the filtering conditions, the operation of comparing data row by row during the query process is reduced, thereby improving the query efficiency of the partitioned table and reducing the query time.
Smart Images

Figure CN120804179A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of data processing, and in particular to a partition-based query method and device, electronic equipment, storage medium and product. BACKGROUND
[0002] Structured Query Language (SQL) is the most important and most commonly used language for relational database operations. A horizontally partitioned table can be created through an SQL statement, and the creation of the horizontally partitioned table needs to be specified through a <PARTITION clause>. Horizontal partitioning includes HASH partitioning, which is a partitioning method that determines the actual data storage location by performing a HASH operation on the partition column value. Using HASH partitioning, rows can be mapped to partitions based on the hash value (HASH value) of the partition key, allowing data to be evenly divided among a specified number of partitions. Specifically, when a user writes data to a table, the database server can calculate the data based on a hash function to distribute the data evenly among the partitions.
[0003] However, when performing partition column filtering queries on a partitioned sub-table, the user cannot predict which partition the data will be written to, and the partitioned sub-tables that do not meet the filtering conditions are also queried, increasing the processing amount of the query process and affecting the query efficiency. SUMMARY
[0004] The present application provides a partition-based query method and device, electronic equipment, storage medium and product to improve the efficiency of partition column filtering queries on partitioned tables.
[0005] In a first aspect, the embodiments of the present application provide a partition-based query method, comprising:
[0006] determining a target column to be queried and a target table corresponding to the target column according to a filtering condition in a query statement;
[0007] determining a partition column of a parent partition master table of the target table;
[0008] if the partition column is the same as the target column, updating the filtering condition according to the partition column and the target table to obtain a new query statement;
[0009] querying data according to the new query statement.
[0010] In a second aspect, the embodiments of the present application also provide a partition-based query device, comprising:
[0011] a first determination module configured to determine a target column to be queried and a target table corresponding to the target column according to a filtering condition in a query statement;
[0012] a second determining module, configured to determine a partition column of a parent partition master table of the target table;
[0013] an updating module, configured to update the filter condition according to the partition column and the target table to obtain a new query statement if the partition column is the same as the target column;
[0014] a querying module, configured to query data according to the new query statement.
[0015] In a third aspect, an electronic device is provided, including:
[0016] one or more processors;
[0017] a storage device configured to store one or more programs;
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the partition-based query method according to the first aspect.
[0019] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the partition-based query method according to the first aspect is implemented.
[0020] In a fifth aspect, a computer program product is provided, which includes a computer program and / or instructions. When the computer program and / or instructions are executed by a processor, the partition-based query method according to any of the above embodiments is implemented.
[0021] The embodiments of the present application provide a partition-based query method, device, electronic device, storage medium and product. The partition-based query method includes: determining a target column to be queried and a target table corresponding to the target column according to a filter condition in a query statement; determining a partition column of a parent partition master table of the target table; updating the filter condition according to the partition column and the target table to obtain a new query statement if the partition column is the same as the target column; and querying data according to the new query statement. The above technical solution can optimize the query statement and improve the efficiency of the partition column filter query of the partition table by updating the filter condition when the target column is the same as the partition column of the corresponding parent partition master table. BRIEF DESCRIPTION OF DRAWINGS
[0022] The above and other features, advantages, and aspects of the present disclosure will become more apparent by describing in detail the following specific embodiments in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals indicate the same or similar elements. It should be understood that the drawings are schematic, and the original and elements are not necessarily drawn according to the scale.
[0023] Figure 1 A flow chart of a query method based on partitioning provided in an embodiment of the present application;
[0024] Figure 2 A structural schematic diagram of a query device provided in an embodiment of the present application;
[0025] Figure 3 A structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The present application will be further described below in conjunction with the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application. In addition, it should be noted that, for the convenience of description, only the parts related to the present application are shown in the drawings, but not all the structures.
[0027] Before the example embodiments are discussed in more detail, it should be mentioned that some of the example embodiments are described as processes or methods depicted as flow charts. While the steps of the processes are depicted in a sequential order, many of the steps can be performed in parallel, concurrently or at the same time with each other. In addition, the order of the steps can be re-arranged. The processes can be terminated when their operations are completed, but can also have additional steps not included in the figure, which can also be performed after the operations of the processes are completed. The processes can correspond to methods, functions, procedures, subroutines, subprograms, etc.
[0028] It should be noted that the terms "first", "second", etc. mentioned in the embodiments of the present application are only used to distinguish different devices, modules, units or other objects, and do not limit the order or interdependence of the functions performed by these devices, modules, units or other objects.
[0029] In addition, the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0030] In the technical solutions of the present application, the acquisition, storage, use, processing, etc. of data all comply with the relevant provisions of national laws and regulations.
[0031] It should be noted that in the embodiments of the present application, some industry existing solutions, components, models, etc. may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but does not mean that the applicant has or will necessarily use the relevant content of the solutions.
[0032] Figure 1A flowchart of a partition-based query method provided by an embodiment of the present application. The embodiment can be applied to a case of querying based on partitioning. Specifically, the partition-based query method can be executed by a partition-based query device, which can be implemented in software and / or hardware and integrated in an electronic device. The electronic device includes, but is not limited to, a computer, a smartphone, or a server, and the like, a device having a computing function, and can also be a device deployed or connected to a database, and can also be a central processing unit (CPU) system on chip (SoC) computer or a field-programmable gate array (FPGA), and the like.
[0033] As shown in Figure 1 , the method specifically includes the following steps:
[0034] S110, determining a target column to be queried and a target table corresponding to the target column according to a filter condition in a query statement.
[0035] In the embodiment, the query statement mainly refers to a statement for performing partition column filtering query on m (m≥1) level partition sub-tables, wherein the partition column is an n level (m≥n) hash partition column, and the query statement contains a filter condition, which can be an equality query or an in condition, etc. The partition column on which the query is based is the target column, and the partition sub-table to which the target column belongs is the target table.
[0036] S120, determining a partition column of a parent partition master table of the target table.
[0037] S130, if the partition column is the same as the target column, updating the filter condition according to the partition column and the target table to obtain a new query statement.
[0038] In the embodiment, if the partition column of the parent partition master table is the same as the target column, the filter condition can be optimized. For example, it can be determined according to the partition column and the constant value in the filter condition whether the constant value can locate the target table, i.e., whether there is data in the target table that satisfies the filter condition. If it is determined that the constant value in the filter condition cannot locate the target table, i.e., there is no data in the target table that satisfies the filter condition, the filter condition can be optimized to be FALSE, and the target table does not need to be queried. If it is determined that the constant value in the filter condition can locate the target table, i.e., there is data in the target table that satisfies the filter condition, the filter condition is not optimized, and the target table can be normally queried.
[0039] S140, querying data according to the new query statement.
[0040] For example: create table T3(c1 varchar(10),c2 int)partition by hash(c1)
[0041] (partition p1,partition p2);
[0042] The first-level hash partition table T3 has the partition column c1, and contains two partition sub-tables p1 and p2, wherein the data in the p1 partition and the p2 partition do not overlap.
[0043] For a partition column filtering query on m (m≥1) level partition sub-tables, wherein the partition column is an n-level (m≥n) hash partition column, and the filtering condition is an equality query or an in condition of a hash partition table. Because the data in the partition columns of different hash partition sub-tables do not overlap, if the constant hash value in the query condition cannot locate the specified m-level partition sub-table, it indicates that there is no data in the partition sub-table that satisfies the filtering condition, and thus the filtering condition can be converted into a constant false (FALSE), and no query needs to be performed on the target table.
[0044] The method provided in the embodiments of the present application can simplify the filtering condition of a hash partition table in advance by updating the filtering condition when the target column and the partition column of the corresponding upper-level partition master table are the same, thereby avoiding a large number of operations of comparing data row by row to determine whether the data satisfies the filtering condition in the query process, improving the query efficiency, and reducing the query time consumption.
[0045] In an embodiment, the method further comprises:
[0046] S150, if the partition column is different from the target column, the upper-level partition master table is taken as a new target table, and the step of determining the partition column of the upper-level partition master table of the target table is returned.
[0047] For example, if the target table is an x-level partition table, and the partition column of the upper-level (x-1-level) partition master table is different from the target column, the upper-level (x-1-level) partition master table can be taken as a new target table, the partition column of the upper-level (x-2-level) partition master table is determined, and it is determined again whether the partition column is the same as the target column; if yes, the filtering condition is optimized according to the partition column and the target table (the (x-1-level) partition master table); otherwise, the upper-level (x-2-level) partition master table is taken as a new target table, and the above process is repeated until a set condition is met. If the upper-level partition master table is empty, it indicates that the traversal is ended, and the optimization condition is not met, and the original filtering condition can be used for query.
[0048] In an embodiment, the filtering condition comprises an equality expression, such as an equality query or an in condition for a hash-partitioned table, and the target table is a hash-partitioned table.
[0049] In an embodiment, updating the filtering condition according to the partition column and the target table comprises:
[0050] S1310, determining a function for calculating a hash value according to a data type of the partition column;
[0051] S1320, calculating a hash value based on the function and a constant in the equality expression;
[0052] S1330, generating a new expression according to the hash value and the target table to update the filtering condition.
[0053] For example, the hash value is calculated based on the function and the constant in the equality expression. If the hash value cannot locate the target table, i.e., it is determined that there is no data satisfying the filtering condition in the target table, the filtering condition can be optimized as FALSE, and the target table does not need to be queried. If the hash value can locate the target table, i.e., there is data satisfying the filtering condition in the target table, the filtering condition is not optimized, and the target table is normally queried.
[0054] In an embodiment, generating a new expression according to the hash value and the target table comprises:
[0055] S1301, determining a partition sequence number according to the hash value;
[0056] S1302, determining a partition sub-table according to the partition sequence number;
[0057] S1303, if the partition sub-table is different from the target table, generating a new expression, and the new expression is a FALSE expression.
[0058] For example, the partition sequence number is determined according to the hash value, and the partition sub-table is determined. The hash value is calculated based on the function and the constant in the equality expression. Whether the hash value can locate the target table can be understood as whether the partition sub-table corresponding to the hash value is the same as the target table. If they are different, the hash value cannot locate the target table, and in this case, the filtering condition can be optimized as FALSE. If they are the same, the hash value can locate the target table, and in this case, the filtering condition does not need to be optimized.
[0059] It should be noted that in the process of generating new expression, for the case that the filter condition is "col in lst" (i.e. in condition), a "col = constant" expression can be constructed for each constant in lst, and each constructed expression can be optimized. If the constructed expression can be optimized to FALSE, the corresponding constant can be removed from lst; if each constant in lst can be optimized to FALSE, the "col in lst" expression can be optimized to FALSE as a whole.
[0060] In an embodiment, before determining the target column to be queried and the target table corresponding to the target column according to the filter condition in the query statement, the method further comprises:
[0061] S100, determining that the filter condition is in the form of a Boolean expression of a column and a constant.
[0062] As an example, the optimization process of the query statement is as follows:
[0063] 1) execute the SQL statement, perform partition pruning optimization, and execute step 2);
[0064] 2) determine whether the filter condition is in the form of a Boolean expression of a column and a constant, for example: where c1 = 10. If yes, execute step 3); if not, execute step 10);
[0065] 3) parse the column col (i.e. target column) involved in the filter condition and the table to which the column belongs (i.e. target table), and mark the current processing table (i.e. target table) as table tab, and execute step 4);
[0066] 4) obtain the upper-level partition base table base_tab of table tab, if the obtained partition base table is empty, it means that the traversal ends and the optimization condition is not met, and step 10) is executed; if base_tab is obtained, obtain the partition column part_col of base_tab, if it is the same as the column col involved in the filter condition, it means that optimization can be performed, set the optimization flag to TRUE, and execute step 5); if the partition column part_col of base_tab is different from col, move the current processing table tab up to point to the upper-level partition base table base_tab, and continue to execute step 4);
[0067] 5) if the optimization flag is not TRUE, or the partition base table is not a hash partition table, or the filter condition is not an equality expression, execute step 10), otherwise execute step 6);
[0068] 6) Get the function of calculating the hash value through the data type of the partition column part_col, and then use the function to calculate the hash value of the constant in the equality expression to obtain the hash value hash_value, and execute step 7);
[0069] 7) Hash partition positioning is performed through the calculated hash value, the located partition serial number is found, the specific partition sub-table sub_tab_hash located is obtained through the partition serial number, and step 8) is executed;
[0070] 8) If the partition sub-table sub_tab_hash is the same as the partition sub-table sub_tab of the SQL query, it is not optimized, and step 10) is executed;
[0071] If the partition sub-table sub_tab_hash is not the partition sub-table sub_tab of the SQL query, a FALSE expression is generated, and step (9) is executed;
[0072] 9) The newly generated expression is analyzed, and the expression of the original filter condition is replaced, and step 10) is executed;
[0073] 10) Optimization ends.
[0074] The following is a specific example:
[0075] A two-level partition table TEST_HASH can be defined by the following process:
[0076]
[0077]
[0078] The specific partition situation can be seen from Table 1, and it can be assumed that the data in the table is distributed according to Table 1.
[0079] Table 1 Partition table situation
[0080]
[0081] (1) Execute the following SQL query statement:
[0082] SELECT*FROM TEST_HASH_P1 WHERE C1=1;
[0083] Since the partition column C1 value is 1, the sub-partition P2 is located, and the sub-partition P1 has no data satisfying the filter condition, the filter condition is optimized to FALSE by this method, avoiding the row-by-row comparison operation for the data in the sub-partition P1 in the execution process, reducing the execution time. The specific analysis is as follows:
[0084] The column involved in the filter condition (i.e., the target column) is C1, the table to which the column belongs (i.e., the target table) is TEST_HASH_P1, the partition sub-table sub_tab is set to TEST_HASH_P1, the upper partition master table base_tab of TEST_HASH_P1 is TEST_HASH, the partition column of TEST_HASH is C1, which is the same as the column col involved in the filter condition, and the optimization flag is set to TRUE. The hash value of the constant in the filter condition is calculated, and the corresponding partition sub-table sub_tab_hash is located as TEST_HASH_P2. The partition sub-table sub_tab_hash is not the partition sub-table sub_tab of the SQL query, and the filter condition can be optimized to FALSE.
[0085] The execution plan before optimization is as follows:
[0086]
[0087] The execution time of the above query process is 1548 ms.
[0088] The execution plan after optimization is as follows:
[0089]
[0090] The execution time of the above query process is 26 ms.
[0091] (2) SELECT * FROM TEST_HASH_P1_Q2 WHERE C1 = 1;
[0092] Since the partition column C1 value is 1, it is located in the sub-partition P2, and the partition master table TEST_HASH_P1 to which the partition sub-table TEST_HASH_P1_Q2 belongs has no data satisfying the filter condition, the filter condition is optimized to FALSE, avoiding the row-by-row comparison operation for the data in the partition sub-table TEST_HASH_P1_Q2 in the execution process, reducing the execution time. The specific analysis is as follows:
[0093] The column involved in the filter condition is C1, the table to which the column belongs is TEST_HASH_P1_Q2, the partition sub-table sub_tab is set as TEST_HASH_P1_Q2, the upper partition master table base_tab of TEST_HASH_P1_Q2 is TEST_HASH_P1, the partition column of TEST_HASH_P1 is C2, which is different from the column in the filter condition, at this time, the current processing table tab is moved up to point to the upper partition master table base_tab TEST_HASH_P1, the partition sub-table sub_tab is set as TEST_HASH_P1, and the upper partition master table TEST_HASH of the partition sub-table sub_tab is continued to be acquired, the partition column part_col of TEST_HASH is C1, which is the same as the column col involved in the filter condition, and the optimization flag is set as TRUE. The hash value of the constant in the filter condition is calculated to obtain the corresponding partition sub-table sub_tab_hash as TEST_HASH_P2. The partition sub-table sub_tab_hash is not the partition sub-table sub_tab of the SQL query, and the filter condition can be optimized as FALSE.
[0094] The execution plan before optimization is as follows:
[0095]
[0096] The execution time of the above query process is 1539 ms.
[0097] The execution plan after optimization is as follows:
[0098]
[0099]
[0100] The execution time of the above query process is 5 ms.
[0101] By comparing the execution plan and the execution time, it can be seen that the partition-based query method of the above embodiment can improve the query efficiency by optimizing the filter condition.
[0102] Figure 2 A structure diagram of a partition-based query device provided by an embodiment of the present application is shown. The partition-based query device provided by the embodiment includes:
[0103] A first determination module 210 is configured to determine a target column to be queried and a target table corresponding to the target column according to a filter condition in a query statement.
[0104] A second determination module 220 is configured to determine a partition column of an upper partition master table of the target table.
[0105] The updating module 230 is configured to update the filter condition according to the partition column and the target table to obtain a new query statement if the partition column is the same as the target column.
[0106] The querying module 240 is configured to query data according to the new query statement.
[0107] The device can optimize the query statement and improve the efficiency of the query of the partition column of the partition table by updating the filter condition if the target column is the same as the partition column of the corresponding upper-level partition master table.
[0108] On the basis of any of the above embodiments, the second determining module 220 is further configured to, if the partition column is different from the target column, take the upper-level partition master table as a new target table, and return to perform the step of determining the partition column of the upper-level partition master table of the target table.
[0109] On the basis of any of the above embodiments,
[0110] The filter condition comprises an equal expression.
[0111] The target table is a hash partition table.
[0112] On the basis of any of the above embodiments, the updating module 230 comprises:
[0113] A function determining unit is configured to determine a function for calculating a hash value according to the data type of the partition column.
[0114] A calculating unit is configured to calculate a constant in the equal expression based on the function to obtain a hash value.
[0115] An updating unit is configured to generate a new expression according to the hash value and the target table to update the filter condition.
[0116] On the basis of any of the above embodiments, the updating unit is specifically configured to:
[0117] Determine a partition serial number according to the hash value.
[0118] Determine a partition sub-table according to the partition serial number.
[0119] If the partition sub-table is different from the target table, generate a new expression, and the new expression is a FALSE expression.
[0120] On the basis of any of the above embodiments, the device further comprises a verifying module configured to determine that the filter condition is in the form of a Boolean expression of a column and a constant before determining the target column to be queried and the target table corresponding to the target column according to the filter condition in the query statement.
[0121] The partition-based query device provided by the embodiments of the present application can be used to execute the partition-based query method provided by any of the embodiments described above, and has the corresponding functions and advantages.
[0122] Figure 3 A structural schematic diagram of an electronic device 10 that can be used to implement the embodiments of the present application is shown. The electronic device 10 is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device 10 can also represent various forms of mobile devices, such as personal digital processors, cellular telephones, smart phones, user equipment, and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit the implementations of the present application described and / or claimed in this document.
[0123] As shown in Figure 3 The electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11, wherein the memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0124] A plurality of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, a loudspeaker, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks, wireless networks.
[0125] The processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, and the like. The processor 11 performs various methods and processes described above.
[0126] In some embodiments, the methods of the above-described embodiments can be implemented as a computer program tangibly embodied in a computer readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the above-described methods can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform any of the above-described embodiment methods by other any suitable means, such as by means of firmware.
[0127] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a programmable logic device (PLD), a computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0128] Computer programs used to implement the methods of the application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the computer program, when executed by the processor, implements the functions / acts specified in the flowcharts and / or block diagrams. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as a standalone software package, and partially on a machine or entirely on a remote machine or server.
[0129] In the context of this application, a computer readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer readable storage medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer readable storage medium can be a machine readable signal medium. More specific examples of a machine readable storage medium will include a one or more lines of a computer program code, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0130] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device 10 having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device 10. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0131] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0132] The embodiments of the present application also provide a computer program product, comprising computer programs and / or instructions, which, when executed by a processor, implement the partition-based query method as described in any of the above embodiments.
[0133] It should be understood that the various forms of flow shown above can be used to reorder, add, or remove steps. For example, the steps recited in the present application can be performed in parallel, in series, or in a different order, as long as the desired results of the present application are achieved, which is not limited herein.
[0134] The foregoing detailed description has not been limited by a particular embodiment thereof. Alternative embodiments, which practice the application, will be apparent to those skilled in the art given the benefit of this disclosure. Therefore, the scope of the application should be determined, not with reference to the above description, but should instead be made by reference to the appended claims, taken in conjunction with the full scope of equivalents to which such claims are entitled. It will be further understood that the use of relational terms such as first and second, and the like, if any, are used solely to distinguish one from another entity and do not necessarily require a serial or chronological order of one to another.
Claims
1. A partition-based query method, characterized in that: include: Determine the target column to be queried and the target table corresponding to the target column according to the filter conditions in the query statement; Determine the partition columns of the upper-level partition master table of the target table; If the partition column is the same as the target column, the filter condition is updated according to the partition column and the target table to obtain a new query statement; Query data according to the new query statement.
2. The method according to claim 1, characterized in that Also includes: If the partition column is different from the target column, the upper-level partition master table is used as a new target table, and the process returns to the step of determining the partition column of the upper-level partition master table of the target table.
3. The method according to claim 1, characterized in that The filtering condition includes an equivalent expression; The target table is a hash partition table.
4. The method according to claim 3, characterized in that Updating the filtering condition according to the partition column and the target table includes: Determining a function for calculating a hash value according to a data type of the partition column; Calculating the constants in the equivalent expression based on the function to obtain a hash value; A new expression is generated according to the hash value and the target table to update the filtering condition.
5. The method according to claim 4, characterized in that Generating a new expression according to the hash value and the target table, including: Determine a partition sequence number according to the hash value; Determine a partition sub-table according to the partition sequence number; If the partition sub-table is different from the target table, a new expression is generated, and the new expression is a FALSE expression.
6. The method according to claim 1, characterized in that Before determining the target column to be queried and the target table corresponding to the target column according to the filtering condition in the query statement, the method further includes: The filtering condition is determined to be in the form of a Boolean expression of columns and constants.
7. A partition-based query device, characterized in that: include: A first determining module is used to determine a target column to be queried and a target table corresponding to the target column according to a filtering condition in a query statement; A second determination module determines the partition columns of the upper-level partition master table of the target table; An update module, configured to update the filter condition according to the partition column and the target table to obtain a new query statement if the partition column is the same as the target column; A query module is used to query data according to the new query statement.
8. An electronic device, characterized in that: include: at least one processor; a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to execute the partition-based query method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the partition-based query method according to any one of claims 1 to 6 is implemented.
10. A computer program product comprising a computer program and / or instructions, characterized in that When the computer program and / or the instructions are executed by a processor, the partition-based query method according to any one of claims 1 to 6 is implemented.