Accelerated filtering, grouping, and aggregation in database systems
By adopting column storage tables and processor configuration methods in the database system, using filters and indicators to process encoded value column vectors, and selecting appropriate algorithms, the problem of low database query efficiency is solved, and queries for quickly processing large-scale data are realized. need.
Patent Information
- Application Number
- CN201880088339.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2017-12-01
- Filing Date
- 2018-11-30
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2038-11-30
AI Technical Summary
When processing queries, existing database management systems take too long to respond when faced with large amounts of data, resulting in low query efficiency and inability to meet real-time or pseudo-real-time search requirements.
Adopt column store table and processor configuration methods to process encoded value column vectors through filters and indicators, and select appropriate algorithms to improve query efficiency, including techniques such as compression, aggregate selection, and special group allocation.
It significantly reduces the query result return time, improves the search query efficiency of the database system, and can process large-scale data more quickly.
Smart Images

Figure CN111699480B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to database searching, and more particularly to methods and systems for improving the efficiency of search queries in database systems. Background Art
[0002] As technology advances, the amount of information stored in electronic form and the need for real-time or pseudo-real-time capabilities to search this information continue to increase. Database management systems are designed to organize data in a form that facilitates efficient searching and retrieval of selected information. A typical database management system allows a user to submit a "query" in a query language for retrieving information that meets specific search parameters.
[0003] In known database management systems, a particular query may be processed against data within a database using a static, query-based algorithm or process without regard to the specific characteristics of the query. Because the data against which the query is processed may be very large (e.g., hundreds of millions or billions of individual entries), such a static algorithm or process typically requires one or more orders of magnitude more clock cycles than individual entries to return results to the query, making the query response time unacceptably large. Therefore, it would be advantageous to reduce the time required to return results to a user query of a database management system. Summary of the invention
[0004] On the one hand, a method for causing a processor to perform a query on a column storage table of encoded values is provided. The method includes configuring the processor to receive a query, the query including a filter to be applied to at least a first column vector of encoded values. The method includes configuring the processor to process the query for each of the encoded values in the first column vector, thereby generating a first vector indicating the corresponding encoded values that passed the filter or did not pass the filter. The method includes configuring the processor to determine an indicator of the encoded values that passed the filter and the encoded values that did not pass the filter from the first vector relative to the encoded values in the first column vector. The method includes configuring the processor to determine the bit length of the encoded values in the first column vector. The method includes configuring the processor to select an algorithm for processing the query from a plurality of algorithms based on the indicator and the bit length of the determined encoded values for at least a subset of the encoded values in the first column vector.
[0005] On the other hand, a non-transitory computer-readable medium including code is provided, which, when executed, causes a processor to receive a query, the query including a filter to be applied to at least a first column vector of encoded values. The code, when executed, causes the processor to process the query for each of the encoded values in the first column vector, thereby generating a first vector indicating corresponding encoded values that passed the filter or did not pass the filter. The code, when executed, causes the processor to determine an indicator of the encoded values that passed the filter and the encoded values that did not pass the filter from the first vector relative to the encoded values in the first column vector. The code, when executed, causes the processor to determine the bit length of the encoded values in the first column vector. The code, when executed, causes the processor to select an algorithm for processing the query from a plurality of algorithms based on the indicator and the bit length of the determined encoded values for at least a subset of the encoded values in the first column vector.
[0006] On the other hand, a system configured to perform a query on a column storage table of coded values is provided. The system includes at least one register configured to hold one or more values. The system includes at least one processor. The system includes a computer-readable medium, the computer-readable medium including code, which when executed causes the processor to receive a query, the query including a filter to be applied to at least a first column vector of coded values. The code, when executed, causes the processor to process the query for each of the coded values in the first column vector, thereby generating a first vector indicating the corresponding coded values that passed the filter or did not pass the filter. The code, when executed, causes the processor to determine an indicator of the coded values that passed the filter and the coded values that did not pass the filter from the first vector relative to the coded values in the first column vector. The code, when executed, causes the processor to determine the bit length of the coded values in the first column vector. The code, when executed, causes the processor to select an algorithm for processing the query from a plurality of algorithms based on the indicator and the bit length of the determined coded values for at least a subset of the coded values in the first column vector. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] Figure 1 is a block diagram illustrating a system for executing queries against a data set according to some embodiments;
[0008] Figure 2 is a diagram showing that according to some embodiments, the Figure 1 A block diagram of several modules or engines in the system;
[0009] Figure 3 A flowchart illustrating a process for performing a query on a table of coded values according to some embodiments;
[0010] Figure 4 A process for performing selection by compression for a query is shown according to some embodiments;
[0011] Figure 5 It is shown by Figure 4 Block diagrams of certain data vectors, registers, and operations described;
[0012] Figure 6 A process for performing aggregate selection for a query according to some embodiments is shown;
[0013] Fig. 7A and Figure 7B Shown by Figure 6 Block diagrams of certain data vectors, registers, and operations described;
[0014] Figure 8 A process for performing selection by special group assignment for a query is shown in accordance with some embodiments;
[0015] Fig. 9 It is shown by Figure 8 Block diagrams of certain data vectors, registers, and operations described;
[0016] Fig.10 A process for performing group by and group by classification for a query is shown according to some implementations;
[0017] Fig.11A and Fig. 11B Shown by Fig.10 Block diagrams of certain data vectors, registers, and operations described;
[0018] Fig.12 A process for performing in-register group by count and group by sum for a query is shown according to some embodiments;
[0019] Fig.13 It is shown by Fig.12 Block diagrams of certain data vectors, registers, and operations described;
[0020] Fig.14 A process for performing a group by and multi-aggregation for a query is shown according to some embodiments;
[0021] Fig.15 It is shown by Fig.14 Block diagrams of certain data vectors, registers, and operations described;
[0022] Fig.16 shows a process for performing a fast group by count (*) using bit-level logic for a query in accordance with some embodiments;
[0023] Fig.17 It is shown by Fig.16 A block diagram of some of the data vectors, registers, and operations described. DETAILED DESCRIPTION
[0024] In the following description, specific details such as specific architectures, interfaces, technologies, etc. are set forth for purposes of explanation rather than limitation, in order to provide a thorough understanding of the concepts described herein. However, it will be apparent to those skilled in the art that other embodiments that depart from these specific details may be practiced. Similarly, the present application is directed to example embodiments as shown in the accompanying drawings, and is not intended to be limited beyond the terms explicitly included in the claims. For the purposes of simplicity and clarity, detailed descriptions of known devices and methods are omitted so as not to obscure the description with unnecessary details. However, the lack of any description of any particular device or method does not necessarily indicate that it or its function is known.
[0025] The accompanying drawings describe an example query processing system using a paradigm of a database query system that processes queries formed using the operations and formats of a standard structured query language (SQL). However, those skilled in the art will recognize that the principles described herein may also be applied to the processing of queries in other programming and query languages.
[0026] Figure 1 1 is a block diagram illustrating a system 100 for executing queries against a data set according to some embodiments. The system 100 includes a central processing unit (CPU) 102, a memory 120, and a storage 130. The CPU 102 includes a processor 106, at least one cache 108, a clock 110, and a plurality of registers 104a, 104b ... 104n (104a to 104n). In some embodiments, one or more registers described herein, including registers 104a to 104n, may be single instruction multiple data (SIMD) registers. However, the present disclosure contemplates the use of any type of data register having a capacity of any number of bits.
[0027] Each of the registers 104a to 104n may be configured to hold data received from each other and / or from one or more of the processor 106, cache 108, memory 120, or storage 130. Each of the registers 104a to 104n may be a 256-bit register configured to store up to 256 bits of data, e.g., for one or more operations to be performed simultaneously by the processor 106. However, the registers 104a to 104n are not limited in this regard and may have any other number of bits and / or may be any other type of register.
[0028] The processor 106 is configured to execute one or more operations or instructions for processing data held in at least one of the registers 104a-104n (which data is ultimately retrieved from one or more of the cache 108, the memory 120, or the storage 130) or a query of data held in one or more of the cache 108, the memory 120, or the storage 130. In some embodiments, such instructions may be single-input multiple-data (SIMD) instructions compatible with Advanced Vector Extensions (AVX), such as AVX2 that extends most integer commands to 256 bits, AVX512 that extends most integer commands to 512 bits, or any other extension that extends integer commands to an arbitrary number of bits.
[0029] Clock 110 is configured to provide a train of clock signals used to time, control, and execute computer operations within system 100 .
[0030] Cache 108 may include data storage that is physically closer to processor 106 than memory 120 or storage 130. In some implementations, cache 108 may have a smaller storage capacity than memory 120 or storage 130, but certain data may be read from or written to cache 108 in a shorter time period than certain data may otherwise be read from or written to memory 120 or storage 130.
[0031] Memory 120 may include data storage, such as random access memory (RAM), separate from cache 108 and storage 130, from which data stored may be accessed. In some implementations, memory 120 may have a larger storage capacity than cache 108 and a smaller storage capacity than storage 130. In some implementations, certain data may be read from or written to memory 120 in a shorter period of time than bits of data may otherwise be read from or written to storage 130, but certain data may otherwise be read from or written to cache 108 but may take a longer period of time to be read from or written to memory 120.
[0032] Storage 130 may include data storage separate from cache 108 and memory 120, such as a hard drive or a database server, from which data stored may be accessed. In some implementations, storage 130 may have a greater storage capacity than cache 108 or memory 120, however, certain data may take a longer period of time to be read from or written to storage 130 than the certain data could otherwise be read from or written to cache 108 or memory 120.
[0033] Although CPU 102 is shown as having one processor 106, cache 108, clock 110, and a set of registers 104a to 104n, the present disclosure is not limited thereto, and multiple such features may be present in each of one or more CPUs, e.g., to provide one or more multi-core processors for system 100. Furthermore, any discussion of operations performed by processor 106 may indicate operations performed by a single processor 106, or operations performed by different processors of a plurality of similar processors.
[0034] Figure 2 is a diagram showing that according to some embodiments, the Figure 1 200 is a block diagram of several modules or engines within the system 100.
[0035] Schematic 200 includes a decoding engine 212 configured to decode one or more encoded data. Schematic 200 also includes a filtering engine 214 configured to filter one or more groups of data according to a set of filter parameters defined by a query 250. Schematic 200 also includes a group ID mapping engine 216 configured to map one or more group IDs from one or more groups of data to be grouped according to a set of parameters defined by the query 250. Schematic 200 also includes an aggregation engine 218 configured to aggregate one or more data values based on a set of parameters defined by the query 250 to provide a result output 240. In some embodiments, one or more of the decoding engine 212, the filtering engine 214, the group ID mapping engine 216, and the aggregation engine 218 can be executed by the processor 106 (see Figure 1 ) and / or another processor similar to processor 106 of system 100.
[0036] In some implementations, table 220 includes data against which query 250 may be executed. Table 220 may include encoded data stored in a column storage format. For example, in a column storage format, each of one or more columns 222 of the encoded data holds a value of a particular field and is stored in a memory (e.g., memory 120 and / or storage 130 (see Figure 1)) corresponding positions in. In some embodiments, the columns 222 can each include billions of rows or more of encoded data. Thus, each column 222 can be divided into multiple consecutive segments 224 of, for example, 1 million (M) rows of encoded data. Each segment 224 of a given column 222 can be encoded separately from each other segment 224 of another column 222 using an encoding technique such as dictionary encoding, run length encoding, or integer value encoding, but other encoding techniques are also contemplated.
[0037] Dictionary encoding involves mapping instances of the same cyclic bits in the original data to corresponding integers in a corresponding dictionary, and then replacing the cyclic bits with the corresponding integers, thereby reducing the number of bits required to describe the original data. A dictionary can be employed to represent a collection of objects that map between original data values and integer sequence numbers of these values in one or two directions. Table 1 below shows an example uncoded table.
[0038]
[0039] Table 1
[0040] Since each segment 224 of each column 222 ("partition", "state", "sale_amt") can be encoded with its own dictionary of values, Table 2 shows an example dictionary for the "partition" column, Table 3 shows an example dictionary for the "state" column, and Table 4 shows an example dictionary for the "sale_amt" column.
[0041] Encoded value Original value 0 East 1 West
[0042] Table 2
[0043] Encoded value Original value 000 New York 001 California 010 Florida 011 Washington 100 Nevada
[0044] Table 3
[0045] Encoded value Original value 00 1,000 01 2,000 10 3,000 11 4,000
[0046] Table 4
[0047] The dictionary of Table 1 has two different original values (East / West), and thus can be encoded using 1 bit. The dictionary of Table 2 has 5 different original values (New York / California / Florida / Washington / Nevada), and thus can be encoded using 3 bits. The dictionary of Table 3 has 4 original values (1,000 / 2,000 / 3,000 / 4,000), and thus can be encoded using 2 bits. Therefore, using the dictionaries of Tables 2 to 4, the data shown in Table 1 can be dictionary encoded as shown in Table 5. This dictionary encoding can be used for any data type, such as integers, strings, etc.
[0048]
[0049]
[0050] Table 5
[0051] Run-length encoding includes indicating multiple repeating values by indicating the smallest unit of a repeating number followed by an integer indicating the number of times the smallest unit is repeated consecutively. For example, WWWWWWWWWWWWWWBBBBBBBBBBBB will be encoded as W12B12, reducing 24 characters to 6. Similarly, WWBWWBWWBWWB will be encoded as WWB4, reducing 12 characters to 4. Although this example of run-length encoding is shown using ASCII characters, it is also generally possible to ultimately store such data in binary form.
[0052] For purposes of the present disclosure, queries 250 executed against encoded data in table 220 are executed by evaluating the encoded data in segments 224 of columns 222 of table 220 in batches 230. For example, batches 230 may include a moving window of a fixed number of rows (e.g., up to 4096 rows) per column 222. Each batch is fully processed before advancing to the next batch of rows, and previously processed batches are not revisited during processing of the same query or subquery.
[0053] Thus, one or more of the decoding engine 212, the filtering engine 214, the group ID mapping engine 216, and the aggregation engine 218 may sequentially process each batch 230 according to the parameters of the particular query or sub-query 250. In some embodiments, such processing may include loading the encoded data from each batch 230 into registers 104a to 104n and processing the data at least in part as described below in conjunction with any of the figures herein. However, any operations described herein with any type of data loaded and / or manipulated in registers may alternatively operate on the data while stored in an array or other type of data structure (such as cache 108, memory 120, or storage 130).
[0054] In performing such processing, one or more of the decoding engine 212, the filtering engine 214, the group ID mapping engine 216, and the aggregation engine 218 can utilize a set of functions, such as C programming language functions within the vector toolbox 202, which are configured to perform specific operations on all data maintained in one or more column vectors, associated dictionaries, and aggregation dictionaries simultaneously at a specific time. In some embodiments, the data portions in one or more column vectors can be optionally stored in registers such as registers 104a to 104n ( Figure 1) are stored and manipulated in registers of a query or subquery 250. In some embodiments, such functionality may include a selection function that collects values based on the parameters of the query or subquery 250 while retaining their encoding, as will be described below. Such functionality may further include a cascading function that can cascade data from more than one column of table 220, as will be described below. In some cases, such a cascade can combine data encoded using different encoding schemes (e.g., RLE and dictionary encoding). Such functionality may further include an aggregation function, which may include grouping data based on one or more parameters of the query or subquery 250 and / or performing operations that require aggregation of multiple values, such as determining the count, sum, average, minimum, maximum, standard deviation, median, mode, etc. of items that pass a specific filter and belong to a specific group, as will be described below. Such functionality may further include dictionary encoding and decoding functions, such as generating and utilizing dictionaries.
[0055] Figure 3 A flowchart 300 is shown of a process for performing a query 250 on a table 220 of coded values according to some embodiments. Figure 3 Certain steps or actions are described, but the process for performing a query 250 on the table of encoded values 220 may include fewer than all of the steps described, and / or steps in addition to or in place of the steps described.
[0056] In some embodiments, flowchart 300 can be used to process a query or subquery 250 that includes both selection (e.g., selecting a subset of values in one or more columns 222 of table 220 based on one or more parameters of the query or subquery 250) and grouping and aggregation of the subsets of values identified by the selection (e.g., classifying and performing aggregation operations such as sum, minimum, maximum, average, standard deviation, median, mode, etc. on the selected subsets of values based on one or more parameters of the query or subquery 250).
[0057] Block 302 includes receiving a query that includes a filter to be applied to at least a first column vector of encoded values. For example, processor 106 ( Figure 1 ) can receive query 250( Figure 2 ). Query 250 may include a filter to be applied to at least one column vector of encoded values of column 222 of table 220. A non-limiting example of such a query is as follows:
[0058] Select state, sum(sale_amt)
[0059] From table_of_sales
[0060] Among them, division == 'East'
[0061] Group by state
[0062] This example query selects entries from the table "table_of_sales" where the partition is "East" and indicates that the output results should be the sum of "sale_amt" for each "State", grouped by "State". Thus, in such an example query, partition == 'East' would be a filter or selection, sum(sale_amt) would be an aggregation (sum), and group by state would be an indication of how the results should be grouped or categorized.
[0063] Block 304 includes processing a query for each of the encoded values in the first column vector to generate a first vector indicating corresponding encoded values that passed or failed the filter. For example, processor 106 ( Figure 1 ) can be configured to generate a first vector (optionally described herein as a selection byte vector) that indicates whether each row in batch 230 satisfies the filter parameters via a first value (e.g., 0x00 or all bits are not set), or does not satisfy the filter parameters via a second value (e.g., 0xFF or all bits are set). Such a selection byte vector can have entries of length 1 byte (8 bits), consistent with how the output of AVX2 compare instructions store single-byte elements. Since the encoded data of table 220 is processed in batches 230, such a selection byte vector can have a number of rows equal to the number of rows of table 220 processed in batch 230 (e.g., 4096 rows). A non-limiting example of a portion of such a selection byte vector is shown in Table 6 below, corresponding to a portion of table_of_sales of Table 5 and encoded using the example dictionary previously described in conjunction with Tables 2 to 4 for the query shown in the previous paragraph:
[0064] 0xFF 0x00 0xFF 0xFF 0x00 0x00 0xFF 0xFF
[0065] Table 6
[0066] Block 306 includes determining, from the first vector, indicators of coded values that passed the filter and coded values that did not pass the filter relative to the coded values in the first column vector. For example, processor 106 ( Figure 1) may be configured to determine, from the first vector, indicators of encoded values that passed the filter and encoded values that did not pass the filter, relative to the encoded values in the first column vector. Such an indicator may indicate the selectivity of the filter defined by the parameters of the query 250 on the portion of the table 220 included in the current batch 230. Using Table 6 as an example, such an indicator of selectivity may indicate that the filter passed 5 of the 8 rows, corresponding to a selectivity of 62.5% or 0.625. In this example, the filter or selection eliminated 3 of the 8 rows. However, depending on the parameters of the particular filter used, the selectivity may range from 0% (0.000) to 100% (1.000), inclusive.
[0067] Block 308 includes determining the bit length of the encoded values in the first column vector. For example, processor 106 (see Figure 1 ) can be configured to determine the bit length of the encoded value in the column vector being evaluated, for example, for the example query shown above, the column vector of sale_amt of Table 5 has a bit length of 2 bits.
[0068] Block 310 includes selecting an algorithm for processing the query from a plurality of algorithms for a subset of the encoded values in the first column vector based on the indicator and the determined bit length of the encoded values. For example, the following describes an algorithm for performing selection, grouping, and / or aggregation of the encoded values to generate output 240 (see Figure 2 ) of the query 250. However, depending on the selectivity of the filter defined by the query 250 and the bit length of the encoded value, some of these processes or algorithms are more efficient than others in terms of clock cycles required to execute the query 250. For example, as will be described below, between selection by compression, selection by aggregation, and selection by special group assignment, at a selectivity of 62.5% and a bit width of 2 bits, some embodiments may select selection by compression as the preferred selection process.
[0069] Selection by compression
[0070] The compressed vector operation takes two inputs: the previous combined Figure 3 The selection byte vector (first vector) described in block 304 of FIG. 1 and an input column vector having any number of elements from which an output column vector can be generated. The element size of the input column vector can be any of 1 byte, 2 bytes, 4 bytes, or 8 bytes. The result of the compression is an output column vector having all entries of the input column vector indicated by the selection byte vector having passed the filter defined by query 250 (e.g., having corresponding row entries of 0xFF). The following references Figure 4 and Figure 5 Description selection by compression, Figure 4shows a process for performing select by compression for a query 250 according to some embodiments, Figure 5 It is shown by Figure 4 A block diagram of some of the data vectors, registers, and operations described.
[0071] Despite the combination Figure 4 Certain steps or actions are described, but the process for performing selection by compression for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0072] Block 402 includes adding bits to each of at least a subset of the encoded values in the first column vector, thereby generating decompressed encoded values of the first column vector, each decompressed encoded value having the same length. The same length can be one byte, two bytes, four bytes, or eight bytes. For example, referring to Figure 5 , the encoded value of the given first column vector 512 does not have to be encoded with a full byte length. Therefore, in order to ensure that registers 104a to 104n (see Figure 1 ), and to ensure that the encoded values of the first column vector 512 each fit completely into a given register 104a, the processor 106 ( Figure 1 ) The encoded values of the first column vector 512 may be decompressed to the next largest size of 1 byte, 2 bytes, 4 bytes, or 8 bytes using a decompression operation 514 to generate a corresponding first column vector 516 of decompressed encoded values. n The byte size (where n = 0, 1, 2, or 3) provides such a guarantee.
[0073] Block 404 includes loading a first subset of values into corresponding lanes of a first register, the first subset including the decompressed encoded values. Figure 5 , processor 106( Figure 1 ) can load the first subset of decompressed encoded values, now having full byte length, from the decompressed first column vector 516 into the corresponding lanes of register 104a using a load operation 522. Figure 5 , a channel is indicated by a single box with a length of 1 byte, although the channel can be any length based on the data being loaded.
[0074] Block 406 includes loading a second subset of values into corresponding lanes of a second register, the second subset including values of the first vector corresponding to the first subset of values. Figure 5 , processor 106( Figure 1) may perform a load operation 524 to load a second subset of the values of the selection byte vector 518 (first vector) into the corresponding lanes of the register 104b. The second subset of values 518 corresponds to the first subset of the values of the decompressed first column vector 516 and is loaded into the register 104b. Since the values of the selection byte vector 518 (first vector) each have a length of 1 byte, an integer number of decompressed encoded values may be loaded into the register 104b. Since the second subset of the values of the selection byte vector loaded into the register 104b corresponds to the first subset of the decompressed encoded values loaded into the register 104a, the same number of values of the second byte vector 518 are loaded into the register 104b, and in the same order, as the decompressed encoded values were loaded into the register 104a.
[0075] Block 408 includes outputting the decompressed encoded value that passed the filter from the first register to the filtered first column vector based on the value in the second subset using a single instruction. Figure 5 , processor 106( Figure 1 ) can output the decompressed encoded values that pass the filter from register 104a to the filtered first column vector 540 based on the value of the selection byte vector 518 (first vector) loaded into register 104b using a single instruction (output operation 530). In some embodiments, such an operation can be an AND operation between corresponding channels of registers 104a and 104b (e.g., between the decompressed encoded values from the decompressed first column vector 516 loaded into register 104a and the corresponding values from the selection byte vector 518 (first vector) loaded into register 104b).
[0076] Aggregation Selection
[0077] The vector operation of aggregate selection utilizes some steps of the process previously described for selection by compression, while introducing additional and / or alternative steps. Figure 6 as well as Fig. 7A and 7B Describes the aggregation selection, Figure 6 shows a process for performing aggregate selection for a query 250 according to some embodiments, Fig. 7A and 7B Shown by Figure 6 A block diagram of some of the data vectors, registers, and operations described.
[0078] Despite the combination Figure 6 Certain steps or actions are described, but the process for performing aggregate selection for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0079] Block 602 includes generating a second vector including a plurality of consecutive integer values. In some implementations, the length of the integer values may be one byte, two bytes, four bytes, or eight bytes. For example, referring to Fig. 7A , the processor 106 may be configured to generate a second vector 702 having entries that are consecutive integer values. In some implementations, the consecutive integers start with zero, and the second vector 702 may have as many entries as the selection index vector 518 described previously.
[0080] Block 604 includes loading a first subset of values into corresponding lanes of the first register, the first subset including consecutive integer values of the second vector. Fig. 7A , processor 106( Figure 1 ) may utilize a load operation 722 to load a first subset of consecutive integer values from the second vector 702 into corresponding lanes of the register 104a.
[0081] Block 606 includes loading a second subset of values into corresponding lanes of a second register, the second subset including the values of the first vector. Fig. 7A , processor 106( Figure 1 ) may perform a load operation 724 to load a second subset of the values of the select byte vector 518 into the corresponding lanes of register 104b. The first subset of values are those values at the same locations and in the same order within the second vector 712 as the locations of the second subset of values within the select byte vector 518. Thus, when comparing corresponding lanes of registers 104a and 104b, the values in register 104b may be used as a mask for the values in register 104a.
[0082] Block 608 includes outputting integer values from the first register into the index vector based on the values in the second subset using a single instruction. Fig. 7A , processor 106( Figure 1) can output each integer value from register 104a into a third vector 740 with a single AVX2 SIMD instruction (output operation 730), where the corresponding lane of register 104b holds the value of the select byte vector 518 indicating that the filter passed, without outputting each integer value from register 104a into a third vector 740 with a corresponding lane of register 104b holding the value of the select byte vector 518 indicating that the filter did not pass. In some embodiments, such an operation can be an AND operation between corresponding lanes of registers 104a and 104b (e.g., between the integer values from the second vector 712 loaded into register 104a and the corresponding values from the select byte vector 518 loaded into register 104b). The third vector 740 can be referred to as a "select index vector" and can indicate the ordinal position of the row of the select byte vector 518 holding the values indicating that the filter passed.
[0083] Block 610 includes matching the integer values of the third vector with the indices of the first column vector. Figure 7B , processor 106( Figure 1 ) can use AVX2 SIMD instructions to compare the integer values of the third vector 740 with the indexes of the first column vector 512.
[0084] Block 612 includes retrieving and decoding the encoded value of the first column vector based on the match. Figure 7B , processor 106( Figure 1 ) may utilize AVX2 SIMD instructions to perform a retrieval or aggregation operation 752 that retrieves the encoded values of the column vector 512 stored at the index within the column vector 512 that matches the integer value of the selection index vector 740. These retrieved encoded values may be loaded directly into a corresponding lane of one of the registers 104a to 104n. The processor 106 may perform a decoding operation 754 on the retrieved encoded values by looking up the decoded value mapped to the retrieved encoded value in an appropriate encoding dictionary to generate a decoded column vector 760. In some embodiments, such a decoding operation may utilize AVX2 SIMD instructions to operate on multiple retrieved encoded values simultaneously.
[0085] Aggregation selection effectively combines the filtered rows of the bit-decompressed and de-encoded column vectors.At least block 610 may be repeated for each column 222 for which the query 250 of table 220 defines a "group by" parameter and for each column 222 for which the query 250 of table 220 defines an aggregation parameter.
[0086] Selection by special group assignment
[0087] Selection by special group assignment is to be used in conjunction with a "group by" aggregation that follows this type of selection. Selection by special group assignment is an optimization that can be viewed as pushing the grouping and aggregation before the part that processes the selection operation in the pipeline.
[0088] The following references Figure 8 and Fig. 9 Description Selection by special group assignment, Figure 8 shows a process for performing selection by special group assignment for query 250 according to some embodiments, Fig. 9 It is shown by Figure 8 A block diagram of some of the data vectors, registers, and operations described.
[0089] Despite the combination Figure 8 Certain steps or actions are described, but the process for performing selection by special group assignment for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0090] Block 802 includes adding bits to the encoded values in the second column vector by which the query indicates that the results are to be grouped, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length. The same length can be one byte, two bytes, four bytes, or eight bytes. Such encoded values can be considered a group ID because each different encoded value represents a different entry by which the results can be grouped. For example, query 250 ( Figure 2 ) may include an indication of a second column vector having encoded values by which the results are grouped. Such an indication in query 250 may have the general form "Group by..." followed by an identifier of one or more columns 222 of table 220, such as "State". Fig. 9 , the encoded values of the second column vector 910 do not have to be in full byte length (e.g., Fig. 9 Therefore, in order to ensure that registers 104a to 104n (see Figure 1 ), and to ensure that the encoded values of the second column vector 910 each fit completely into a given register 104a, the processor 106 ( Figure 1 ) The encoded values of the second column vector 910 may be decompressed to the next maximum size of 1 byte, 2 bytes, 4 bytes, or 8 bytes using a decompression operation 514 to generate a corresponding second column vector 916 of decompressed encoded values.
[0091] Block 804 includes loading a first subset of values into corresponding lanes of the first register, the first subset including the decompressed encoded values of the second column vector. Fig. 9 , processor 106( Figure 1) can use load operation 522 to load the first subset of decompressed encoded values, now having a full byte length, from the decompressed second column vector 916 into the corresponding lanes of register 104a.
[0092] Block 806 includes loading a second subset of values into corresponding lanes of the second register, the second subset including values of the first vector corresponding to the first subset of values. Fig. 9 , processor 106( Figure 1 ) A load operation 524 may be performed to load a second subset of the values of the select byte vector 518 into the corresponding lanes of the register 104b. The same number of values of the select byte vector 518 are loaded into the register 104b as the decompressed encoded values were loaded into the register 104a, and in the same order.
[0093] Block 808 includes updating the decompressed encoded values in the lanes of the first register corresponding to the lanes of the second register including the indication that failed the filter to constant values using a single instruction, thereby generating an updated second column vector. Fig. 9 , processor 106( Figure 1 ) can update the decompressed encoded values in the lanes of register 104a corresponding to the lanes of register 104b including the indication that the filter did not pass (e.g., 0x00) to constant values (e.g., 0x04) using a single AVX2 SIMD instruction (update operation 930), thereby generating an updated second column vector 940. In some embodiments, the constant value can be the first unused value of the decompressed second column vector 916 (e.g., 0x04 in Fig. 9 916 as the first unused value). However, any unused value of the decompressed second column vector 916 may also be utilized. Such an update operation may be, for example, a NOT AND operation between corresponding lanes of registers 104a and 104b (e.g., between the decompressed encoded value from the decompressed second column vector 916 loaded into register 104a and the corresponding value from the select byte vector 918 loaded into register 104b).
[0094] Block 810 includes executing a query on the column storage table using the updated second column vector, thereby generating a result of the query that includes results for all groups except for the group corresponding to the constant value. Fig. 9 , processor 106( Figure 1) can execute query 250 against column store table 220 using updated second column vector 940 that now includes the constant value in the updated row, without regard to the filter defined by query 250. Thus, by updating the entries in second column vector 940 for rows that do not pass the filter defined by query 250, the unqualified rows are effectively grouped into groups of constant values and can be discarded without fully processing the filter before outputting the results of query 250. Executing the query may include performing any "group by" and any "aggregate" operations as defined by query 250.
[0095] Comparison of selection by compression, selection by aggregation, and selection by special group assignment
[0096] In general, selection by aggregation will be best suited for filters with low selectivity (where a relatively small percentage of the rows in batch 230 of table 220 pass or satisfy the conditions of the filter of query 250), selection by compression will be best suited for filters with moderate selectivity, and selection by special group assignment will be best suited for filters with selectivity close to 1 (where nearly all of the rows in batch 230 of table 220 pass or satisfy the conditions of the filter or query 250).
[0097] The per-row cost of running a query for all three approaches can be expressed as c compact 、c gather and c special If the cost of an aggregation result (e.g., computing the sum, minimum, maximum, average, standard deviation, etc.) is represented by c aggregate , and the filter selectivity is denoted as α, then when α <c compact / c gather Aggregate selection is better than selection by compression when α<(c special +c aggregate -c compact ) / c aggregate , selection by compression will outperform selection by special group assignment. Thus, for each bit width of the encoded data, there is a fixed filter selectivity beyond which selection by compression begins to outperform selection by aggregation. For example, it has been determined that for a 4-bit width, selection by compression outperforms selection by aggregation for filter selectivity ≥ approximately 2% (at least 2% of the rows pass through the filter), for a 7-bit width, selection by compression outperforms selection by aggregation for filter selectivity ≥ approximately 4%, for a 14-bit width, selection by compression outperforms selection by aggregation for filter selectivity ≥ approximately 30%, and for a 21-bit width, selection by compression outperforms selection by aggregation for filter selectivity ≥ approximately 38%.
[0098] Classification based on by and group by
[0099] The group-by-and-group-by sort operation using SIMD sorts the row indexes within each batch 230 of rows into groups based on an indication of how the results are grouped in the query 250 .
[0100] Reference below Fig.10 as well as Fig.11A and Fig. 11B Describes the classification based on by and group by, Fig.10 shows a process for performing a by and group by classification for a query 250 according to some embodiments, Fig.11A and Fig. 11B Shown as Fig.10 Certain data vectors, registers, and operations that are the subject of a process.
[0101] Despite the combination Fig.10 Certain steps or actions are described, but the process for performing group by and group by based sorting for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0102] Block 1002 includes determining, for each unique encoded value in the second column vector, a count of unique encoded values in the second column vector. For example, query 250 ( Figure 2 ) may include an indication of a second column vector having coded values by which the results are grouped. Such indications in query 250 may have the general form "Group by" followed by an indication of one or more columns 222 of table 220, such as "State". Fig.11A , the processor 106 can be configured to perform a group by count (*) operation 1112 on the second column vector 910, which returns a corresponding count 1114 for each unique encoded value in the second column vector 910. In some embodiments, having the same encoded value occur in consecutive rows of the second column vector 910 can cause write conflicts in a single counter used to track the count for each group indicated by the second column vector 910. Therefore, in some embodiments, to avoid such write conflicts, two or more counters can be utilized to track the count for each group, and the partial sums from each counter of a given group can be added together at the end of the counting process.
[0103] Block 1004 includes generating a plurality of subarrays, each subarray being associated with a different uniquely encoded value in the second column vector and having a length based on the count corresponding to the uniquely encoded value. For example, referring to FIG. 11 , processor 106 ( Figure 1 ) can generate a plurality of sub-arrays 1120, 1122, 1124, 1126. Each sub-array 1120, 1122, 1124, 1126 has a length based on a corresponding count 1114 of corresponding unique encoded values in the second column vector 910.
[0104] Block 1006 includes, for each row of the second column vector, inserting an indication of the row into a subarray of the plurality of subarrays based on the encoded value at the row. Fig.11A , processor 106( Figure 1 ) may perform an insert operation 1116 on each index of the second column vector 910 by inserting an indication of the row into one of the plurality of sub-arrays 1120, 1122, 1124, 1126 based on the encoded value in the row.
[0105] Block 1008 includes cascading each of the plurality of sub-arrays to generate a first array. Fig.11A , processor 106( Figure 1 ) may perform a concatenation operation 1118 to concatenate each of the plurality of subarrays 1120, 1122, 1124, 1126 to generate a first array 1130 of sorted rows for a second column vector. The first array 1130 contains indications of all rows within the batch 230 that fall into the group. Using such an array, the sum of the encoded values at the rows of one or more columns may then be calculated. In some embodiments, the concatenation step of block 1008 may be optional. For example, such a concatenation may alternatively include a logical operation in which a plurality of subarrays 1120, 1122, 1124, 1126 that may be physically stored adjacent to one another in memory are not actually concatenated to form the first array 1130, but are optionally interpreted together as the first array 1130.
[0106] Block 1010 includes, for a subarray of the subarrays of the first array, matching an indication of a row in the subarray with a row of the first column vector. Fig. 11B , processor 106( Figure 1 ) can be configured to perform a matching operation 1152 that matches indications of rows in the subarray 1120 of the first array 1130 with rows of the first column vector 512.
[0107] Block 1012 includes retrieving and decoding the encoded value of the first column vector based on the match. Fig. 11B , processor 106( Figure 1) may be configured to retrieve the encoded value of the first column vector 512 via a retrieval operation 1154 based on the match at block 1010, and decode the encoded value of the first column vector 512 via a decoding operation 1156. Thus, the processor 106 may retrieve the encoded value at the row of the first column vector 512 that matches the indication of the row in the subarray 1120 of the first array 1130. The processor 106 may utilize the encoded value to perform a lookup in the encoding dictionary corresponding to the encoded value, and return a decoded value 1160. In some embodiments, the decoding portion of block 1012 may be optional. For example, in some cases, for numeric columns having encoded values that are small enough to fit within a 64-bit register, for example, in the case of encoding a small integer range (e.g., 0 to 10) using the minimum number of bits that can uniquely represent each of the small numbers, decoding may not be necessary because the encoded value can still be added to a larger, extended byte-level length without decoding. For example, in the case of encoding the numbers 0 to 10 using 4 bits (e.g., integer 1 is represented as 0001, integer 2 is represented as 0010, integer 3 is represented as 0011, etc.), the encoded 4-bit value can be added to the larger, extended byte-level size without decoding. In such an embodiment, block 1012 can include retrieving the encoded value from the first column vector based on the match.
[0108] Block 1014 includes loading the decoded values of the first column vector into the corresponding lanes of the first register. Fig. 11B , the processor 106 may be configured to load the decoded values 1160 of the first column vector 512 into the corresponding lanes of the register 104a. Although only two values are shown to be loaded into the register 104a, this is merely an example, and any number of qualifying values may be loaded into the register 104a. In embodiments where the decoding portion of block 1012 is not performed, block 1014 may instead operate using the encoded values of the first column vector, as described above.
[0109] Block 1016 includes adding the decoded value in each lane of the first register to the corresponding lane in the other register using a single instruction, thereby generating a sum of the decoded values from the corresponding lane of the first register in the corresponding lane of the other register. Fig. 11B, the processor 106 may be configured to add the decoded values in each lane of register 104a to the corresponding lane in register 104f using a single instruction (e.g., a SIMD instruction), thereby generating a sum of the decoded values from the corresponding lane of register 104a in the corresponding lane of register 104f. The loading step of block 1014 and the operation of block 1016 may be repeated until all values of a particular column and a particular group have been processed. The processor 106 may then determine a sum 1170 for the group as indicated by query 250 by utilizing a sum operation 1158 (also sometimes referred to as a "reduce") that adds all running sums in the lanes of register 104f to obtain a sum 1170 for the lanes of register 104f. The sum 1170 may include the sum indicated by query 250.
[0110] Processor 106 may perform the matching, retrieving, decoding, loading, and summing operations for each column and each group, where the sum is indicated by query 250 .
[0111] Group by count and group by sum within register
[0112] In some embodiments, computing aggregates with grouping can be based on keeping intermediate results entirely in CPU registers rather than in memory 120. Some such embodiments can be utilized where the number of groups by which the results are grouped is about 32 or less. Each aggregate (sum, minimum, maximum, etc.) can be processed separately.
[0113] The following references Fig.12 and Fig.13 Describe the grouping by count and grouping by sum in registers, Fig.12 shows a process for performing in-register group by count and group by sum for query 250 according to some embodiments, Fig.13 It is shown by Fig.12 A block diagram of some of the data vectors, registers, and operations described.
[0114] Despite the combination Fig.12 Certain steps or actions are described, but the process for performing the in-register group by count and group by sum for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0115] The query 250 also includes an indication of a second column vector 910 having an encoded value by which the results of the query 250 are grouped. As an example, assume that the query 250 defines the results as the number of rows of a column corresponding to each group, as identified by a 1-byte encoded value within the column (e.g., grouped by count).
[0116] Block 1202 includes adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length. The same length can be one byte, although any other full-byte length is contemplated. Such encoded values can be considered a group ID because each different encoded value represents a different entry by which the results can be grouped. For example, query 250 ( Figure 2 ) may include an indication of a second column vector 910 having an encoded value by which the results are grouped. Such an indication in the query 250 may have the general form "Group by..." followed by an identifier of one or more columns 222 of the table 220, such as "State". Fig.13 , the encoded values of the second column vector 910 do not have to be in full byte length (e.g., Fig.13 Therefore, in order to ensure that register 104a (see Figure 1 ), and to ensure that each of the encoded values of the second column vector 910 fits completely into a given register 104a, the processor 106 ( Figure 1 ) The encoded values of the second column vector 910 may be decompressed to the next maximum size of 1 byte using a decompression operation 514 to generate a corresponding second column vector 916 of decompressed encoded values.
[0117] Block 1204 includes loading each value in a first subset of values into a corresponding lane of the first register, the first subset including the decompressed encoded values of the second column vector. Fig.13 , processor 106( Figure 1 ) can use load operation 522 to load each value in the first subset of decompressed encoded values, now having a full byte length, from the decompressed second column vector 916 into the corresponding lane of register 104a.
[0118] Block 1206 includes initializing, for each channel of the first register, a first counter in a corresponding channel of each of the plurality of other registers, such that each of the plurality of other registers holds a corresponding first counter for each channel of the first register, and all first counters in each of the other registers correspond to a unique decompressed encoded value of the second column vector. For example, referring to Fig.13 , processor 126( Figure 1) can initialize the partial counters in the corresponding lanes of each of the plurality of registers 104b, 104c, 104d such that each of the plurality of registers 104b to 104e holds a corresponding partial counter for each lane of the first register 104a, and all of the partial counters in the registers 104b, 104c, 104d, 104e correspond to unique decompressed encoded values of the second column vector 916. For example, register 104b can hold a partial counter for group "0", register 104c can hold a partial counter for group "1", register 104d can hold a partial counter for group "2", and register 104e can hold a partial counter for group "3". Although only four registers 104b to 104e are shown, such an implementation would have N-1 registers holding partial counters for N-1 of the N unique decompressed encoded values in the column vector 916. As will be described in more detail below, one fewer register than groups N may be utilized because the final group count may be obtained by subtracting all other group counts from the total number of rows in the second column vector 916 .
[0119] Block 1208 includes, for each lane of the first register, incrementing a first counter of a corresponding lane of one of the plurality of other registers corresponding to the decompressed encoded value in the lane of the first register. Fig.13 , processor 126( Figure 1) can be performed on a channel-by-channel basis for register 104a to increment a partial counter in a corresponding channel of one of a plurality of registers 104b to 104e corresponding to the decompressed encoded value in the channel of the first register 104a. For example, working from right to left, the first channel of register 104a holds the decompressed encoded value "0". Therefore, the partial counter in the corresponding channel of register 104b holding the partial counter for group "0" is incremented, for example, its value is changed to 0xFF or 1. The second channel of register 104a also holds the decompressed encoded value "0". Therefore, the partial counter in the corresponding channel of register 104b is incremented, for example, its value is changed to 0xFF or 1. The third and fifth channels of register 104a hold the decompressed encoded value "1". Therefore, the partial counter in the corresponding channel of register 104c holding the counter for group "1" is incremented, for example, its value is changed to 0xFF or 1. The fourth and seventh channels of register 104a hold the decompressed encoded value "2". Thus, some of the counters in the corresponding lane of register 104d holding the counters for group "2" are incremented, e.g., their values are changed to 0xFF or 1. As can be appreciated, each time register 104a is loaded with a subsequent set of decompressed encoded values from the second column vector 916, only one lane across registers 104b through 104d will be incremented for any corresponding decompressed encoded value in the corresponding lane of register 104a.
[0120] Block 1210 includes, for each of a plurality of other registers, summing the first counter in the other register and adding the sum to the corresponding second counter for the corresponding unique decompressed encoded value. Fig.13 , processor 126( Figure 1 ) can be configured to perform a summing operation 1322 that sums all partial counters in a particular register 104b for each register 104b to 104d, for example, and adds the result to a corresponding total counter in the second array 1340. As shown, register 104b has two channels (a first channel and a second channel) with a value of 1, which can be summed and added to a corresponding total counter C0 in the second array 1340. Similarly, two channels with a value of 1 in each of registers 104c and 104d can be summed and added to corresponding total counters C1 and C2, respectively, in the second array 1340. Thus, registers 104b to 104d can maintain partial counters for occurrences of unique decompressed encoded values in each load of register 104a, while the second array 1340 maintains a total counter for occurrences of unique decompressed encoded values in all loads of register 104a described in this section.
[0121] In embodiments where the increment value of some of the counters in registers 104b-104d is 0xFF, such summing operations may include negating the increment value 0xFF (since 0xFF means a signed 8-bit integer minus 1) and merging each value into the counter in the second array 1340. In some embodiments, the actions of block 1210 may be performed using a single set of SIMD instructions for registers 104a-104d.
[0122] Block 1212 includes determining a third counter by subtracting the corresponding second counter from the total number of rows in the second column vector, the third counter value corresponding to the last of the unique decompressed encoded values in the second column vector. Fig.13 , processor 126( Figure 1 ) can be configured to determine the last total counter C3 in the second array 1340 by subtracting all corresponding total counters C0, C1, C2 in the second array from the total number of rows in the second column vector 916. The last total counter value C3 corresponds to the last of the unique decompressed encoded values in the second column vector 916, such as the value "3".
[0123] Group By and Multi Aggregation
[0124] In some embodiments, query 250 may need to determine multiple sums across multiple columns. Although the previous embodiments exploited data-level parallelism vertically, the embodiments utilizing the group-by-sum multi-aggregation processing can exploit data-level parallelism horizontally, which means summing multiple aggregates across multiple columns for the same input row rather than multiple input rows for the same aggregate column. In some embodiments, time-row aggregation for multiple sums can be faster than time-column aggregation. Further improvements can be obtained by loading the inputs for multiple sums for the same row into a register and executing only one set of load-add-store instructions for all these inputs. As previously described, the column storage table stores values in memory by column. Therefore, the values from the columns to be summed are reorganized via matrix transposition, as described in more detail below.
[0125] The following references Fig.14 and Fig.15 Describe group by and multi aggregation, Fig.14 shows a process for performing a group by and multi aggregation for a query 250 according to some embodiments, Fig.15 It is shown by Fig.14 A block diagram of some of the data vectors, registers, and operations described.
[0126] Despite the combination Fig.14Certain steps or actions are described, but the process for performing the group by and multi-aggregation for query 250 may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0127] refer to Fig.15 , query 250( Figure 2 ) may include multiple column vectors 1520, 1522, 1524, 1526, 1528 (see Fig.15 ), each column vector has an encoded value to be summed, and the results of the query are grouped by the encoded value. The encoded values of column vectors 1520, 1522, 1524, 1526 are not in Fig.15 , and for simplicity are alternatively indicated as A1 to A4, B1 to B4, C1 to C4, D1 to D4, and E1 to E4.
[0128] Reference now Fig.14 , block 1402 includes, for each column vector of the plurality of column vectors, loading a first subset of the encoded values of the column vector into a corresponding lane of a corresponding register, thereby forming a third array including the corresponding register. Fig.15 , processor 106( Figure 1 ) may be configured to perform a load operation 1512 that loads a respective first subset of the encoding values A1 to A4, B1 to B4, C1 to C4, D1 to D4, and E1 to E4 from respective column vectors 1520, 1522, 1524, 1526, 1528 into respective registers 104a, 104b, 104c, 104d, 104e. Thus, Fig.15 , the third array 1530 includes the encoded values in registers 104a to 104e. As a non-limiting example, the encoded values A1 to A4 have a length of 64 bits (8 bytes), the encoded values B1 to B4 and E1 to E4 have a length of 32 bits (4 bytes), the encoded values C1 to C4 and D1 to D4 have a length of 16 bits (2 bytes), and registers 104a to 104e are 256-bit (32-byte) registers. In some embodiments, the load operation 1512 may include AVX2 SIMD instructions that allow a single instruction to collect multiple lines of data simultaneously and load them into registers 104a to 104e.
[0129] Block 1404 includes adding bits to the encoded value in each of the corresponding registers, thereby generating a plurality of column vectors of decompressed encoded values, each decompressed encoded value having a first length or a second length. A challenging aspect of efficiently converting columns to rows is that, in general, there may be different numbers of input columns and they may store elements of different byte sizes. Combinations of template functions may be used to create a specialized SIMD implementation in which processor 106 ( Figure 1 ) can be configured to decompress the encoded values A1 to A4, B1 to B4, C1 to C4, D1 to D4, and E1 to E4 to 4 bytes in length (e.g., a first length) or 8 bytes in length (e.g., a second length) by adding padding zeros, so that encoded values of 1 byte length or 2 bytes in length are decompressed to 4 bytes using decompression operation 1514, and encoded values with larger lengths are decompressed to 8 bytes. This ensures that up to 65,536 rows can be summed using 64-bit addition in a SIMD lane of registers 104a to 104e, for example, without overflow for input values of up to 4 bytes. Such an implementation supports any combination of the number and size of input columns, as long as, after expansion, all elements for a single row can fit into a 256-bit SIMD register, where 32-bit extended elements are 32-bit aligned and 64-bit elements are 64-bit aligned.
[0130] Block 1406 includes transposing the third array so that the decompressed encoded values previously loaded into a single corresponding register are now loaded into corresponding lanes of each of the corresponding registers. Fig.15 , processor 106( Figure 1 ) can be configured to perform a transpose operation 1516, which can realign all entries within registers 104a to 104e so that the decompressed encoded values (e.g., A1 to A4) previously loaded into a single corresponding register (e.g., 104a) are now loaded into corresponding lanes of corresponding registers 104a to 104d. For example, decompressed encoded values C1 to C4 are shown as being transposed from only the lane in register 104c to the first 32-bit lane of each of registers 104a to 104d; decompressed encoded values D1 to D4 are shown as being transposed from only the lane in register 104d to the second 32-bit lane of each of registers 104a to 104d; and E1 to E4 are shown as being transposed from the lanes in registers 104a, 104b, and 104e to the corresponding 64-bit lanes of each of registers 104a to 104d.
[0131] Block 1408 includes, for each respective register, adding the decompressed encoded value in each lane of the respective register to the corresponding lanes in the other registers using a single instruction, thereby generating a sum of the decompressed encoded values from the corresponding lanes of each respective register in the corresponding lanes of the other registers. Fig.15 , processor 106( Figure 1 ) can use a single AVX2 SIMD instruction to add the decompressed encoded value in each lane of the corresponding register to the corresponding lane in the other register 104f for each register 104a to 104d. In another example, one instruction can add C1, D1, A1, B1 and C1 to the corresponding values CT, DT, AT, BT and ET in register 104f. For the first addition, each of CT, DT, AT, BT and ET can have a zero value. Another instruction can add C2, D2, A2, B2 and C2 to the corresponding values CT, DT, AT, BT and ET in register 104f. Another instruction can add C3, D3, A3, B3 and C3 to the corresponding values CT, DT, AT, BT and ET in register 104f, and another instruction can add C4, D4, A4, B4 and C4 to the corresponding values CT, DT, AT, BT and ET in register 104f. Thus, the running sum of the decompressed encoded values (e.g., CT, DT, AT, BT, and ET) from the corresponding lane of each respective register 104a to 104d is maintained in the corresponding lane of register 104f. This transposition of the array 1530 including the originally loaded registers 104a to 104e allows the encoded entries from multiple columns to be reassembled into registers as if they were original entries within a single column, allowing them to be summed in a single operation.
[0132] Quickly group by count (*) using bit-level logic
[0133] It is also possible to improve the performance of grouping by count (*) for bit-compressed columns with coded values by which the results of the query are grouped. Such processing may be particularly useful in cases where the number of groups (e.g., the number of unique coded values, and therefore the bit length of the coded values) is relatively small. Fig.16 and Fig.17 Describes this fast grouping by count (*) using bit-level logic, Fig.16 shows a process for performing a fast group by count (*) using bit-level logic for query 250, according to some embodiments, Fig.17 It is shown by Fig.16 A block diagram of some of the data vectors, registers, and operations described.
[0134] Despite the combination Fig.16Certain steps or actions are described, but the process 250 for quickly grouping by count (*) using bit-level logic for a query may include fewer than all of the steps described and / or additional or alternative steps to the steps described.
[0135] refer to Fig.17 , query 250( Figure 2 ) may include an indication of a second column vector 910 having encoded values by which the results of the query 250 are grouped.
[0136] refer to Fig.16 , block 1602 includes loading each value in a first subset of values into a plurality of registers, the first subset including the encoded values of the second column vector. Fig.17 , processor 106( Figure 1 ) can be configured to perform a load operation 522 that loads a corresponding first subset of encoded values from the second column vector 910 into registers 104a, 104b, and 104c. In some embodiments, registers 104a to 104c are 256-bit registers, although only 8 bits are shown for ease of illustration. Therefore, in some embodiments, the first subset of values can include 256 values from the second column vector 910, although only 8 are shown for ease of illustration. The second column vector 910 is shown as including 3-bit encoded values. Therefore, the first subset of values can be loaded into the same number of registers as the number of bits in the encoded values, for example, 3 in this example.
[0137] Block 1604 includes separating and reloading the bits of the encoded values in the plurality of registers such that the i-th bit of each encoded value is stored in the i-th register in the plurality of registers. For example, processor 106 ( Figure 1 ) can be configured to perform a split and reload operation 1724, wherein the first bit of each encoded value (for ease of reference only in Fig.16 104a to 104c, the second bit of each encoded value may be separated and loaded into register 104b, and the third bit of each encoded value may be separated and loaded into register 104c, as shown by the dashed circle and arrow portion. Although the bits of the encoded values from the second column vector 910 may be separated and reloaded into registers 104a to 104c in any order, the order must be the same for each register 104a to 104c.
[0138] Block 1606 includes, for at least some of the unique encoded values of the second column vector, comparing bits of each encoded value in the plurality of registers to corresponding bits of the unique encoded values.
[0139] Block 1608 includes setting other bits for each encoded value that matches all bits with a unique encoded value based on the comparison. Fig.17 , processor 106( Figure 1 ) can be configured to perform operation 1726, which compares the bits for each encoded value in each of the registers 104a to 104c with the corresponding bits of the unique encoded value, and then based on the comparison, generates a fourth vector having corresponding bit settings for each encoded value with all bits matching the unique encoded value. For example, for the unique encoded value "000", the processor 106 can be configured to generate the bit vector 1712 using the comparison function Z=NOT(A OR BOR C), where, for each bit in the registers 104a, 104b, 104c, A, B, and C are the corresponding i-th bits in the registers 104a, 104b, 104c, respectively. Similarly, for the unique encoded value "010", the processor 106 can be configured to generate the bit vector 1716 using the comparison function Z=NOT(A OR B)AND C.
[0140] Block 1610 includes incrementing a fourth counter in the third array for uniquely encoded values for each additional bit setting. Fig.17 , processor 106( Figure 1 ) may be configured to perform two increment operations 1728 on each of the total counters C0, C1, and C2 based on each corresponding bit vector 1712, 1714, 1716 having two bits set.
[0141] Block 1612 includes determining a fifth counter value in the third array by subtracting a fourth counter in the third array from the total number of rows in the second column vector, the fifth counter corresponding to the last of the uniquely encoded values in the second column vector. Fig.17 Once all encoded values of the second column vector 912 have been processed by block 1610, the processor 106 ( Figure 1 ) can be configured to subtract the total counts C0, C1 and C2 from the total number of rows in the second column vector 912 to determine the total count C3 corresponding to the final unique encoded value in the second column vector 912.
[0142] Combination Fig.16 and Fig.17 The described process can also be applied to filters, where such filters are in the form of bit vectors similar to bit vectors 1712, 1714, 1716. For example, the filter bit vector can be the same as in Fig.17The separated and reloaded bits in registers 104a to 104c shown after operation 1724 in are ANDed. This can be equivalent to assigning all filtered rows to group zero and skipping that group when updating the counter, as previously described in conjunction with block 1610. Thus, that group can be selected as a skipped group. The count of group zero or filtered rows can be determined by subtracting the number of rows that passed the filter (e.g., the number of bits set in the filter bit vector) from the total number of rows in the second column vector 910.
[0143] Combination Fig.16 and Fig.17 The described process can also be applied to multiple grouping columns, as long as they all utilize bit compression with relatively small bit widths, and the sum of all bit widths is also relatively small (e.g., 5 bits). For example, in such an embodiment, query 250 ( Figure 2 ) may include an indication of multiple column vectors (e.g., two or more) having encoded values by which the results of query 250 are grouped. In such an embodiment, a separate set of bit vectors (similar to bit vectors 1712, 1714, 1716) may be generated for each column vector by which query 250 indicates that the results are grouped. Blocks 1610 and 1612 may then be performed using the union of all bit vector sets for multiple grouped column vectors, as if all bits were from a single column. Logically, this corresponds to concatenating the bits of the values from all grouped columns of the same row.
[0144] Group ID Mapping
[0145] In some implementations, a query may include one or more expressions that need to be evaluated repeatedly in order to return results. An example of such a query may be:
[0146] select substr(1,3,s),count(*)
[0147] From
[0148] Group by substr(1, 3, s)
[0149] Such a query requires a substring of the first to third characters of all entries in column "s" across table "t", and the results are grouped by unique substrings. Therefore, in order to return a result, the expression "substr(1, 3, s)" must be evaluated. Instead of fully evaluating the expression each time, a two-level dictionary can be employed that allows for lookup of previously mapped evaluations for a particular expression. In the case of repeated input of an expression, such a lookup can save considerable processing cycles compared to re-evaluating the expression each time it is encountered. For example, consider the example column s in Table 7 below and the evaluation results of the expression "substr(1, 3, s)" in Table 8.
[0150] When the expression "substr(1, 3, s)" is evaluated for column "s", a first mapping or hash table may be generated such that each time a new input from column "s" is encountered, the input is mapped to the encoded value of that entry in the first table, as shown in Table 9 below. Likewise, each time an output of the expression is generated, the output is mapped to the encoded value of that output in the second table, as shown in Table 10. Similarly, the encoded values of the first table may then be further mapped to encoded values of the second table, as shown in Table 11.
[0151]
[0152]
[0153] Table 7
[0154] s car car bat bri car bat car bri
[0155] Table 8
[0156]
[0157] Table 9
[0158]
[0159] Table 10
[0160]
[0161] Table 11
[0162] Thus, when evaluating each row of column "s", processor 106 ( Figure 1 ) can first determine whether the string appearing in column "s" has been mapped to an encoding value in the first mapping. If so, the processor 106 can instead use the corresponding encoding value (e.g., "00") from the first mapping to use the mapping correspondence in the third mapping to look up the output value in the second mapping instead of re-evaluating the expression "substr(1, 3, s)". In this way, by using the multi-level dictionary, the expression can be evaluated in much fewer CPU cycles than re-evaluating the expression each time.
[0163] In yet another embodiment where the results are grouped by multiple columns, the hash tables used to encode each of the multiple columns according to any of the methods discussed above can be merged into a single hash table and used to group the results as if the results were grouped by only a single column. For example, recall Table 5 again, and assume the following query:
[0164] select partition, state, sum(sale_amt)
[0165] From table_of_sales
[0166] By division, state grouping
[0167] This query requires the sum of sale_amt from the table table_of_sales and requires the resulting sum to be grouped by division and state, so it is necessary to group by operation based on entries in both the Division column and the State column.
[0168] According to some embodiments, instead of evaluating queries by column individually by each group, according to any of the processes previously described, the encoded values in corresponding rows of the "division" and "state" columns can be concatenated to form a single encoded column by which the output results can be grouped.
[0169] Therefore, a hash table can be generated that maps each concatenated encoded entry to a decoded value for each encoded column value, as shown in Table 12 below. The key of the hash table of Table 12 has a number of bits that is the sum of the number of bits of the originally encoded "division" and "state" columns, for example, 1 bit + 3 bits = 4 bits. Therefore, since the sort or group operation operates on the concatenated columns of encoded values, each concatenated encoded value is treated as if it were a single encoded value, so grouping by the concatenated columns of encoded values allows avoiding multiple iterations through the group by process. This greatly reduces the number of CPU cycles required to generate the results of the query.
[0170]
[0171] Table 12
[0172] When interpreting this application, it should be understood that the word "including" does not exclude the existence of other elements or actions other than those listed, and the word "a" or "an" before the element does not exclude the existence of multiple such elements. Any reference symbol does not limit the scope of the entity to which it refers. Several "devices" can be represented by the same item or structure or function implemented by hardware or software. Each of the disclosed elements may include a combination of a hardware part (e.g., including discrete and integrated electronic circuits) and a software part (e.g., computer programming, instructions or codes). The hardware part may include one or more processors and / or memory, and the software part may be stored on a non-temporary computer-readable medium, and may be configured to enable such one or more processors to perform some or all functions of one or more elements in the disclosed elements. The hardware part may include one or both of the analog part and the digital part. Unless otherwise specifically stated, any of the disclosed devices or parts thereof may be combined together or separated into other parts. Unless otherwise specifically stated, it is not intended to require a specific order of actions. The term "plurality" of elements includes two or more of the claimed elements and does not imply any particular range of the number of elements; that is, the plurality of elements may be as few as two elements and may include an incalculable number of elements.
Claims
1. A method for causing a processor to perform a query on a column storage table including one or more coded values, the method comprising configuring the processor to: receiving the query, the query comprising a filter to be applied to at least a first column vector of the encoded values, in, The first column vector includes a plurality of consecutive segments, each segment being encoded separately from segments in another column vector in the column storage table; processing queries for a batch of the encoded values in segments of the first column vector to generate a first vector indicating corresponding encoded values that pass the filter or fail the filter; determining, from the first vector, a selectivity indicator of the filter for the encoded values in the batch, the selectivity indicator indicating: a proportion of the encoded values in the batch for segments of the first column vector that pass the filter, or a proportion of the encoded values in the batch for segments of the first column vector that do not pass the filter; determining a bit length for encoding of the encoded value in the segment of the first column vector; and For the batch of the encoded values, an algorithm is selected from a plurality of algorithms for further processing the query, the algorithm being selected based on the selectivity indicator of the batch and a determined bit length of the encoded values in the segment of the first column vector.
2. The method according to claim 1, in, The selected algorithm enables the processor to: adding bits to each of at least the batches of the encoded values in the first column vector, thereby generating decompressed encoded values of the first column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of a first register, the first subset comprising the decompressed encoded values; loading a second subset of values into corresponding lanes of a second register, the second subset comprising values of the first vector corresponding to the first subset of values; and Decompressed encoded values that pass through the filter are output from the first register into a filtered column vector based on values in the second subset using a single instruction.
3. The method according to claim 1, in, The query further includes an indication of a second column vector having encoded values by which results of the query are grouped, the selected algorithm causing the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of a first register, the first subset comprising the decompressed encoded values of the second column vector; loading a second subset of values into corresponding lanes of a second register, the second subset comprising values of the first vector corresponding to the first subset of values; updating, with a single instruction, the decompressed encoded values in the lanes of the first register corresponding to the lanes of the second register including the indication that failed the filter to constant values, thereby generating an updated second column vector; and The query is executed on the column storage table using the updated second column vector, thereby generating a result of the query, the result including results of all groups except a group corresponding to the constant value.
4. The method according to claim 1, in, The query further includes an indication of a second column vector having encoded values by which results of the query are grouped, the selected algorithm causing the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading each value in a first subset of values into a corresponding lane of a first register, the first subset comprising the decompressed encoded value of the second column vector; initializing, for each channel of the first register, a first counter in a corresponding channel of each of a plurality of other registers, such that each of the plurality of other registers holds a respective first counter for each channel of the first register, and all first counters in each of the other registers correspond to a unique decompressed encoded value of the second column vector; for each channel of the first register, incrementing the first counter of a corresponding channel of one of the plurality of other registers corresponding to the decompressed encoded value in the channel of the first register; for each other register of the plurality of other registers, summing the first counters in the other registers and adding the sum to a corresponding second counter for the corresponding unique decompressed encoded value; and A third counter is determined by subtracting the corresponding second counter from the total number of rows in the second column vector, the third counter value corresponding to a last one of the unique decompressed encoded values in the second column vector.
5. A non-transitory computer readable medium comprising code which, when executed, causes a processor to: receiving a query comprising a filter to be applied to at least a first column vector of encoded values, in, The first column vector is one of one or more column vectors in a column storage table, and the first column vector includes a plurality of consecutive segments, each segment being encoded separately from segments in another column vector in the column storage table; processing queries for a batch of the encoded values in segments of the first column vector to generate a first vector indicating corresponding encoded values that pass the filter or fail the filter; determining, from the first vector, a selectivity indicator of the filter for the encoded values in the batches, the selectivity indicator indicating: a proportion of the encoded values that pass the filter relative to the encoded values in each batch of segments of the first column vector, or a proportion of the encoded values that do not pass the filter relative to the encoded values in the batches of segments of the first column vector; determining a bit length for encoding of the encoded value in the segment of the first column vector; and For the batch of the encoded values, an algorithm is selected from a plurality of algorithms for further processing the query, the algorithm being selected based on the selectivity indicator of the batch and a determined bit length of the encoded values in the segment of the first column vector.
6. The non-transitory computer readable medium of claim 5, in, The selected algorithm enables the processor to: adding bits to each of at least the batches of the encoded values in the first column vector, thereby generating decompressed encoded values of the first column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of a first register, the first subset comprising the decompressed encoded values; loading a second subset of values into corresponding lanes of a second register, the second subset comprising values of the first vector corresponding to the first subset of values; and Decompressed encoded values that pass through the filter are output from the first register into a filtered column vector based on values in the second subset using a single instruction.
7. The non-transitory computer readable medium of claim 5, in, The query further includes an indication of a second column vector having encoded values by which results of the query are grouped, the selected algorithm causing the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of a first register, the first subset comprising the decompressed encoded values of the second column vector; loading a second subset of values into corresponding lanes of a second register, the second subset comprising values of the first vector corresponding to the first subset of values; updating, with a single instruction, the decompressed encoded values in the lanes of the first register corresponding to the lanes of the second register including the indication that failed the filter to constant values, thereby generating an updated second column vector; and The query is executed on the column storage table using the updated second column vector, thereby generating a result of the query, the result including results of all groups except a group corresponding to the constant value.
8. The non-transitory computer readable medium of claim 5, in, The query further includes an indication of a second column vector having encoded values by which results of the query are grouped, the selected algorithm causing the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading each value in a first subset of values into a corresponding lane of a first register, the first subset comprising the decompressed encoded value of the second column vector; initializing, for each channel of the first register, a first counter in a corresponding channel of each of a plurality of other registers, such that each of the plurality of other registers holds a respective first counter for each channel of the first register, and all first counters in each of the other registers correspond to a unique decompressed encoded value of the second column vector; for each channel of the first register, incrementing the first counter of a corresponding channel of one of the plurality of other registers corresponding to the decompressed encoded value in the channel of the first register; for each other register of the plurality of other registers, summing the first counters in the other registers and adding the sum to a corresponding second counter for the corresponding unique decompressed encoded value; and A third counter is determined by subtracting the corresponding second counter from the total number of rows in the second column vector, the third counter value corresponding to a last one of the unique decompressed encoded values in the second column vector.
9. A system configured to perform a query on a column storage table including one or more coded values, the system include: at least one register configured to hold one or more values; at least one processor; as well as A computer readable medium comprising code which, when executed, causes the processor to: receiving the query, the query comprising a filter to be applied to at least a first column vector of the encoded values, wherein the first column vector comprises a plurality of consecutive segments, each segment being encoded separately from segments in another column vector in the column storage table; processing queries for a batch of the encoded values in segments of the first column vector to generate a first vector indicating corresponding encoded values that pass the filter or fail the filter; determining, from the first vector, a selectivity indicator of the filter for the encoded values in the batch, the selectivity indicator indicating: a proportion of the encoded values in the batch for segments of the first column vector that pass the filter, or a proportion of the encoded values in the batch for segments of the first column vector that do not pass the filter; determining a bit length for encoding of the encoded value in the segment of the first column vector; and For the batch of the encoded values, an algorithm is selected from a plurality of algorithms for further processing the query, the algorithm being selected based on the selectivity indicator of the batch and a determined bit length of the encoded values in the segment of the first column vector.
10. The system according to claim 9, in, The at least one register includes a first register and a second register, and the selected algorithm causes the processor to: adding bits to each of at least the batches of the encoded values in the first column vector, thereby generating decompressed encoded values of the first column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of the first register, the first subset comprising the decompressed encoded values; loading a second subset of values into corresponding lanes of the second register, the second subset comprising values of the first vector corresponding to the first subset of values; and Decompressed encoded values that pass through the filter are output from the first register into a filtered column vector based on values in the second subset using a single instruction.
11. The system according to claim 9, in, The at least one register includes a first register and a second register, wherein the query further includes an indication of a second column vector having encoded values, the results of the query being grouped by the encoded values, and the selected algorithm causes the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading a first subset of values into corresponding lanes of a first register, the first subset comprising the decompressed encoded values of the second column vector; loading a second subset of values into corresponding lanes of a second register, the second subset comprising values of the first vector corresponding to the first subset of values; updating, with a single instruction, the decompressed encoded values in the lanes of the first register corresponding to the lanes of the second register including the indication that failed the filter to constant values, thereby generating an updated second column vector; and The query is executed on the column storage table using the updated second column vector, thereby generating a result of the query, the result including results of all groups except a group corresponding to the constant value.
12. The system according to claim 9, in, The at least one register includes a first register and a plurality of other registers, wherein the query further includes an indication of a second column vector having encoded values, results of the query being grouped by the encoded values, and the selected algorithm causes the processor to: adding bits to the encoded values in the second column vector, thereby generating decompressed encoded values of the second column vector, each decompressed encoded value having the same length; loading each value in a first subset of values into a corresponding lane of a first register, the first subset comprising the decompressed encoded value of the second column vector; initializing, for each channel of the first register, a first counter in a corresponding channel of each of the plurality of other registers, such that each of the plurality of other registers holds a respective first counter for each channel of the first register, and all first counters in each of the other registers correspond to a unique decompressed encoded value of the second column vector; for each channel of the first register, incrementing the first counter of a corresponding channel of one of the plurality of other registers corresponding to the decompressed encoded value in the channel of the first register; for each other register of the plurality of other registers, summing the first counters in the other registers and adding the sum to a corresponding second counter for the corresponding unique decompressed encoded value; and A third counter is determined by subtracting the corresponding second counter from the total number of rows in the second column vector, the third counter value corresponding to a last one of the unique decompressed encoded values in the second column vector.
