The present invention relates to database queries, and more particularly to improving a performance of a database query.
In a massively parallel processing (mpp) environment, table data is stored in multiple data slices, nodes, or multiple logical nodes (mlns). Data is moved into multiple data slices based on a distribution key of a database table, which is defined during table creation. Based on the distribution key of the table, data is stored into different data slices. In response to a complex query, the mpp environment facilitates query execution by allowing the complex query to be executed in parallel. An optimizer decides how a query is to be executed based on several factors, including parameters such as statistics of the table, cardinality value, distribution key, etc. The optimizer decides how to proceed with query execution based on an estimation of the aforementioned parameters at an initial phase and in between the query execution.
In one embodiment, the present invention provides a computer-implemented method. The method includes receiving, by one or more processors, a query whose execution in a massively parallel processing (mpp) environment includes a first join of multiple tables having sets of records and further includes a subsequent second join with a next table whose set of records is smaller than a set of intermediate transient records resulting from the first join. The method further includes receiving, by the one or more processors, min_row_threshold, which is (i) a threshold value for a number of records in the next table and (ii) a parameter of an optimizer that determines a query execution plan for the query. The method further includes estimating, by the one or more processors and using the optimizer, a first count of the set of intermediate transient records resulting from the first join. The method further includes determining, by the one or more processors and using the optimizer, a second count of a number of records in the next table. The method further includes determining, by the one or more processors and using the optimizer, that the second count is less than min_row_threshold. The method further includes based on the second count being less than min_row_threshold and without using the estimated first count, generating, by the one or more processors and using the optimizer, the query execution plan to include a broadcast of the set of records in the next table to data slices in the mpp environment without including a broadcast of the intermediate transient records.
A computer program product and a computer system corresponding to the above-summarized method are also described and claimed herein.
If the statistics of a database table are not up-to-date, an optimizer may produce an incorrect query execution plan and the query execution may be delayed. Similarly, during the query execution phase, if there is processing skew on transient tables, then the overall query execution may be delayed. In a case in which two or more substantially large tables (i.e., tables having relatively large numbers of records) are involved in a join operation and in which complex query conditions may be present, an optimizer can incorrectly estimate the cardinality value of transient records after the join. Transient records are also referred to herein as “intermediate transient records.” If the aforementioned join is being followed by a subsequent join with a small table (i.e., a table whose set of records is smaller than the set of intermediate transient records resulting from the join of the aforementioned two or more large tables), the incorrect cardinality value estimation is likely to cause an undesirable increase in the overall query execution time. If the cardinality value estimation of the intermediate transient records after the join of the first two or more tables is done incorrectly (i.e., a substantial underestimation of the actual cardinality value, which is a substantially large cardinality value), then the optimizer may decide to broadcast the result sets as part of the query execution. The optimizer makes the decision to broadcast the result sets because the decision is based on the incorrect estimation that the first join of the two or more tables results in a relatively low cardinality value. Broadcasting a substantially large dataset across each data slice is an expensive, time-consuming task. The decision to broadcast a relatively large dataset compared to a relatively small table involved in the subsequent join delays the overall query execution and diminishes query performance. Furthermore, due to the aforementioned issues, a query can keep running endlessly and consume a huge amount of resources for its execution, thereby negatively impacting the execution of other queries.
Embodiments of the present invention address the aforementioned unique challenges of query performance by providing the optimizer with a new optimizer parameter, herein referred to as min_row_threshold. The optimizer uses the min_row_threshold parameter to determine whether or not to broadcast intermediate transient records resulting from a join of multiple tables. By using the new optimizer parameter, the optimizer avoids broadcasting a large number of intermediate transient records due to an incorrect estimation of cardinality by the optimizer. The min_row_threshold parameter is a self-adjusting value whose adjustment is based on the query and the data available in the tables involved in the query. In one embodiment, the min_row_threshold parameter has a default value of 20,000 and a user has an option to change the value of the parameter per the user's requirements.
In one embodiment, as database queries are executed and the min_row_threshold parameter is used to decide whether to broadcast intermediate transient records, a self-learning machine learning system is also executing and checking section actuals (i.e., the actual cardinality value that was used to broadcast and also the cardinality value or statistics on the other side of the join). In one embodiment, the machine learning system also tracks the top frequently run SQL queries, checks against the actual cardinality, and stores the cardinality values. Over a period of time, after the machine learning system finds a pattern for the tracked queries, the machine learning system adjusts the min_row_threshold parameter per the query requirements. In one embodiment, the optimizer designates any table that contains a number of records that is less than the min_row_threshold as a broadcasting table, even if the optimizer underestimates the number of intermediate transient records resulting from an initial join of multiple tables. The condition for the aforementioned designation as a broadcasting table is that the table on the other side of the join is created after data processing of two or more tables being joined and/or complex query conditions.
Query performance improvement system 104 receives a query that includes a first join of multiple tables (not shown) and further includes a subsequent second join with a smaller next table (not shown) (i.e., a table whose number of records is less than the number of intermediate transient records (i.e., actual intermediate transient records) resulting from the first join, which is prior to the second join). Query performance improvement system 104 also receives a new optimizer parameter: min_row_threshold 112, which indicates a threshold number of records in the aforementioned next table.
Optimizer 106 calculates intermediate transient record estimated count 114 (i.e., an estimate of a count of the number of intermediate transient records resulting from the aforementioned first join). Optimizer 106 also calculates a next table record count 116 (i.e., a count of the number of records in the aforementioned next table).
Optimizer 106 generates a query execution plan 118. If the next table record count 116 is less than min_row_threshold 112, query execution plan 118 includes a broadcast of records in the next table to data slices in an mpp environment, regardless of the intermediate transient record estimated count 114 and without including a broadcast of the intermediate transient records.
Machine learning system 107 tracks section actuals, determines patterns in estimated and actual cardinalities, and adjusts the value of min_row_threshold 112 based on the patterns.
The functionality of the components shown in
In step 204, query performance improvement system 104 (see
In step 206, query performance improvement system 104 (see
In step 208, query performance improvement system 104 (see
In step 210, query performance improvement system 104 (see
In step 212, query performance improvement system 104 (see
In one embodiment and in response to step 212, a query execution component (not shown in
Returning to step 212, if query performance improvement system 104 (see
In step 214, query performance improvement system 104 (see
After step 212 following the Yes branch of step 210 and after step 214 following the No branch of step 210, the process of
In one embodiment, over time and for multiple queries executed in the mpp environment, machine learning system 107 (see
(1) tracks (i) estimated cardinalities of records resulting from joins in the multiple queries and (ii) actual cardinalities of the records resulting from the joins in the multiple queries;
(2) based on the tracked estimated and actual cardinalities, adjusts the value of min_row_threshold 112 (see
(3) identifies a pattern in the tracked estimated and actual cardinalities, where the adjustment of the value of the min_row_threshold 112 (see
In one embodiment, the process of
(1) receives a second query whose execution in the mpp environment includes (i) complex conditions that include multiple conditions within a where clause in a select statement and (ii) a third join with a second table, where the third join is performed subsequent to an execution of the complex conditions;
(2) using optimizer 106 (see
(3) using optimizer 106 (see
(4) using optimizer 106 (see
(5) based on the fourth count being less than min_row_threshold 112 (see
The three database tables 302 are involved in a query 304. In step 202 (see
In step 204 (see
In step 206 (see
In step 208 (see
In contrast to the query performance improvement system 104 (see
Memory 404 includes a known computer readable storage medium, which is described below. In one embodiment, cache memory elements of memory 404 provide temporary storage of at least some program code (e.g., program code 414) in order to reduce the number of times code must be retrieved from bulk storage while instructions of the program code are executed. Moreover, similar to CPU 402, memory 404 may reside at a single physical location, including one or more types of data storage, or be distributed across a plurality of physical systems or a plurality of computer readable storage media in various forms. Further, memory 404 can include data distributed across, for example, a local area network (LAN) or a wide area network (WAN).
I/O interface 406 includes any system for exchanging information to or from an external source. I/O devices 410 include any known type of external device, including a display, keyboard, etc. Bus 408 provides a communication link between each of the components in computer 102, and may include any type of transmission link, including electrical, optical, wireless, etc.
I/O interface 406 also allows computer 102 to store information (e.g., data or program instructions such as program code 414) on and retrieve the information from computer data storage unit 412 or another computer data storage unit (not shown). Computer data storage unit 412 includes one or more known computer readable storage media, where a computer readable storage medium is described below. In one embodiment, computer data storage unit 412 is a non-volatile data storage device, such as, for example, a solid-state drive (SSD), a network-attached storage (NAS) array, a storage area network (SAN) array, a magnetic disk drive (i.e., hard disk drive), or an optical disc drive (e.g., a CD-ROM drive which receives a CD-ROM disk or a DVD drive which receives a DVD disc).
Memory 404 and/or storage unit 412 may store computer program code 414 that includes instructions that are executed by CPU 402 via memory 404 to improve a performance of a query. Although
Further, memory 404 may include an operating system (not shown) and may include other systems not shown in
As will be appreciated by one skilled in the art, in a first embodiment, the present invention may be a method; in a second embodiment, the present invention may be a system; and in a third embodiment, the present invention may be a computer program product.
Any of the components of an embodiment of the present invention can be deployed, managed, serviced, etc. by a service provider that offers to deploy or integrate computing infrastructure with respect to improving a performance of a query. Thus, an embodiment of the present invention discloses a process for supporting computer infrastructure, where the process includes providing at least one support service for at least one of integrating, hosting, maintaining and deploying computer-readable code (e.g., program code 414) in a computer system (e.g., computer 102) including one or more processors (e.g., CPU 402), wherein the processor(s) carry out instructions contained in the code causing the computer system to improve a performance of a query. Another embodiment discloses a process for supporting computer infrastructure, where the process includes integrating computer-readable program code into a computer system including a processor. The step of integrating includes storing the program code in a computer-readable storage device of the computer system through use of the processor. The program code, upon being executed by the processor, implements a method of improving a performance of a query.
While it is understood that program code 414 for improving a performance of a query may be deployed by manually loading directly in client, server and proxy computers (not shown) via loading a computer-readable storage medium (e.g., computer data storage unit 412), program code 414 may also be automatically or semi-automatically deployed into computer 102 by sending program code 414 to a central server or a group of central servers. Program code 414 is then downloaded into client computers (e.g., computer 102) that will execute program code 414. Alternatively, program code 414 is sent directly to the client computer via e-mail. Program code 414 is then either detached to a directory on the client computer or loaded into a directory on the client computer by a button on the e-mail that executes a program that detaches program code 414 into a directory. Another alternative is to send program code 414 directly to a directory on the client computer hard drive. In a case in which there are proxy servers, the process selects the proxy server code, determines on which computers to place the proxy servers' code, transmits the proxy server code, and then installs the proxy server code on the proxy computer. Program code 414 is transmitted to the proxy server and then it is stored on the proxy server.
Another embodiment of the invention provides a method that performs the process steps on a subscription, advertising and/or fee basis. That is, a service provider can offer to create, maintain, support, etc. a process of improving a performance of a query. In this case, the service provider can create, maintain, support, etc. a computer infrastructure that performs the process steps for one or more customers. In return, the service provider can receive payment from the customer(s) under a subscription and/or fee agreement, and/or the service provider can receive payment from the sale of advertising content to one or more third parties.
The present invention may be a system, a method, and/or a computer program product at any possible technical detail level of integration. The computer program product may include a computer readable storage medium (or media) (i.e., memory 404 and computer data storage unit 412) having computer readable program instructions 414 thereon for causing a processor (e.g., CPU 402) to carry out aspects of the present invention.
The computer readable storage medium can be a tangible device that can retain and store instructions (e.g., program code 414) for use by an instruction execution device (e.g., computer 102). The computer readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer readable storage medium includes the following: 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), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
Computer readable program instructions (e.g., program code 414) described herein can be downloaded to respective computing/processing devices (e.g., computer 102) from a computer readable storage medium or to an external computer or external storage device (e.g., computer data storage unit 412) via a network (not shown), for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card (not shown) or network interface (not shown) in each computing/processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing/processing device.
Computer readable program instructions (e.g., program code 414) for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, configuration data for integrated circuitry, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++, or the like, and procedural programming languages, such as the “C” programming language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
Aspects of the present invention are described herein with reference to flowchart illustrations (e.g.,
These computer readable program instructions may be provided to a processor (e.g., CPU 402) of a general purpose computer, special purpose computer, or other programmable data processing apparatus (e.g., computer 102) to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium (e.g., computer data storage unit 412) that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions (e.g., program code 414) may also be loaded onto a computer (e.g. computer 102), other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the Figures. For example, two blocks shown in succession may, in fact, be accomplished as one step, executed concurrently, substantially concurrently, in a partially or wholly temporally overlapping manner, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
While embodiments of the present invention have been described herein for purposes of illustration, many modifications and changes will become apparent to those skilled in the art. Accordingly, the appended claims are intended to encompass all such modifications and changes as fall within the true spirit and scope of this invention.