Data sorting method and apparatus

By separating and storing the data to be sorted and calling independently, the problem of inefficient data sorting in the prior art is solved, and a more efficient sorting process is achieved.

WO2025123949A1PCT designated stage expired Publication Date: 2025-06-19BEIJING OCEANBASE TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/127296
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-12-15
Filing Date
2024-10-25
Publication Date
2025-06-19

AI Technical Summary

Technical Problem

In the prior art, when sorting data, the sort key and additional fields need to be stored together, resulting in additional cache space occupancy and inefficient sorting.

Method used

By determining the sorting key and additional fields in the data table, the data to be sorted and additional data are stored separately in memory, and the data to be sorted according to the preset sorting rules are sorted. Finally, the additional data is merged with the sorted data to be sorted to obtain the sorting result.

Benefits of technology

Reduces the amount of data that needs to be called during the sorting process, improves the sorting efficiency, and improves the cache hit rate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024127296_19062025_PF_FP_ABST
    Figure CN2024127296_19062025_PF_FP_ABST
Patent Text Reader

Abstract

The present description relates to the technical field of databases. Provided in one or more embodiments are a data sorting method and apparatus. The method comprises: determining in a data table a sorting key and an additional field associated with the sorting key, the sorting key being used for storing at least one row of data to be sorted, and the additional field being used for storing additional data corresponding to each row of said data; independently storing into a memory the at least one row of said data and the corresponding additional data; according to a preset sorting rule, sorting the at least one row of said data stored in the memory; combining the additional data stored in the memory with the sorted at least one row of said data, so as to obtain a sorting result. The embodiments of the present description store said data and the additional data separately, such that said data can be independently called in the sorting process, so as to complete the sorting operation for said data. The mode can reduce the amount of data needing to be called in the sorting process and further improves the sorting efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Data sorting method and device Technical Field

[0001] One or more embodiments of this specification relate to the field of database technology, and more particularly, to a data sorting method and device. Background Art

[0002] Data sorting is the process of arranging data stored in a database according to specific rules. Related technologies typically store the data in the sort key that participates in the sorting process together with the data in the additional fields that do not participate in the sorting process. During the sorting process, the data in the sort key and the additional fields are mobilized and sorted as a whole. This approach consumes additional cache space and results in lower sorting efficiency.

[0003] Summary of the Invention

[0004] In view of this, one or more embodiments of this specification provide a data sorting method and apparatus.

[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:

[0006] According to a first aspect of one or more embodiments of the present specification, a data sorting method is proposed, including: determining a sorting key and an additional field associated with the sorting key in a data table, the sorting key being used to store at least one row of data to be sorted, and the additional field being used to store additional data corresponding to each row of data to be sorted; storing the at least one row of data to be sorted and the corresponding additional data independently in a memory; sorting the at least one row of data to be sorted stored in the memory according to a preset sorting rule; and merging the additional data stored in the memory with the sorted at least one row of data to be sorted to obtain a sorting result.

[0007] According to a second aspect of one or more embodiments of the present specification, a data sorting device is proposed, including: a determination module for determining a sorting key and an additional field associated with the sorting key in a data table, the sorting key being used to store at least one row of data to be sorted, and the additional field being used to store additional data corresponding to each row of data to be sorted; a storage module for independently storing at least one row of data to be sorted and the corresponding additional data in a memory; a sorting module for sorting at least one row of data to be sorted stored in the memory according to a preset sorting rule; and a merging module for merging the additional data stored in the memory with the sorted at least one row of data to be sorted to obtain a sorting result.

[0008] According to a third aspect of one or more embodiments of this specification, an electronic device is proposed, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the method of the first aspect by running the executable instructions.

[0009] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided, on which computer instructions are stored. When the instructions are executed by a processor, the steps of the method of the first aspect are implemented.

[0010] The solution provided in this specification can determine the sorting key and the additional fields associated with the sorting key in the data table, and then independently store the data to be sorted stored in the sorting key and the additional data stored in the additional fields in the memory, and then sort at least one row of data to be sorted stored in the memory according to the preset sorting rules, and merge the additional data stored in the memory with the at least one row of data to be sorted after sorting to obtain the sorting result. The embodiment of this specification stores the data to be sorted and the additional data separately, and can call the data to be sorted separately during the sorting process to complete the sorting operation on the data to be sorted. This method reduces the amount of data that needs to be called during the sorting process and improves the sorting efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] FIG1 is a flow chart of a data sorting method provided by an exemplary embodiment.

[0012] FIG2 is a schematic diagram of a specific process of a data sorting method provided by an exemplary embodiment.

[0013] FIG3 is a schematic structural diagram of a device provided by an exemplary embodiment.

[0014] FIG4 is a schematic structural diagram of a data sorting device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0015] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with certain aspects of one or more embodiments of this specification, as detailed in the appended claims.

[0016] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than those described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments, and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0017] Data sorting refers to the process of arranging data stored in a database according to specific rules. Related technologies typically store the data involved in the sorting in the sort key and the data not involved in the sorting in the additional fields together. During the data sorting process, the data in the sort key and the data in the additional fields are mobilized and sorted as a whole.

[0018] However, in most cases, the sort key may be an integer or date type data, which requires very little storage space, while the additional fields may contain a lot of data and require a lot of storage space.

[0019] According to the sorting method provided by the relevant technology, storing the sort key and the additional fields together may cause the stored data to greatly exceed the capacity of the CPU cache, resulting in a low cache hit rate during the sorting process. Each time the key value is compared, the main memory needs to be accessed, resulting in poor performance and low sorting efficiency.

[0020] In view of this, the solution provided in this specification stores smaller sort key data separately from larger additional field data, so that the sort key data can be called separately during the sorting process, thereby storing as much sort key data as possible in the CPU cache, improving the cache hit rate and thus improving the sorting efficiency.

[0021] Specifically, the solution provided in this specification can determine the sorting key and the additional fields associated with the sorting key in the data table, and then independently store the data to be sorted stored in the sorting key and the additional data stored in the additional fields in the memory, and then sort at least one row of data to be sorted stored in the memory according to the preset sorting rules, and merge the additional data stored in the memory with the at least one row of data to be sorted after sorting to obtain the sorting result. By storing the data to be sorted and the additional data separately, the embodiment of this specification can call the data to be sorted separately during the sorting process to complete the sorting operation on the data to be sorted. This method reduces the amount of data that needs to be called during the sorting process and improves the sorting efficiency.

[0022] Next, exemplary embodiments of the present specification will be described in detail.

[0023] First, the embodiments of this specification provide a data sorting method, which can be executed by any electronic device.

[0024] FIG1 is a flow chart of a data sorting method provided by an exemplary embodiment. As shown in FIG1 , the data sorting method provided by the embodiment of this specification includes the following steps.

[0025] S101 , determining a sort key and additional fields associated with the sort key in a data table, wherein the sort key is used to store at least one row of data to be sorted, and the additional fields are used to store additional data corresponding to each row of data to be sorted.

[0026] It should be noted that a data table can be any one or more tables in a database, and these tables can serve as the query scope of a Structured Query Language (SQL) statement. The sort key and additional fields can be fields in the query results of the SQL statement, where the sort key is the field that directly participates in the sorting of the query results, while the additional fields are the fields that do not participate in the sorting of the query results. For example, for the SQL statement "select c1, c2, c3 from t order by c1", "t" is the data table, "c1", "c2", and "c3" are three fields in the data table, where "c1" is determined as the sort key, and "c2" and "c3" are determined as additional fields. By determining at least some fields as sort keys, the query results of the SQL statement can be output in the order of the data to be sorted in the sort key (for example, sorted in ascending order by numerical value, or sorted from A to Z by first letter).

[0027] It is understandable that the number of sorting keys can be one or more. In the case of multiple sorting keys, the data to be sorted in one of the sorting keys can be prioritized for sorting. If the data to be sorted in the sorting key are the same, the data to be sorted in other sorting keys can be referenced for sorting. For example, for the SQL statement "select c1,c2,c3 from t order by c1,c2", there are two fields "c1" and "c2" that are determined as sorting keys. In the sorting process, the data to be sorted in "c1" can be referenced for sorting first. If the data to be sorted in "c1" are the same, the data to be sorted in "c2" can be referenced for sorting.

[0028] That is to say, when there are multiple sorting keys, the data to be sorted in each sorting key may participate in the sorting process, and the final sorting result depends on the data to be sorted in multiple sorting keys at the same time.

[0029] Furthermore, it is also understood that the number of additional fields can be one or more. Since the additional data in the additional fields does not directly participate in the sorting process, but needs to be output according to the sorting results of the data to be sorted, regardless of the number of additional fields, during the sorting process, it is sufficient to ensure that the additional data in these additional fields maintains a corresponding relationship with the data to be sorted in the sort key. The additional data in the sorting results can be displayed together with the sorted data to be sorted according to their corresponding relationship with the data to be sorted.

[0030] S102: Store at least one row of data to be sorted and corresponding additional data in memory independently.

[0031] It should be noted that the data to be sorted and the additional data can be respectively encoded into data types that can be used for sorting and materialized and stored in the memory, so that the CPU can call the data to be sorted and the additional data to complete the sorting operation.

[0032] By storing the data to be sorted and the additional data separately, only the data to be sorted can be read and sorted during the sorting process, and the additional data can be merged with the sorted data to be sorted after the sorting is completed, thereby improving the efficiency of sorting.

[0033] Since there is a correspondence between the data to be sorted and the additional data, the correspondence between the two needs to be maintained during the process of storing the two separately, so that after independently sorting at least one row of data to be sorted, the additional data corresponding to each row of sorted data can be merged according to the correspondence to obtain the completed sorting result.

[0034] In some embodiments, an identification field may be added to the separately stored sorted data and the additional data, respectively, to indicate the corresponding relationship between the two. For example, the same identification field may be added to the corresponding sorted data and additional data.

[0035] In some embodiments, part of the additional data may be redundantly stored in each row of data to be sorted, or part of the data to be sorted may be redundantly stored in each row of additional data, so that a corresponding relationship between the two is obtained based on the redundantly stored data.

[0036] In some embodiments, at least one row of data to be sorted and the corresponding additional data can be stored in memory in a row-by-row manner. Each row of data to be sorted in the row-by-row storage includes an additional pointer field, which is used to store the memory address of the additional data corresponding to each row of data to be sorted. It will be appreciated that the additional pointer field contains a pointer to each row of data to be sorted. Since each row of additional data is stored in memory in a row-by-row manner, these pointers can directly point to the memory address of the data row containing the additional data.

[0037] By adding an additional pointer field to the data to be sorted, a corresponding relationship can be established between the data to be sorted and the additional data, eliminating the need to introduce additional data or redundantly store data, significantly reducing memory usage. In scenarios with large data volumes, this can increase the amount of data stored in memory at a time, thereby improving sorting speed.

[0038] S103: Sort at least one row of data to be sorted stored in the memory according to a preset sorting rule.

[0039] It should be noted that the preset sorting rule can be a sorting rule specified by the user. For example, for numerical data to be sorted, it can be sorted in ascending or descending order according to the numerical value. For string data to be sorted, it can be sorted in ascending or descending order according to the ASCII value of the first character. This embodiment of the present specification does not limit this.

[0040] In some embodiments, since the embodiments of this specification can independently call the data to be sorted for sorting without calling the additional data during the sorting process, and since the size of the data to be sorted is usually much smaller than the size of the additional data, the entire data to be sorted can be stored in the CPU cache to further improve the sorting efficiency.

[0041] For example, the at least one row of data to be sorted stored in the memory can be stored in a CPU cache. Subsequently, the at least one row of data to be sorted stored in the CPU cache is sorted according to a preset sorting rule. After the at least one row of data to be sorted in the CPU cache is sorted, the sorted at least one row of data to be sorted is returned to the memory so as to be merged with the additional data in the memory to obtain a complete sorting result.

[0042] It is understandable that since the access speed of the CPU cache is much higher than the access speed of the memory, by storing the data to be sorted in the CPU cache, all the data that needs to be called during the sorting process can be hit in the CPU cache, which can greatly improve the sorting efficiency.

[0043] S104: Merge the additional data stored in the memory with the sorted at least one row of data to be sorted to obtain a sorting result.

[0044] In some embodiments, if an additional pointer field is added to each separately stored row of data to be sorted, a corresponding additional pointer field also exists in each sorted row of data to be sorted. By replacing the additional pointer fields in at least one sorted row of data to be sorted with the corresponding additional data stored in memory, the data to be sorted and the additional data can be merged to output a complete sorting result.

[0045] Therefore, the solution provided in this specification separates the data to be sorted in the sort key and the additional data in the additional field, allowing the data to be sorted to be called separately during the sorting process, thereby improving sorting efficiency. After the sorting of the data to be sorted is completed, each row of additional data is merged with the sorted data to finally output the complete sorting result.

[0046] In some embodiments, the process of storing and merging the data to be sorted and the additional data separately also generates a certain amount of operation time. In some application scenarios (e.g., the additional data capacity is small), the generation of this operation time may make the above-mentioned separate storage and sorting solution not the optimal solution.

[0047] To solve the above problems, the embodiments of this specification can also adaptively select an appropriate sorting method according to the actual application scenario, so that a better sorting method can be automatically selected in different application scenarios. Please refer to the following description for its specific implementation method.

[0048] For example, before the data to be sorted and the additional data are stored separately, the data size of the at least one row of data to be sorted can be predicted. If the data size of the data to be sorted is smaller than the size of the CPU cache, the at least one row of data to be sorted and the corresponding additional data are stored separately in the memory, and then the method steps shown in S103 to S104 are performed.

[0049] When the size of the data to be sorted is smaller than the CPU cache, the data to be sorted can be stored in the CPU cache at once, eliminating the need for repeated memory access during the sorting process. In this case, the method of storing the data to be sorted and the additional data separately and sorting them is guaranteed to have a lower sorting cost, so this sorting method can be selected.

[0050] It should be noted that the CPU cache in this specification may be the CPU's Level 3 cache (L3Cache). The L3 cache is the largest cache in the CPU, which can accommodate as much data to be sorted as possible, reducing memory operations during the sorting process and thus improving sorting efficiency.

[0051] For example, before the data to be sorted and the additional data are stored separately, the sorting costs of storing the at least one row of data to be sorted and the corresponding additional data independently in memory and the sorting costs of storing the at least one row of data to be sorted and the corresponding additional data together in memory can be predicted. If the sorting costs of storing the at least one row of data to be sorted and the corresponding additional data together in memory are lower than the sorting costs of storing them together in memory, the at least one row of data to be sorted and the corresponding additional data can be stored independently in memory.

[0052] Among them, the sorting cost can be understood as the time consumed in the sorting process, which can be estimated by the query optimizer in the database. The sorting cost when at least one row of data to be sorted and the corresponding additional data are stored separately in the memory can be understood as the time consumed when executing the above S102 to S104 for sorting. The sorting cost when at least one row of data to be sorted is combined with the corresponding additional data and stored in the memory can be understood as the time consumed when at least one row of data to be sorted is combined with the corresponding additional data and stored in the memory, and the data to be sorted and the additional data stored together are sorted (i.e., the method steps shown in the above S102 to S104 are not executed). Those skilled in the art will understand that the method of storing the data to be sorted and the additional data together and sorting them is common knowledge of those skilled in the art, and the embodiments of this specification will not be elaborated on this.

[0053] It should be noted that the two adaptive judgment methods provided above can be used in combination. When used in combination, only one of the two needs to be met to ensure that the time consumption for sorting by executing the method steps shown in S102 to S104 above is lower. In other words, as long as the data size of the data to be sorted is smaller than the size of the CPU cache, or the sorting cost when the data is stored separately in the memory is smaller than the sorting cost when the data is stored together in the memory, the method steps shown in S102 to S104 above can be executed to quickly output the sorting result.

[0054] In some embodiments, because predicting the sorting cost takes more time than predicting the size of the data to be sorted, the aforementioned method of predicting the size of the data to be sorted can be used first. If the size of the data to be sorted is greater than or equal to the size of the CPU cache, the sorting cost is predicted, thereby reducing the time spent in selecting the sorting method.

[0055] For ease of understanding, the specific implementation of the embodiment of this specification will be described below with reference to FIG2 .

[0056] Specifically, Figure 2 is a schematic diagram of a data sorting method according to an exemplary embodiment. Referring to Figure 2 , upon receiving a user input query sorting instruction (select c1, c2, c3 from t order by c1), "c1" can be determined as the sorting key within the data table, and "c2" and "c3" can be determined as additional fields.

[0057] Subsequently, an adaptive judgment can be made for the data stored in "c1," "c2," and "c3." If the data stored in sort key "c1" is smaller than the CPU's L3 cache, or if the sorting cost of storing sort key "c1" separately from additional fields "c2" and "c3" is lower than the sorting cost of storing sort key "c1" together with additional fields "c2" and "c3," it can be determined that sorting using separate storage takes less time and is more efficient. Therefore, it can be considered that the sorting task for sort key "c1" and additional fields "c2" and "c3" meets the adaptive judgment criteria and can be sorted using separate storage.

[0058] As a result, the data in the sort key "c1" and the data in the additional fields "c2" and "c3" can be encoded into data types suitable for sorting and materialized and stored in memory. The data in the sort key "c1" and the data in the additional fields "c2" and "c3" are stored in memory in a row-wise manner. An additional pointer field is added to the row-wise stored sort key data. The additional pointer field stores the memory address of the additional field in each row of the row-wise storage, thereby maintaining the correspondence between the data in the sort key "c1" and the data in the additional fields "c2" and "c3."

[0059] The data in the sort key "c1" with the additional pointer field is stored in the CPU's L3 cache, where it is sorted according to the preset rules. The sort result is then returned to memory, and the additional pointer fields in the sort result are replaced with the additional data corresponding to the memory addresses where they were stored. This allows the sorted data in the sort key "c1" to be merged with the data in the additional fields "c2" and "c3" to obtain the complete sort result.

[0060] FIG3 is a schematic diagram of the structure of a device provided by an exemplary embodiment. Referring to FIG3 , at the hardware level, the device includes a processor 302, an internal bus 304, a network interface 306, a memory 308, and a non-volatile memory 310, and may also include hardware required for other functions. One or more embodiments of this specification may be implemented based on software, such as the processor 302 reading the corresponding computer program from the non-volatile memory 310 into the memory 308 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but may also be hardware or logic devices.

[0061] Please refer to FIG4 , which provides a data sorting device 400 that can be applied to the device shown in FIG3 to implement the technical solution of this specification. Exemplarily, the data sorting device 400 may include:

[0062] The determination module 401 is used to determine a sort key and additional fields associated with the sort key in a data table, wherein the sort key is used to store at least one row of data to be sorted, and the additional fields are used to store additional data corresponding to each row of data to be sorted.

[0063] The storage module 402 is configured to independently store the at least one row of data to be sorted and the corresponding additional data in a memory.

[0064] The sorting module 403 is configured to sort at least one row of data to be sorted stored in the memory according to a preset sorting rule.

[0065] The merging module 404 is configured to merge the additional data stored in the memory with the sorted at least one row of data to be sorted to obtain a sorting result.

[0066] In some embodiments, the sorting module 403 is specifically used to store at least one row of data to be sorted stored in the memory into the central processing unit CPU cache; sort the at least one row of data to be sorted stored in the CPU cache according to a preset sorting rule; and return the sorted at least one row of data to be sorted to the memory.

[0067] In some embodiments, the data sorting device 400 further includes a first prediction module (not shown). The first prediction module is configured to predict the data size of the at least one row of data to be sorted. The storage module 402 is specifically configured to, when the data size is smaller than the size of the CPU cache, independently store the at least one row of data to be sorted and the corresponding additional data in a memory.

[0068] In some embodiments, the data sorting device 400 further includes a second prediction module (not shown). The second prediction module is configured to predict the sorting cost when the at least one row of data to be sorted and the corresponding additional data are stored separately in the memory, and the sorting cost when the at least one row of data to be sorted and the corresponding additional data are stored together in the memory. The storage module 402 is specifically configured to store the at least one row of data to be sorted and the corresponding additional data separately in the memory if the sorting cost when the at least one row of data to be sorted and the corresponding additional data are stored separately in the memory.

[0069] In some embodiments, the storage module 402 is specifically used to store the at least one row of data to be sorted and the corresponding additional data in row-by-row manner in the memory, wherein an additional pointer field is added to each row of data to be sorted stored in row-by-row manner, and the additional pointer field is used to store the memory address of the additional data corresponding to each row of data to be sorted in the memory.

[0070] In some embodiments, the merging module 404 is specifically configured to replace the additional pointer field in at least one row of sorted data with corresponding additional data stored in the memory to obtain a sorting result.

[0071] In some embodiments, the CPU cache is a CPU level 3 cache.

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

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

[0074] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

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

[0076] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0077] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0078] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "an," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0079] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when..." or "when..." or "in response to determining."

[0080] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included in the scope of protection of one or more embodiments of this specification.

Claims

1. A data sorting method, comprising: Determine a sort key and an additional field associated with the sort key in the data table, wherein the sort key is used to store at least one row of data to be sorted, and the additional field is used to store additional data corresponding to each row of data to be sorted; The at least one row of data to be sorted and the corresponding additional data are stored separately in the memory; Sort at least one row of data to be sorted stored in the memory according to a preset sorting rule; The additional data stored in the memory is merged with at least one row of sorted data to be sorted to obtain a sorting result.

2. The method according to claim 1, wherein the step of sorting at least one row of data to be sorted stored in the memory according to a preset sorting rule comprises: Storing at least one row of data to be sorted stored in the memory into a CPU cache; Sorting at least one row of data to be sorted stored in the CPU cache according to a preset sorting rule; Returning at least one row of sorted data to be sorted to the memory.

3. The method according to claim 2, before storing the at least one row of data to be sorted and the corresponding additional data separately in the memory, the method further comprises: Predicting the data size of the at least one row of data to be sorted; The step of independently storing the at least one row of data to be sorted and the corresponding additional data in the memory includes: In a case where the data size is smaller than the size of the CPU cache, the at least one row of data to be sorted and the corresponding additional data are independently stored in the memory.

4. The method according to claim 1, before storing the at least one row of data to be sorted and the corresponding additional data separately in the memory, the method further comprises: Predicting the sorting cost when the at least one row of data to be sorted and the corresponding additional data are stored separately in the memory, and the sorting cost when the at least one row of data to be sorted is stored together with the corresponding additional data in the memory; The step of independently storing the at least one row of data to be sorted and the corresponding additional data in the memory includes: In a case where the sorting cost when they are stored separately and independently in the memory is less than the sorting cost when they are stored together in the memory, the at least one row of data to be sorted and the corresponding additional data are stored separately and independently in the memory.

5. The method according to any one of claims 1 to 4, wherein the step of independently storing the at least one row of data to be sorted and the corresponding additional data in a memory comprises: The at least one row of data to be sorted and the corresponding additional data are respectively stored in a row-by-row manner in the memory, wherein an additional pointer field is added to each row of data to be sorted in the row-by-row storage, and the additional pointer field is used to store the memory address of the additional data corresponding to each row of data to be sorted in the memory.

6. The method according to claim 5, wherein the step of merging the additional data stored in the memory with the sorted at least one row of data to be sorted to obtain the sorting result comprises: The additional pointer field in at least one row of sorted data to be sorted is replaced with the corresponding additional data stored in the memory to obtain a sorting result.

7. The method according to claim 2 or 3, wherein the CPU cache is a third-level cache of the CPU.

8. A data sorting device, comprising: A determination module, used to determine a sort key and an additional field associated with the sort key in a data table, wherein the sort key is used to store at least one row of data to be sorted, and the additional field is used to store additional data corresponding to each row of data to be sorted; A storage module, used for independently storing the at least one row of data to be sorted and the corresponding additional data in a memory; A sorting module, used to sort at least one row of data to be sorted stored in the memory according to a preset sorting rule; The merging module is used to merge the additional data stored in the memory with at least one row of sorted data to be sorted to obtain a sorting result.

9. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 7 by running the executable instructions.

10. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data sorting method and device, electronic medium and storage medium

    CN112527847A

  • Data sorting method and device

    CN117763008A

  • Systems and methods for column store indices

    US20230394017A1