Embodiments of the invention relate to joins for hash tables, in particular, for an efficient join on a dynamically compressed inner for better fit into a cache hierarchy.
Hash joins are a common operator in business intelligence (BI) queries. Hash joins involve many random accesses to hash tables. On modern processors, the performance of joins depends on how well the join data structures fit in the memory hierarchy.
Embodiments of the invention relate to dynamically compressing an inner for better fit into a cache hierarchy. One embodiment includes a method including joining data between at least two data sets. Values of one or more join attributes of each of the data sets is represented in a compressed form, indicated by an encoding scheme. A compression scheme for the one or more joins attribute is dynamically selected.
These and other features, aspects and advantages of the present invention will become understood with reference to the following description, appended claims and accompanying figures.
Aspects of the present invention are described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products, according to embodiments of the invention. 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 may 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 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.
In use, the gateway 101 serves as an entrance point from the remote networks 102 to the proximate network 108. As such, the gateway 101 may function as a router, which is capable of directing a given packet of data that arrives at the gateway 101, and a switch, which furnishes the actual path in and out of the gateway 101 for a given packet.
Further included is at least one data server 114 coupled to the proximate network 108, which is accessible from the remote networks 102 via the gateway 101. It should be noted that the data server(s) 114 may include any type of computing device/groupware. Coupled to each data server 114 is a plurality of user devices 116. Such user devices 116 may include a desktop computer, laptop computer, handheld computer, printer, and/or any other type of logic-containing device. It should be noted that a user device 111 may also be directly coupled to any of the networks in some embodiments.
A peripheral 120 or series of peripherals 120, e.g., facsimile machines, printers, scanners, hard disk drives, networked and/or local storage units or systems, etc., may be coupled to one or more of the networks 104, 106, 108. It should be noted that databases and/or additional components may be utilized with, or integrated into, any type of network element coupled to the networks 104, 106, 108. In the context of the present description, a network element may refer to any component of a network.
According to some approaches, methods and systems described herein may be implemented with and/or on virtual systems and/or systems, which emulate one or more other systems, such as a UNIX system that emulates an IBM z/OS environment, a UNIX system that virtually hosts a MICROSOFT WINDOWS environment, a MICROSOFT WINDOWS system that emulates an IBM z/OS environment, etc. This virtualization and/or emulation may be implemented through the use of VMWARE software in some embodiments.
In other examples, one or more networks 104, 106, 108, may represent a cluster of systems commonly referred to as a “cloud.” In cloud computing, shared resources, such as processing power, peripherals, software, data, servers, etc., are provided to any system in the cloud in an on-demand relationship, therefore allowing access and distribution of services across many computing systems. Cloud computing typically involves an Internet connection between the systems operating in the cloud, but other techniques of connecting the systems may also be used, as known in the art.
A hash table (HT) is made up of two parts: an array (the actual table where the data to be searched is stored) and a mapping function, known as a hash function. With a hash table, any value may be used as an index, such as a floating-point value, a string, another array, or even a structure as the index. This index is called the key, and the contents of the array element at that index is called the value. Therefore, an HT is a data structure that stores key/value pairs and can be quickly searched by the key. The hash function is a mapping from the input space to the integer space that defines the indices of the array. The hash function provides a way for assigning numbers to the input data such that the data can then be stored at the array index corresponding to the assigned number.
A hash join is an example of a join process and is used in the implementation of a relational database management system (DMS). The task of a join process is to find, for each distinct value of the join attribute(s), the set of tuples in each relation which have that value. Hash joins require an equijoin predicate (a predicate comparing values from one table with values from the other table using the equals operator ‘=’).
An inner join creates a new result table by combining column values of two tables (e.g., table1 and table2) based upon the join-predicate. The query compares each row of table1 with each row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row.
A classic hash join algorithm for an inner join of two relations proceeds as follows. First prepare an HT of the smaller relation. The HT entries consist of the join attribute and its row. Because the HT is accessed by applying a hash function to the join attribute, it is quicker to find a given join attribute's rows by using this table than by scanning the original relation. Once the HT is built, the larger relation is scanned and the relevant rows from the smaller relation are found by looking in the HT. The first phase is usually called the “build” phase, while the second is called the “probe” phase. Similarly, the join relation on which the HT is built is called the “build” (also referred to as ‘inner’) input, whereas the other input is called the “probe” input (also referred to as ‘outer’). The process requires that the smaller join relation fits into memory, which is sometimes not the case. A simple approach to handling this situation proceeds as follows:
In one or more embodiments, the system 100 utilizes a process for encoding join keys that produces a very tight code, guarantees that all keys will be encoded, and forms the encoding very cheaply, with no hash table lookups involved. Embodiments of the invention relate to dynamically compressing an inner for better fit into a cache hierarchy. One embodiment includes a method including joining data between at least two data sets. Values of one or more join attributes of each of the data sets is represented in a compressed form. A compression scheme for the join attribute is dynamically selected (e.g., based on the data type of a join attribute seen during a join operation).
In one example, the workstation may have resident thereon an operating system, such as the MICROSOFT WINDOWS Operating System (OS), a MAC OS, a UNIX OS, etc. It will be appreciated that other examples may also be implemented on platforms and operating systems other than those mentioned. Such other examples may include operating systems written using JAVA, XML, C, and/or C++ language, or other programming languages, along with an object oriented programming methodology. Object oriented programming (OOP), which has become increasingly used to develop complex applications, may also be used.
In one embodiment, for numerical typed key columns, the encoding processor 307 encodes in the range from minimum to maximum value of columns of an inner, (e.g., as the inner exists during actual query execution). In one embodiment, if there are N possible values (in the domain) within that range, the encoding processor 307 represents them with log N bits, where N is a positive integer. All these logarithms must be taken to base 2, and the result rounded up to the nearest integer. While this produces a very compact code, it has a requirement that the scanning processor 310 has to scan the complete the join inner before the encoding processor 307 performs the assigning of codes—meaning two passes over the input. When this is not allowed, another embodiment includes the encoding processor 307 using the minimum and maximum (or second or third minimum and maximum, discarding possible outliers) found from statistics collection over the inner join, but this means the encoding processor 307 needs to support un-encoded keys.
In one embodiment, dates, times, and timestamps are treated as numerical typed key columns because they have a natural minus operator that is used for encoding. In the case of decimals (and Decfloats), the default minus operator may be used. However, greater efficiency is obtained by tracking the largest used scale in the key values, and the encoding processor 307 only encoding values within that scale. For example a DECIMAL(12,7) all of whose values range between 0.00 and 100.99, with no value having scale more than two digits, needs only log(10099+1) bits.
In one embodiment, the encoding processor 307 stores min-key and max-key values of the inner separately in a local list because sometimes MAXINT is used as a default value and will needlessly increase the range.
In one embodiment, for string typed key columns (e.g., ‘CUST0001,’ etc.), if there is a common prefix, the encoding processor 307 considers the suffix (after the longest common prefix) and performs a min/max of the suffix—e.g., if the suffix is 8 bytes, the encoding processor 307 encodes into an 8-byte code in the worst case (and may sometimes perform better based on min/max). In one embodiment, the encoding processor 307 supports overflow values (e.g., 1, 2, etc.) that do not match the prefix.
In one embodiment, the encoding of the key values interacts with hashing and partitioning as follows. The join keys are typically hashed onto a hash table for fast lookups. This hashing, and partitioning, has to be performed on un-encoded keys because it is performed during the first scanning pass over the inner, when codes have not yet been assigned. In one embodiment, for composite join keys, the encoded join keys may be concatenated, but only after partitioning.
In one embodiment, encoding during the outer scan conducted as follows. During the outer scan the encoding processor 307 (
The following is an example of an evaluator sequence. Suppose a key is C1, C2; auxiliary: month(c3), c4. In this example, the inner evaluator sequence is: LCOV(C1)→EncodePK→LCOV(C2)→EncodePK→Concatenate→LCOV(C3)→calculate month from C3→encoding on the month (if any)→LCOV(C4)→Concatenate→HashPartitionEval (where LCOV is an abbreviation for load column values, and PK is an abbreviation for the join attribute from the inner side). The join evaluators on the inner side include:
HashPartition Evaluator partitions the values according to the hash of the values of the join attribute.
In one embodiment, process 500 may provide that for numerical typed key columns, the compression scheme selected is assigning codes for encoding in a range from a minimum value to a maximum value of one of the data sets involved in the join. In one embodiment, for N possible values within the range, the values are represented as ceiling (log N bits), where N is a positive integer and the ceiling function rounds up to the nearest integer or to the nearest multiple of significance. In one embodiment, process 500 may include scanning all records of the one of the data sets prior to assigning the codes.
In one embodiment, for decimal typed key columns, process 500 may include tracking a largest used scale in the values present in one of the data sets involved in the join, and only encoding values within that scale. In one embodiment, for character string typed key columns, if a common prefix exists among the values present in one of the data sets involved in the join, process 500 may use a suffix and assign codes in a range from minimum value to maximum value of a the suffix of those values.
In one embodiment, process 500 may further include hashing join keys onto a particular one of two hash tables and partitioning the particular one hash table. For composite join keys, process 500 may concatenate encoded join keys after the partitioning. In one embodiment, for join inner-joins, process 500 may provide that any records containing join column values that are not representable in the compression scheme are eliminated. In one embodiment, for left outer joins, process 500 may provide that for any records containing join column values that are not representable in the compression scheme selected, the join column values are marked as NULL and assigned a dummy code. In one embodiment, process 500 may include building a bitmap based on a range from minimum value to maximum value indicating join keys found during a scan. In one embodiment, the bitmap is used as a join filter. In one embodiment, for left outer joins, process 500 may include that join column values for records that fail to find a match when looking up the join filter are marked as NULL.
In one embodiment, for numerical typed key columns, the encoding scheme selected for process 600 may include assigning codes for encoding in a range from minimum value to maximum value of one of the data sets involved in the join. In one embodiment, for N possible values within the range, the values are represented as ceiling (log N bits), where N is a positive integer. In one embodiment, for decimal typed key columns, process 600 may include tracking a largest used scale in the values present in one of the data sets involved in the join, and only encoding values within that scale. In one embodiment, for character string typed key columns, if a common prefix exists among the values present in one of the data sets involved in the join, process 600 may include using a suffix and assign codes in a range from minimum value to maximum value of a suffix of those values. In one embodiment, for join inners, process 600 may include eliminating any records containing join column values that are not representable in the compression scheme selected. In one embodiment, for left outer joins, process 600 may include for any records containing join column values that are not representable in the compression scheme selected, marking the join column values as NULL.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or computer program product. Accordingly, aspects of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a “circuit,” “module” or “system.” Furthermore, aspects of the present invention may take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
Any combination of one or more computer readable medium(s) may be utilized. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, 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. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The program code 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).
Aspects of the present invention are described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. 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 may 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 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 program instructions may also be stored in a computer readable medium that can direct a computer, other programmable data processing apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer readable medium produce an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing 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 executed substantially concurrently, 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.
References in the claims to an element in the singular is not intended to mean “one and only” unless explicitly so stated, but rather “one or more.” All structural and functional equivalents to the elements of the above-described exemplary embodiment that are currently known or later come to be known to those of ordinary skill in the art are intended to be encompassed by the present claims. No claim element herein is to be construed under the provisions of 35 U.S.C. section 112, sixth paragraph, unless the element is expressly recited using the phrase “means for” or “step for.”
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the singular forms “a”, “an” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms “comprises” and/or “comprising,” when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The corresponding structures, materials, acts, and equivalents of all means or step plus function elements in the claims below are intended to include any structure, material, or act for performing the function in combination with other claimed elements as specifically claimed. The description of the present invention has been presented for purposes of illustration and description, but is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the invention. The embodiment was chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.