Data sorting method and device, computer device and storage medium

By dividing the data sequence into basic sub-data sequences and combining and merging them, the problem of low efficiency in large-scale data sorting in traditional methods is solved, and efficient data sorting and query performance are improved.

CN116401292BActive Publication Date: 2026-06-05KINGDEE SOFTWARE(CHINA) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
KINGDEE SOFTWARE(CHINA) CO LTD
Filing Date
2023-04-14
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Traditional data sorting methods are inefficient in large-scale data processing and cannot effectively improve data query performance.

Method used

The initial data sequence is divided into multiple basic sub-data sequences, which are then combined and merged. The sorting continues after a break in the sorting process, based on the merge depth value, until the termination condition is met.

Benefits of technology

It improves data sorting efficiency and ensures data orderliness, thereby enhancing the efficiency and performance of data querying in the database, especially significantly improving the query efficiency of large-scale data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116401292B_ABST
    Figure CN116401292B_ABST
Patent Text Reader

Abstract

The application relates to a data sorting method and device, a computer device, a storage medium and a computer program product. The method comprises the following steps: obtaining an initial data sequence, dividing the initial data sequence to obtain a plurality of basic sub-data sequences; taking each basic sub-data sequence as an initial sub-data sequence, combining each initial sub-data sequence to obtain a plurality of initial sub-data sequence combinations; performing merge sorting on each initial sub-data sequence in the same initial sub-data sequence combination to obtain an intermediate sub-data sequence combination corresponding to each initial sub-data sequence combination; taking the intermediate sub-data sequence combination as an initial sub-data sequence, returning to the step of combining each initial sub-data sequence until a termination condition is met, and obtaining an ordered data sequence corresponding to the initial data sequence. The method can improve the data sorting efficiency and can be applied to a multidimensional database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data sorting method, apparatus, computer equipment, storage medium, and computer program product. Background Technology

[0002] With the development of computer technology, data sorting techniques have emerged. Traditional methods for sorting data involve determining the maximum or minimum value of each piece of data to be sorted, writing the maximum or minimum value into the sorted data sequence, and then determining the maximum or minimum value from the remaining pieces of data to be sorted, writing the maximum or minimum value into the sorted data sequence, and so on, until all data is sorted and a complete sorted data sequence is obtained.

[0003] However, when the data volume is large, sorting the data using traditional methods results in low sorting efficiency. Summary of the Invention

[0004] Therefore, it is necessary to provide a data sorting method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve sorting efficiency in response to the above-mentioned technical problems.

[0005] This application provides a data sorting method. The method includes:

[0006] Obtain the initial data sequence, and divide the initial data sequence into multiple basic sub-data sequences;

[0007] Each basic sub-data sequence is used as an initial sub-data sequence, and the initial sub-data sequences are combined to obtain multiple combinations of initial sub-data sequences.

[0008] Merge sort each initial sub-data sequence in the same initial sub-data sequence combination to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination; the intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merge depth value; the merge depth value is used to continue sorting from the point of interruption after sorting is interrupted.

[0009] The intermediate sub-data sequences are combined to form the initial sub-data sequences. The process of combining the initial sub-data sequences is repeated until the termination condition is met, resulting in an ordered data sequence corresponding to the initial data sequences.

[0010] This application also provides a data sorting apparatus. The apparatus includes:

[0011] The data sequence acquisition module is used to acquire the initial data sequence and divide the initial data sequence into multiple basic sub-data sequences;

[0012] The data sequence combination module is used to take each basic sub-data sequence as an initial sub-data sequence and combine the initial sub-data sequences to obtain multiple initial sub-data sequence combinations.

[0013] The data sequence merging module is used to merge and sort the initial sub-data sequences in the same initial sub-data sequence combination to obtain the intermediate sub-data sequence combination corresponding to each initial sub-data sequence combination. The intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merge depth value. The merge depth value is used to continue sorting from the point of interruption after the sorting is interrupted.

[0014] The ordered sequence determination module is used to combine intermediate sub-data sequences as initial sub-data sequences, return the execution of the steps for combining each initial sub-data sequence until the termination condition is met, and obtain the ordered data sequence corresponding to the initial data sequence.

[0015] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the above-described data sorting method.

[0016] A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described data sorting method.

[0017] A computer program product includes a computer program that, when executed by a processor, implements the steps of the above-described data sorting method.

[0018] The aforementioned data sorting method, apparatus, computer equipment, storage medium, and computer program product combine initial sub-data sequences corresponding to an initial data sequence to obtain multiple initial sub-data sequence combinations. Then, they perform merge sorting on each initial sub-data sequence in different initial sub-data sequence combinations to obtain intermediate sub-data sequence combinations. The merge depth value of the multiple merged base sub-data sequences in the intermediate sub-data sequence combinations is updated. The merge depth value is used to continue sorting from the point of interruption after a sorting interruption. Then, each intermediate sub-data sequence combination is used as an initial sub-data sequence, and the step of combining the initial sub-data sequences corresponding to the initial data sequence is returned for execution until the merging is complete, resulting in an ordered data sequence corresponding to the initial data sequence. Thus, by combining the initial sub-data sequences corresponding to the initial data sequence, performing merge sorting on each initial sub-data sequence combination to obtain ordered intermediate sub-data sequence combinations, and then using these intermediate sub-data sequence combinations as initial sub-data sequences, the step of combining the initial sub-data sequences is returned for execution until the merging is complete. Dividing the data sorting task of the initial data sequence into multiple parts, and performing merge sort on each part separately, can effectively improve the efficiency of data sorting. Furthermore, based on the merge depth value corresponding to each basic sub-data sequence, after a sorting interruption, sorting can resume from the point of interruption without re-sorting, further improving efficiency. In addition, improved data sorting efficiency effectively ensures the ordered nature of data in the database, thereby improving the efficiency and performance of subsequent data queries. This improvement is even more pronounced for large-scale data queries. This is because when the data in the database is ordered, there is no need for traversal queries; search algorithms can be used to improve query performance, such as binary search. Attached Figure Description

[0019] Figure 1 This is a diagram illustrating the application environment of a data sorting method in one embodiment;

[0020] Figure 2 This is a flowchart illustrating a data sorting method in one embodiment;

[0021] Figure 3 This is a flowchart illustrating the process of continuing the sorting from the point of interruption in one embodiment;

[0022] Figure 4 This is a schematic diagram illustrating the sorting of key values ​​in a multidimensional database in one embodiment;

[0023] Figure 5 This is a flowchart illustrating the data sorting process in one embodiment;

[0024] Figure 6This is a structural block diagram of a data sorting device in one embodiment;

[0025] Figure 7 This is a structural block diagram of a data sorting device in another embodiment;

[0026] Figure 8 This is an internal structural diagram of a computer device in one embodiment;

[0027] Figure 9 This is a diagram of the internal structure of a computer device in another embodiment. Detailed Implementation

[0028] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0029] The data sorting method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104 or located on the cloud or other network servers. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can be smart TVs, smart in-vehicle devices, etc. Portable wearable devices can be smartwatches, smart bracelets, head-mounted devices, etc. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers. Terminal 102 and server 104 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.

[0030] Both the terminal and the server can be used independently to execute the data sorting method provided in the embodiments of this application.

[0031] For example, the terminal acquires an initial data sequence and divides it into multiple basic sub-data sequences. The terminal uses each basic sub-data sequence as its own initial sub-data sequence and combines these sequences to obtain multiple initial sub-data sequence combinations. The terminal performs merge sorting on the initial sub-data sequences within the same initial sub-data sequence combination to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination. Each intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, each with a corresponding merge depth value. The merge depth value is used to resume sorting from the point of interruption if the sorting is interrupted. The terminal uses the intermediate sub-data sequence combination as its initial sub-data sequence and returns to the step of combining the initial sub-data sequences until the termination condition is met, resulting in an ordered data sequence corresponding to the initial data sequence.

[0032] Terminals and servers can also work together to execute the data sorting method provided in the embodiments of this application.

[0033] For example, a terminal sends a data sorting request to a server. This request carries a sequence identifier corresponding to the initial data sequence. The server retrieves the initial data sequence based on the sequence identifier and divides it into multiple basic sub-data sequences. The server uses each basic sub-data sequence as its own initial sub-data sequence and combines them to obtain multiple initial sub-data sequence combinations. The server performs merge sorting on the initial sub-data sequences within the same initial sub-data sequence combination, resulting in intermediate sub-data sequence combinations for each initial sub-data sequence combination. Each intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, each with a corresponding merge depth value. This merge depth value is used to resume sorting from the point of interruption if the sorting process is interrupted. The server uses the intermediate sub-data sequence combinations as initial sub-data sequences and returns to the step of combining the initial sub-data sequences until a termination condition is met, resulting in an ordered data sequence corresponding to the initial data sequence. The server sends the ordered data sequence to the terminal, which can then display the ordered data sequence.

[0034] In one embodiment, such as Figure 2 As shown, a data sorting method is provided. Taking the application of this method to a computer device as an example, the computer device can be a terminal or a server. The method can be executed independently by the terminal or server, or it can be implemented through interaction between the terminal and the server. The data sorting method includes the following steps:

[0035] Step S202: Obtain the initial data sequence and divide the initial data sequence into multiple basic sub-data sequences.

[0036] The initial data sequence refers to the data sequence that needs to be sorted. The basic sub-data sequences refer to the data sequences obtained after dividing the initial data sequence. For example, when the initial data sequence is array A

[10] ={5,2,13,24,12,4,1,7,8,10}, array A is divided according to a fixed length of 4 to obtain the data sequence A1[4]={5,2,13,24} composed of the 1st to 4th data in array A, the data sequence A2[4]={12,4,1,7} composed of the 5th to 8th data in array A, and the data sequence A3[2]={8,10} composed of the 9th to 10th data in array A. The data sequences A1~A3 are the three basic sub-data sequences corresponding to the initial data sequence A. If each basic sub-data sequence is divided into three sub-data sequences, the data sequence A1~A3 is divided into three sub-data sequences. The basic sub-data sequences are sorted in ascending order. At this time, array A

[10] = {2,5,13,24,1,4,7,12,8,10}, and the basic sub-data sequences corresponding to array A are A1[4] = {2,5,13,24}, A2[4] = {1,4,7,12} and A3[2] = {8,10}. If the basic sub-data sequences A1 and A2 are merge sorted, the basic sub-data sequences corresponding to array A are A1[4] = {1,2,4,5}, A2[4] = {7,12,13,24} and A3[2] = {8,10}.

[0037] For example, in data sorting, the traditional method involves determining the target data (maximum or minimum value) from the initial data sequence, writing the target data into the already sorted data sequence, then determining the target data from the remaining unsorted data in the initial data sequence, writing the target data into the already sorted data sequence, and so on, until all data is sorted, resulting in a complete sorted data sequence. However, when the amount of data to be sorted is large, this traditional method suffers from low sorting efficiency. To improve data sorting efficiency, the computer acquires the initial data sequence and divides it into multiple basic sub-data sequences of a fixed length. Then, each basic sub-data sequence corresponding to the initial data sequence is used as an initial sub-data sequence. These initial sub-data sequences are combined to obtain combinations of initial sub-data sequences. These combinations of initial sub-data sequences are then merged and sorted to obtain ordered combinations of intermediate sub-data sequences. Finally, these intermediate sub-data sequence combinations are used as initial sub-data sequences, and the process of combining the initial sub-data sequences is repeated until the merging is complete. In this way, the data sorting task for the initial data sequence is divided into multiple parts, and each part is merge sorted separately, which can effectively improve the efficiency of data sorting.

[0038] Step S204: Each basic sub-data sequence is used as an initial sub-data sequence, and the initial sub-data sequences are combined to obtain multiple initial sub-data sequence combinations.

[0039] Here, an initial sub-data sequence refers to a data sequence that is already internally ordered. A combination of initial sub-data sequences refers to a combination of data sequences that contain multiple initial sub-data sequences.

[0040] For example, if the data in the basic sub-data sequence is unordered, the computer device first sorts the basic sub-data sequence, and then uses the sorted basic sub-data sequence as the initial sub-data sequence. If the data in the basic sub-data sequence is ordered, the basic sub-data sequence is directly used as the initial sub-data sequence to obtain various initial sub-data sequences. Starting from the first initial sub-data sequence corresponding to the initial data sequence, adjacent initial sub-data sequences are combined according to a preset number to obtain multiple initial sub-data sequence combinations. For example, if the initial data sequence corresponds to 6 initial sub-data sequences, and each initial sub-data sequence is A1-A6, when the preset number is 2, adjacent initial sub-data sequences are combined pairwise starting from A1, resulting in initial sub-data sequence combinations of {A1,A2}, {A3,A4}, and {A5,A6}; when the preset number is 3, adjacent initial sub-data sequences are combined starting from A1, resulting in initial sub-data sequence combinations of {A1,A2,A3} and {A4,A5,A6}; and so on.

[0041] Step S206: Merge sort each initial sub-data sequence in the same initial sub-data sequence combination to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination; the intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merge depth value; the merge depth value is used to continue sorting from the point of interruption after the sorting is interrupted.

[0042] The intermediate sub-data sequence combination refers to the data sequence combination obtained after merging and sorting the initial sub-data sequences in the initial sub-data sequence combination. The merged basic sub-data sequence refers to the basic sub-data sequences corresponding to the intermediate sub-data sequence combination obtained after merging the initial sub-data sequences in the initial sub-data sequence combination.

[0043] The merge depth value corresponding to the basic sub-data sequence refers to the number of merge sorts that the basic sub-data sequence has undergone.

[0044] For example, a computer device determines the unsorted data in each of the initial sub-data sequences included in the same initial data sequence combination, and determines the target data from the unsorted data included in each initial sub-data sequence. For instance, when sorting the initial data sequence in descending order, the maximum value among the unsorted data included in each initial sub-data sequence is used as the target data; when sorting the initial data sequence in ascending order, the minimum value among the unsorted data included in each initial sub-data sequence is used as the target data. After writing the target data into the sorted data sequence corresponding to the initial sub-data sequence combination, the step of determining the target data from the unsorted data included in each initial sub-data sequence is returned for execution until the merging is completed, resulting in the sorted data sequence corresponding to the initial sub-data sequence combination. The initial sub-data sequence combination is updated based on the sorted data sequence to obtain the intermediate sub-data sequence combination. The same method is used to determine the intermediate sub-data sequence combinations corresponding to each of the other initial sub-data sequences, thereby obtaining the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination. For example, when the initial sub-data sequence combination includes two initial sub-data sequences A1[4]={2,5,13,24} and A2[4]={1,4,7,12}, the sorted data sequence obtained by merging and sorting A1 and A2 is {1,2,4,5,7,12,13,24}. The initial sub-data sequence combination is updated based on the sorted data sequence to obtain the intermediate sub-data sequence combination, which includes two updated initial sub-data sequences, A1[4]={1,2,4,5} and A2[4]={7,12,13,24}.

[0045] Step S208: Combine the intermediate sub-data sequences as the initial sub-data sequences, return to the step of combining each initial sub-data sequence, and continue until the termination condition is met to obtain the ordered data sequence corresponding to the initial data sequence.

[0046] The termination condition refers to the condition used to determine whether the sorting has ended. For example, the termination condition can be that there is only one initial sub-data sequence; the termination condition can also be that the merge depth value corresponding to each basic sub-data sequence reaches a preset threshold; and so on. An ordered data sequence refers to a data sequence obtained after sorting the initial data sequence.

[0047] For example, the computer device combines each intermediate sub-data sequence as an initial sub-data sequence to obtain each initial sub-data sequence. For instance, when the combination of intermediate sub-data sequences includes two merged basic sub-data sequences, A1[4]={1,2,4,5} and A2[4]={7,12,13,24}, the combination of intermediate sub-data sequences is used as the initial sub-data sequence. At this time, the initial sub-data sequence is the data sequence {1,2,4,5,7,12,13,24} composed of A1 and A2.

[0048] In one embodiment, when the termination condition is that the merge depth value corresponding to each basic sub-data sequence reaches a preset threshold, the preset threshold can be calculated using the following formula:

[0049]

[0050] Where D is the preset threshold, z is the number of combinations corresponding to the initial data sequence, and X is the sequence length corresponding to the initial data sequence.

[0051] In one embodiment, the data sorting method of this application can also be applied to data sorting in a database. For example, it can be applied to sorting data in various types of databases such as multidimensional databases and relational databases. In a multidimensional database, each piece of data is stored in a multidimensional array, meaning that each piece of data contains information in multiple dimensions. The data in the multidimensional database is sorted according to the key values ​​corresponding to each piece of data in the multidimensional database.

[0052] In the aforementioned data sorting method, multiple initial sub-data sequences are combined to obtain multiple initial sub-data sequence combinations. Merge sorting is then performed on each initial sub-data sequence in each of these combinations to obtain intermediate sub-data sequence combinations. The merge depth value of each merged base sub-data sequence in the intermediate sub-data sequence combinations is updated. This merge depth value is used to resume sorting from the point of interruption if the sorting process is interrupted. Then, each intermediate sub-data sequence combination is used as an initial sub-data sequence, and the process of combining the initial sub-data sequences corresponding to the initial data sequence is repeated until the merging is complete, resulting in an ordered data sequence corresponding to the initial data sequence. Thus, by combining the initial sub-data sequences corresponding to the initial data sequence, merging and sorting each initial sub-data sequence combination to obtain ordered intermediate sub-data sequence combinations, and then using these intermediate sub-data sequence combinations as initial sub-data sequences, the process of combining the initial sub-data sequences is repeated until the merging is complete. Dividing the data sorting task for the initial data sequence into multiple parts, with each part undergoing merge sorting separately, effectively improves the efficiency of data sorting. Furthermore, based on the merge depth values ​​corresponding to each basic sub-data sequence, sorting can resume from the point of interruption after a sorting interruption, without needing to re-sort, thus significantly improving data sorting efficiency. In addition, improved data sorting efficiency effectively ensures the ordered nature of data in the database, thereby improving the efficiency and performance of subsequent data queries. This improvement is even more pronounced for large-scale data queries. This is because when the data in the database is ordered, there is no need to traverse the data; search algorithms can be used to improve query performance, such as binary search.

[0053] In one embodiment, an initial data sequence is obtained, and the initial data sequence is divided into multiple basic sub-data sequences, including:

[0054] Obtain the initial data sequence and the corresponding segment length; based on the segment length, divide the initial data sequence into multiple candidate sub-data sequences; sort each candidate sub-data sequence to obtain the basic sub-data sequences corresponding to the initial data sequence.

[0055] Here, segment length refers to the sequence length used to divide the initial data sequence, indicating the sequence length of each resulting data sequence. The sequence length of a data sequence refers to the number of data points it contains. Candidate sub-data sequences refer to the initial unsorted basic data sequences obtained after dividing the initial data sequence. For example, when the initial data sequence is array A

[10] ={5,2,13,24,12,4,1,7,8,10}, the segment length corresponding to the initial data sequence is 4. Array A is divided according to the segment length of 4 to obtain the data sequence A1[4]={5,2,13,24} composed of the 1st to 4th data in array A, the data sequence A2[4]={12,4,1,7} composed of the 5th to 8th data in array A, and the data sequence A3[2]={8,10} composed of the 9th to 10th data in array A. The data sequences A1 to A3 are the three initial unsorted basic sub-data sequences corresponding to the initial data sequence A, that is, the candidate sub-data sequences. The sequence lengths corresponding to the data sequences A1 to A3 are 4, 4 and 2 respectively.

[0056] For example, a computer device obtains an initial data sequence and the corresponding segment lengths of the initial data sequence, divides the initial data sequence based on the segment lengths to obtain multiple candidate sub-data sequences. The data in each candidate sub-data sequence is then sorted to obtain the corresponding basic sub-data sequences of the initial data sequence. For instance, when sorting the initial data sequence in ascending order, the initial data sequence is divided into multiple candidate sub-data sequences based on the corresponding segment lengths, and then each initial sub-data sequence is sorted in ascending order to obtain the corresponding basic data sequences; similarly, when sorting the initial data sequence in descending order, the initial data sequence is divided into multiple candidate sub-data sequences based on the corresponding segment lengths, and then each initial sub-data sequence is sorted in descending order to obtain the corresponding basic data sequences.

[0057] In the above embodiments, by obtaining the segment length corresponding to the initial data sequence, the initial data sequence is divided into multiple candidate sub-data sequences, and each candidate sub-data sequence is sorted to obtain each basic sub-data sequence. By merging and sorting each internally ordered basic sub-data sequence, the ordered data sequence corresponding to the initial data sequence can be obtained, which can improve the efficiency of data sorting.

[0058] In one embodiment, the initial sub-data sequences are combined to obtain multiple combinations of initial sub-data sequences, including:

[0059] Obtain the even-numbered sub-data sequences corresponding to each odd-numbered sub-data sequence in each initial sub-data sequence; the even-numbered sub-data sequence corresponding to the odd-numbered sub-data sequence is the next initial sub-data sequence corresponding to the odd-numbered sub-data sequence; when an odd-numbered sub-data sequence has a corresponding even-numbered sub-data sequence, combine the odd-numbered sub-data sequence and the corresponding even-numbered sub-data sequence to obtain the initial sub-data sequence combination; when an odd-numbered sub-data sequence does not have a corresponding even-numbered sub-data sequence, use the odd-numbered sub-data sequence as the initial sub-data sequence combination.

[0060] Among them, the odd-numbered sub-data sequence refers to the initial sub-data sequence located at the odd-numbered position, determined according to the corresponding order of each initial sub-data sequence in the initial data sequence. The even-numbered sub-data sequence refers to the initial sub-data sequence located at the even-numbered position, determined according to the corresponding order of each initial sub-data sequence in the initial data sequence. For example, when the initial data sequence is array A

[10] ={5,2,13,24,12,4,1,7,8,10}, the initial data sequence is divided to obtain each initial unsorted basic sub-data sequence. Each basic sub-data sequence is sorted in ascending order to obtain each sorted and internally ordered basic sub-data sequence as A1[4]={2,5,13,24}, A2[4]={1,4,7,12} and A3[2]={8,10}, respectively. The basic sub-data sequences A1~A3 are used as the initial data sequences. The corresponding initial sub-data sequences are as follows: A1, A2, and A3 are the first, second, and third initial sub-data sequences corresponding to the initial data sequence, respectively. Therefore, A1 and A3 are the odd-numbered sub-data sequences in the initial sub-data sequence, and A2 is the even-numbered sub-data sequence in the initial sub-data sequence. At the same time, the even-numbered sub-data sequence corresponding to the odd-numbered sub-data sequence A1 is A2, that is, A2 is the next initial sub-data sequence corresponding to A1. The odd-numbered sub-data sequence A3 does not have a corresponding even-numbered sub-data sequence.

[0061] For example, in each initial sub-data sequence, the computer device determines the even-numbered sub-data sequence corresponding to each odd-numbered sub-data sequence, that is, the next initial sub-data sequence corresponding to each odd-numbered sub-data sequence. If an odd-numbered sub-data sequence has a corresponding even-numbered sub-data sequence, the odd-numbered sub-data sequence and the corresponding even-numbered sub-data sequence are combined to obtain a combination of initial sub-data sequences. If an odd-numbered sub-data sequence does not have a corresponding even-numbered sub-data sequence, the odd-numbered sub-data sequence is directly used as the initial sub-data sequence combination to obtain multiple combinations of initial sub-data sequences.

[0062] In the above embodiments, the odd-numbered and even-numbered sub-data sequences are combined in pairs to obtain multiple initial sub-data sequence combinations. In this way, the merge sort is performed on each initial sub-data sequence combination, which can improve the efficiency of data sorting.

[0063] In one embodiment, the data sorting method further includes:

[0064] Obtain the number of combinations corresponding to the initial data sequence; the number of combinations is the number of initial sub-data sequences included in the combination of initial sub-data sequences; based on the number of combinations and the number of merged basic sub-data sequences included in the combination of intermediate sub-data sequences, determine the merge depth value corresponding to each merged basic sub-data sequence in the combination of intermediate sub-data sequences.

[0065] The combination quantity refers to the preset number of initial sub-data sequences used to combine the various initial sub-data sequences, indicating the number of initial sub-data sequences included in the combination. For example, when the initial data sequence A corresponds to 9 initial sub-data sequences, and the initial sub-data sequences are A1-A9, if the combination quantity corresponding to the initial data sequence A is 2, combining the initial sub-data sequences will result in the following combinations: {A1,A2}, {A3,A4}, {A5,A6}, {A7,A8}, and {A9}; if the combination quantity corresponding to the initial data sequence A is 3, combining the initial sub-data sequences will result in the following combinations: {A1,A2,A3}, {A4,A5,A6}, and {A7,A8,A9}; and so on.

[0066] For example, the computer device obtains the number of combinations corresponding to the initial data sequence, determines the number of basic sub-data sequences included in the intermediate sub-data sequence combination, and performs logarithmic processing on the number of basic sub-data sequences included in the intermediate sub-data sequence combination based on the number of combinations to obtain the merge depth value corresponding to each basic sub-data sequence included in the intermediate sub-data sequence combination.

[0067] In one embodiment, the merge depth value corresponding to the basic sub-data sequence can be calculated using the following formula:

[0068]

[0069] Where, depth i Let z be the merge depth of the i-th basic sub-data sequence corresponding to the initial data sequence, and z be the number of combinations corresponding to the initial data sequence. i This represents the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which the i-th basic sub-data sequence belongs.

[0070] For example, when the initial data sequence is divided into 11 basic sub-data sequences A1-A11, and the number of combinations corresponding to the initial data sequence is 3, each basic sub-data sequence is used as an initial sub-data sequence. Based on the number of combinations, the initial sub-data sequences are combined to obtain multiple initial sub-data sequence combinations. The first round of merge sorting is then performed to obtain the intermediate sub-data sequence combinations, namely {A1, A2, A3}, {A4, A5, A6}, {A7, A8, A9}, and {A10, A11}. At this point, for the first basic sub-data sequence A1 corresponding to the initial data sequence, the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which A1 belongs is 3, i.e., N1 = 3. The merge depth value corresponding to A1 is... For the 10th basic sub-data sequence A10 corresponding to the initial data sequence, the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which A10 belongs is 2, that is, N. 10 =2, the merge depth value corresponding to A10 Each intermediate sub-data sequence combination is used as an initial sub-data sequence. Based on the number of combinations, these initial sub-data sequences are combined to obtain multiple initial sub-data sequence combinations. A second round of merge sorting is then performed to obtain the intermediate sub-data sequence combinations: {A1, A2, A3, A4, A5, A6, A7, A8, A9} and {A10, A11}. At this point, for the first basic sub-data sequence A1 corresponding to the initial data sequence, the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which A1 belongs is 9, i.e., N1 = 9. The merge depth value corresponding to A1 is... For the 10th basic sub-data sequence A10 corresponding to the initial data sequence, the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which A10 belongs is 3, that is, N. 10 =3, the merge depth value corresponding to A10

[0071] In the above embodiments, based on the number of combinations corresponding to the initial data sequence and the number of intermediate sub-data sequences included in the current intermediate sub-data sequence combination, the merge depth value corresponding to each basic sub-data sequence included in the intermediate sub-data sequence combination can be quickly determined. Based on the merge depth value corresponding to each basic sub-data sequence, sorting can continue from the point of interruption after the sorting is interrupted, which can greatly improve the efficiency of data sorting.

[0072] In one embodiment, such as Figure 3 As shown, data sorting methods also include:

[0073] Step S302: When sorting is interrupted, record the merge depth value corresponding to each basic sub-data sequence at the current time.

[0074] Step S304: When sorting continues, the first basic sub-data sequence corresponding to the initial data sequence is used as the reference sub-data sequence.

[0075] Step S306: Based on the merge depth value corresponding to the reference sub-data sequence and the number of combinations corresponding to the initial data sequence, determine the number of reference ordered data corresponding to the reference sub-data sequence.

[0076] Step S308: Determine the combination of intermediate sub-data sequences corresponding to the reference sub-data sequence based on the reference ordered quantity, and obtain the target sub-data sequence combination.

[0077] Step S310: Take the next basic sub-data sequence corresponding to the target sub-data sequence combination as the reference sub-data sequence, return the step of determining the reference ordered number of the reference sub-data sequence based on the merge depth value corresponding to the reference sub-data sequence and the number of combinations corresponding to the initial data sequence, until all intermediate sub-data sequence combinations corresponding to the initial data sequence are obtained.

[0078] Step S312: Combine the intermediate sub-data sequences as the initial sub-data sequences, return to the step of combining each initial sub-data sequence, and continue until the termination condition is met to obtain the ordered data sequence corresponding to the initial data sequence.

[0079] The number of combinations refers to the preset number of combinations used to combine the initial sub-data sequences, indicating the number of initial sub-data sequences included in the combination of initial sub-data sequences.

[0080] The reference ordered number corresponding to the reference sub-data sequence refers to the number of basic sub-data sequences included in the intermediate sub-data sequence combination to which the reference sub-data sequence belongs.

[0081] For example, when sorting is interrupted, the computer device records the merge depth value corresponding to each basic sub-data sequence at the current time. When sorting continues, the first basic sub-data sequence in the initial data sequence is used as the reference sub-data sequence. The number of combinations corresponding to the initial data sequence is raised to the power of the merge depth value corresponding to the reference sub-data sequence to obtain the reference ordered number corresponding to the reference sub-data sequence. Based on the reference ordered number, each basic sub-data sequence belonging to the same intermediate sub-data sequence combination as the reference sub-data sequence is determined from each basic sub-data sequence corresponding to the initial data sequence, to obtain the intermediate sub-data sequence combination corresponding to the reference sub-data sequence. This intermediate sub-data sequence combination is used as the target sub-data sequence combination. The next basic sub-data sequence corresponding to the target sub-data sequence combination is used as the reference sub-data sequence. The step of raising the number of combinations corresponding to the initial data sequence to the power of the merge depth value corresponding to the reference sub-data sequence to obtain the reference ordered number corresponding to the reference sub-data sequence is repeated until all intermediate sub-data sequence combinations corresponding to the initial data sequence are obtained.

[0082] For example, if the initial data sequence corresponds to 11 basic sub-data sequences, A1-A11, and the number of combinations corresponding to the initial data sequence is 3, when sorting is interrupted, the merge depth values ​​corresponding to the basic sub-data sequences A1-A9 at the current moment are all 2, and the merge depth values ​​corresponding to the basic sub-data sequences A10-A11 are all 1. The current merge depth value corresponding to each basic sub-data sequence is recorded. When sorting continues, the first basic sub-data sequence A1 corresponding to the initial data sequence is taken as the reference sub-data sequence. An exponentiation operation is performed based on the merge depth value 2 corresponding to the reference sub-data sequence A1 and the number of combinations 3 corresponding to the initial data sequence to obtain the reference ordered number sortednum1, where sortednum1 = 3. 2 =9, then the target sub-data sequence combination composed of A1-A9 is the intermediate sub-data sequence combination corresponding to A1. Taking the next basic sub-data sequence A10 corresponding to the target sub-data sequence combination as the reference sub-data sequence, and performing an exponentiation operation based on the merge depth value 1 corresponding to the reference sub-data sequence A10 and the combination data 3 corresponding to the initial data sequence, we obtain the reference ordered number sortednum corresponding to the reference sub-data sequence. 10 sortednum 10 =3 1 =3. Since there are only two basic sub-data sequences remaining starting from A10, the target sub-data sequence combination composed of the remaining two basic sub-data sequences A10 and A11 is taken as the intermediate sub-data sequence combination corresponding to A10. At this time, all the intermediate sub-data sequence combinations corresponding to the initial data sequence are obtained.

[0083] Each intermediate sub-data sequence is used as an initial sub-data sequence. The process of combining the initial sub-data sequences is repeated until the termination condition is met, resulting in an ordered data sequence corresponding to the initial data sequence.

[0084] In one embodiment, the number of reference ordered sub-data sequences can be calculated using the following formula:

[0085]

[0086] Among them, sortednum i The reference ordered number is the number of references corresponding to the i-th basic sub-data sequence in the initial data sequence, z is the number of combinations corresponding to the initial data sequence, and depth is the number of references corresponding to the i-th basic sub-data sequence. i This is the merge depth value corresponding to the reference sub-data sequence.

[0087] In the above embodiments, when sorting is interrupted, the merge depth value corresponding to each basic sub-data sequence at the current time is recorded. When sorting continues, based on the merge depth value corresponding to each basic sub-data sequence, the combination of each intermediate sub-data sequence corresponding to the initial data sequence is determined. Then, each intermediate sub-data sequence is used as the initial sub-data sequence to continue sorting. This realizes the continuation of sorting from the interruption point without re-sorting, which greatly improves the efficiency of data sorting.

[0088] In one embodiment, the initial sub-data sequences in the same initial sub-data sequence combination are merged and sorted to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination, including:

[0089] The first unsorted data item corresponding to each initial sub-data sequence in the current initial sub-data sequence combination is taken as each candidate unsorted data item; the candidate unsorted data items are sorted to obtain a candidate data sequence; the first candidate data item in the candidate data sequence is written into the sorted data sequence, and the step of taking the first unsorted data item corresponding to each initial sub-data sequence in the current initial sub-data sequence combination as each candidate unsorted data item is returned to be executed until the merging is completed; the current initial sub-data sequence combination is updated based on the sorted data sequence to obtain the intermediate sub-data sequence combination corresponding to the current initial sub-data sequence combination.

[0090] Wherein, the current initial sub-data sequence combination refers to any one of the initial sub-data sequences corresponding to the initial data sequence. The first unsorted data refers to the first unsorted data in the initial sub-data sequence. The unsorted data refers to the data in the initial sub-data sequence that is to be sorted, that is, the data that has not been written into the sorted data sequence. The first candidate data refers to the first data in the candidate data sequence. The sorted data sequence refers to the data sequence obtained by merging and sorting the initial sub-data sequences in the current initial sub-data sequence combination. For example, if the current sub-data sequence combination includes two initial sub-data sequences, namely A1[4]={2,5,13,24} and A2[4]={1,4,7,12}, then the first unsorted data corresponding to A1 and A2 are 2 and 1 respectively. The candidate data sequence obtained at this time is {1,2}, and the first candidate data in the candidate data sequence is 1. After writing the first candidate data into the sorted data sequence, the unsorted data in A2 are 4,7 and 12, and the first unsorted data corresponding to A1 and A2 are 2 and 4 respectively.

[0091] For example, the computer device takes the first unsorted data item corresponding to each initial sub-data sequence in the current sub-data sequence combination as candidate unsorted data, sorts each candidate unsorted data item, and obtains a candidate data sequence. The first candidate data item in the candidate data sequence is written into the sorted data sequence corresponding to the current sub-data sequence combination. The candidate data written into the sorted data sequence is then treated as sorted data. The process returns to the step of taking the first unsorted data item corresponding to each initial sub-data sequence in the current sub-data sequence combination as candidate unsorted data, until the merging is complete, i.e., there is no unsorted data in any of the initial sub-data sequences. Based on the sorted data sequence, each basic sub-data sequence in the current initial sub-data sequence combination is updated to obtain an intermediate sub-data sequence combination corresponding to the initial sub-data sequence combination, composed of each merged basic sub-data sequence.

[0092] In the above embodiments, by sorting the first unsorted data corresponding to each initial sub-data sequence in the current initial sub-data sequence combination, a candidate data sequence is obtained. Then, the first unsorted data in the candidate data sequence is written into the already sorted data sequence. This ensures that during ascending sorting, each data written into the already sorted data sequence is the minimum value among all unsorted data included in the current initial sub-data sequence combination; and during descending sorting, each data written into the already sorted data sequence is the maximum value among all unsorted data included in the current initial sub-data sequence combination. This allows for rapid sorting of all unsorted data in the current sub-data sequence combination, obtaining the corresponding intermediate sub-data sequence combination, effectively improving the efficiency of data sorting.

[0093] In one embodiment, the initial sub-data sequences in the same initial sub-data sequence combination are merged and sorted to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination, including:

[0094] The initial sub-data sequences in different initial sub-data sequence combinations are merged and sorted in parallel to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination.

[0095] For example, in order to improve data sorting efficiency, after combining each initial sub-data sequence to obtain multiple initial sub-data sequence combinations, the computer device performs merge sorting on each initial sub-data sequence in different initial sub-data sequence combinations in parallel to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination.

[0096] In the above embodiments, by performing parallel merging and sorting on each initial sub-data sequence in different initial sub-data sequence combinations, the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination can be obtained quickly, which can effectively improve the efficiency of data sorting.

[0097] In one embodiment, the data sorting method further includes:

[0098] Obtain the supplementary data sequence and its corresponding sequence length, and obtain the segment length corresponding to the initial data sequence. When the sequence length is greater than the segment length, perform the same sorting process on the supplementary data sequence as on the initial data sequence to obtain the ordered data sequence corresponding to the supplementary data sequence. When the sequence length is less than or equal to the segment length, sort the supplementary data sequence to obtain the ordered data sequence corresponding to the supplementary data sequence. Merge the ordered data sequences corresponding to the initial data sequence and the supplementary data sequence to obtain the target data sequence.

[0099] The supplementary data sequence refers to the data sequence that needs to be added to the initial data sequence during the sorting process. Sequence length refers to the number of data points contained in the data sequence. Segment length refers to the length of the sequence used to divide the initial data sequence, indicating the length of each resulting data sequence. The target data sequence refers to the ordered data sequence obtained after sorting the data in the initial and supplementary data sequences.

[0100] For example, during the process of sorting the initial data sequence by the computer device, if a supplementary data sequence is added to the initial data sequence, for example, if a supplementary data sequence is written to the end of the initial data sequence, the computer device obtains the segment lengths corresponding to the supplementary data sequence and the initial data sequence, and determines the sequence length corresponding to the supplementary data sequence.

[0101] When the length of the supplementary data sequence is greater than the segment length, the supplementary data sequence is sorted in the same way as the initial data sequence based on the segment length. That is, the supplementary data sequence is divided into multiple basic sub-data sequences based on the segment length. Each basic sub-data sequence is used as an initial sub-data sequence. These initial sub-data sequences are then combined to obtain multiple combinations of initial sub-data sequences corresponding to the supplementary data queue. Merge sort is then performed on the initial sub-data sequences within the same initial sub-data sequence combination to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination. Each intermediate sub-data sequence combination is used as an initial sub-data sequence, and the step of combining the initial sub-data sequences is repeated until the termination condition is met, resulting in an ordered data sequence corresponding to the supplementary data sequence.

[0102] When the length of the supplementary data sequence is greater than the segment length, the supplementary data sequence is directly sorted to obtain the ordered data sequence corresponding to the supplementary data sequence.

[0103] Merge sorting is performed on the ordered data sequences corresponding to the initial and supplementary data sequences. Specifically, the first unsorted item in each of the ordered data sequences is used as a candidate unsorted item. The target data is then determined from these candidates; for example, when sorting the initial data sequence in ascending order, the minimum value among the candidate unsorted items is chosen as the target data, and when sorting in descending order, the maximum value is chosen. The target data is then written into the corresponding sorted data sequence. This process is repeated until the merge is complete. Finally, the basic sub-data sequences in the initial and supplementary data sequences are updated based on the sorted data sequences to obtain the target data sequence. For example, when the ordered data sequence corresponding to the initial data sequence is composed of the basic sub-data sequences A1[4]={1,2,4,5}, A2[4]={7,8,10,12} and A3[2]={13,24}, and the ordered data sequence corresponding to the supplementary data sequence is composed of the basic sub-data sequences A4[4]={3,6,9,11} and A5[2]={14,15}, the ordered data sequences corresponding to the initial data sequence and the supplementary data sequence will be merged and sorted to obtain the sorted data sequence {1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,24}, based on the sorted data sequence, update each basic sub-data sequence in the initial data sequence and the supplementary data sequence to obtain the target data sequence. The basic sub-data sequences included in the target data sequence are A1[4]={1,2,3,4}, A2[4]={5,6,7,8}, A3[2]={9,10}, A4[4]={11,12,13,14} and A[5]={15,24}, that is, the data from the 1st to the 16th position in the target sub-data sequence are 1-15 and 24 respectively.

[0104] In the above embodiments, if other data is added to the initial data sequence during the sorting process, the data sequence composed of the added data is taken as the supplementary data sequence. Based on the sequence length of the supplementary data sequence, the corresponding sorting method is used to sort the supplementary data sequence, resulting in an ordered data sequence corresponding to the supplementary data sequence. Then, the ordered data sequences corresponding to the initial data sequence and the supplementary data sequence are merged to obtain the target data sequence. This ensures that no re-sorting is required when supplementary data is added, greatly improving data sorting efficiency and guaranteeing real-time data sorting.

[0105] In one specific embodiment, the data sorting method of this application can be applied to a multidimensional database. Each piece of data in the multidimensional database is stored in a multidimensional array, meaning each piece of data contains information from multiple dimensions. The data in the multidimensional database is sorted according to the key values ​​corresponding to each piece of data. For example, ... Figure 4 As shown, each piece of data in the multidimensional database is stored in a 4-dimensional array. Each piece of data is a record, and each record includes information such as year, period, expense type, and key value. Taking an initial data sequence consisting of 4 records from the multidimensional database as an example, each record has a corresponding key value. If the initial data sequence is divided according to a segment length of 2, two basic sub-data segments are obtained. Based on the key values ​​corresponding to each record, the segments are first sorted to obtain internally ordered basic sub-data segments. Then, based on the key values ​​corresponding to each record, the two basic sub-data segments are merged and sorted to obtain the ordered data sequence corresponding to the initial data sequence. The data sorting method includes the following steps:

[0106] 1. Divide the initial data sequence

[0107] The computer device retrieves the initial data sequence and its corresponding segment length from a multidimensional database. Based on these segment lengths, it divides the initial data sequence into multiple basic sub-data segments (i.e., basic sub-data sequences). It initializes the depth variables (i.e., merge depth values) corresponding to each basic sub-data segment. Based on the keys corresponding to each data segment, it sorts each basic sub-data segment to obtain internally ordered basic sub-data segments, updates the depth variables corresponding to each basic sub-data segment, and uses each basic sub-data segment as the initial sub-data segment. For example, as... Figure 5 As shown, the initial data sequence is divided into 6 basic sub-data segments. The depth variables corresponding to each basic sub-data segment are initialized to -1. Then, each basic sub-data segment is sorted to form an internally ordered basic sub-data segment. The depth variables corresponding to each basic sub-data segment are updated to 0.

[0108] 2. Data sequence merging

[0109] The computer device uses each basic sub-data segment as an initial sub-data segment, combines these initial sub-data segments to obtain multiple initial sub-data segment combinations. The initial sub-data segments within the same initial sub-data segment combination are then merged and sorted in parallel to obtain multiple initial sub-data segment combinations.

[0110] The initial sub-data segments are combined to obtain multiple initial sub-data segment combinations. Based on the key values ​​corresponding to each data segment, the initial sub-data segments within the same initial sub-data segment combination are merged and sorted to obtain the intermediate sub-data segment combinations corresponding to each initial sub-data segment combination, and the depth variables corresponding to each basic sub-data segment are updated. For example, as shown... Figure 5 As shown, adjacent initial sub-data segments are combined to obtain three initial sub-data segment combinations. After merging and sorting the initial sub-data segments in the same initial sub-data segment combination, the depth variable corresponding to each basic sub-data segment is updated to 1.

[0111] When sorting stops, the depth variable corresponding to each basic sub-data segment is recorded. When sorting restarts, the ordered range corresponding to the basic sub-data segment is determined based on the depth variable, that is, the combination of intermediate sub-data segments to which the basic sub-data segment belongs is determined. The combination of each intermediate sub-data segment is used as the initial sub-data segment, and the step of combining each initial sub-data segment is returned to execute until the termination condition is met, resulting in the ordered data sequence corresponding to the initial data sequence.

[0112] When sorting proceeds normally, the intermediate sub-data segments are combined as the initial sub-data segments, and the step of combining the initial sub-data segments is returned to continue until the termination condition is met, resulting in the ordered data sequence corresponding to the initial data sequence.

[0113] In the above embodiments, since multidimensional databases typically contain a large number of records, reaching billions or even tens of billions, it is necessary to periodically reorder the records in the multidimensional database according to the key value to accelerate query performance. This is because when the records in the multidimensional database are ordered, binary search can be used to improve query performance; if the records are unordered, it is necessary to traverse and query from beginning to end. To address the scenario where large-scale data sorting takes too long, a new segmented structure is constructed, maintaining a depth variable for each data segment. Through parallel merging and breakpoint continuation sorting, the efficiency of data sorting is greatly improved, and the average time for large-scale data sorting is shortened. The depth variable implements a "memory function," meaning that sorting can continue from where it was interrupted. When the total number of records is too large, and a full sort takes too long, it can be stopped midway and then restarted.

[0114] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0115] Based on the same inventive concept, this application also provides a data sorting apparatus for implementing the data sorting method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data sorting apparatus embodiments provided below can be found in the limitations of the data sorting method described above, and will not be repeated here.

[0116] In one embodiment, such as Figure 6 As shown, a data sorting device is provided, including: a data sequence acquisition module 602, a data sequence combination module 604, a data sequence merging module 606, and an ordered sequence determination module 608, wherein:

[0117] The data sequence acquisition module 602 is used to acquire an initial data sequence and divide the initial data sequence into multiple basic sub-data sequences;

[0118] The data sequence combination module 604 is used to take each basic sub-data sequence as an initial sub-data sequence and combine the initial sub-data sequences to obtain multiple initial sub-data sequence combinations.

[0119] The data sequence merging module 606 is used to merge and sort the initial sub-data sequences in the same initial sub-data sequence combination to obtain the intermediate sub-data sequence combination corresponding to each initial sub-data sequence combination; the intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merging depth value; the merging depth value is used to continue sorting from the point of interruption after the sorting is interrupted.

[0120] The ordered sequence determination module 608 is used to combine intermediate sub-data sequences as initial sub-data sequences, return to the execution of the steps of combining each initial sub-data sequence until the termination condition is met, and obtain the ordered data sequence corresponding to the initial data sequence.

[0121] The aforementioned data sorting device combines the initial sub-data sequences corresponding to the initial data sequence to obtain multiple initial sub-data sequence combinations. It then performs merge sorting on each initial sub-data sequence in each of these combinations to obtain intermediate sub-data sequence combinations. The merge depth value of each merged base sub-data sequence in the intermediate sub-data sequence combinations is updated; this merge depth value is used to resume sorting from the point of interruption if the sorting process is interrupted. Furthermore, each intermediate sub-data sequence combination is used as an initial sub-data sequence, and the process of combining the initial sub-data sequences corresponding to the initial data sequence is repeated until the merging is complete, resulting in an ordered data sequence corresponding to the initial data sequence. In this way, by combining the initial sub-data sequences corresponding to the initial data sequence, performing merge sorting on each initial sub-data sequence combination to obtain ordered intermediate sub-data sequence combinations, and then using these intermediate sub-data sequence combinations as initial sub-data sequences, the process of combining the initial sub-data sequences is repeated until the merging is complete. Dividing the data sorting task for the initial data sequence into multiple parts, with each part performing merge sorting separately, effectively improves the efficiency of data sorting. Furthermore, based on the merge depth values ​​corresponding to each basic sub-data sequence, sorting can resume from the point of interruption after a sorting interruption, without needing to re-sort, thus significantly improving data sorting efficiency. In addition, improved data sorting efficiency effectively ensures the ordered nature of data in the database, thereby improving the efficiency and performance of subsequent data queries. This improvement is even more pronounced for large-scale data queries. This is because when the data in the database is ordered, there is no need to traverse the data; search algorithms can be used to improve query performance, such as binary search.

[0122] In one embodiment, the data sequence acquisition module 602 is further configured to:

[0123] Obtain the initial data sequence and the corresponding segment length; based on the segment length, divide the initial data sequence into multiple candidate sub-data sequences; sort each candidate sub-data sequence to obtain the basic sub-data sequences corresponding to the initial data sequence.

[0124] In one embodiment, the data sequence combination module 604 is further configured to:

[0125] Obtain the even-numbered sub-data sequences corresponding to each odd-numbered sub-data sequence in each initial sub-data sequence; the even-numbered sub-data sequence corresponding to the odd-numbered sub-data sequence is the next initial sub-data sequence corresponding to the odd-numbered sub-data sequence; when an odd-numbered sub-data sequence has a corresponding even-numbered sub-data sequence, combine the odd-numbered sub-data sequence and the corresponding even-numbered sub-data sequence to obtain the initial sub-data sequence combination; when an odd-numbered sub-data sequence does not have a corresponding even-numbered sub-data sequence, use the odd-numbered sub-data sequence as the initial sub-data sequence combination.

[0126] In one embodiment, the data sequence merging module 606 is further configured to:

[0127] The first unsorted data item corresponding to each initial sub-data sequence in the current initial sub-data sequence combination is taken as each candidate unsorted data item; the candidate unsorted data items are sorted to obtain a candidate data sequence; the first candidate data item in the candidate data sequence is written into the sorted data sequence, and the step of taking the first unsorted data item corresponding to each initial sub-data sequence in the current initial sub-data sequence combination as each candidate unsorted data item is returned to be executed until the merging is completed; the current initial sub-data sequence combination is updated based on the sorted data sequence to obtain the intermediate sub-data sequence combination corresponding to the current initial sub-data sequence combination.

[0128] In one embodiment, the data sequence merging module 606 is further configured to:

[0129] The initial sub-data sequences in different initial sub-data sequence combinations are merged and sorted in parallel to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination.

[0130] In one embodiment, such as Figure 7 As shown, the data sorting device also includes:

[0131] The depth value determination module 702 is used to obtain the number of combinations corresponding to the initial data sequence; the number of combinations is the number of initial sub-data sequences included in the combination of initial sub-data sequences; based on the number of combinations and the number of merged basic sub-data sequences included in the combination of intermediate sub-data sequences, the merging depth value corresponding to each merged basic sub-data sequence in the combination of intermediate sub-data sequences is determined.

[0132] In one embodiment, such as Figure 7 As shown, the data sorting device also includes:

[0133] The sorting module 704 is used to record the merge depth value of each basic sub-data sequence at the current time when the sorting is interrupted; when the sorting continues, the first basic sub-data sequence in the initial data sequence is used as the reference sub-data sequence; based on the merge depth value of the reference sub-data sequence and the number of combinations in the initial data sequence, the reference ordered number of the reference sub-data sequence is determined; based on the reference ordered number, the intermediate sub-data sequence combination corresponding to the reference sub-data sequence is determined to obtain the target sub-data sequence combination; the next basic sub-data sequence corresponding to the target sub-data sequence combination is used as the reference sub-data sequence, and the step of determining the reference ordered number of the reference sub-data sequence based on the merge depth value of the reference sub-data sequence and the number of combinations in the initial data sequence is returned, until all intermediate sub-data sequence combinations corresponding to the initial data sequence are obtained; the intermediate sub-data sequence combination is used as the initial sub-data sequence, and the step of combining each initial sub-data sequence is returned, until the termination condition is met to obtain the ordered data sequence corresponding to the initial data sequence.

[0134] In one embodiment, such as Figure 7 As shown, the data sorting device also includes:

[0135] The supplementary sequence sorting module 706 is used to obtain the supplementary data sequence and the corresponding sequence length, and to obtain the segment length corresponding to the initial data sequence. When the sequence length is greater than the segment length, the supplementary data sequence is sorted in the same way as the initial data sequence to obtain the ordered data sequence corresponding to the supplementary data sequence. When the sequence length is less than or equal to the segment length, the supplementary data sequence is sorted to obtain the ordered data sequence corresponding to the supplementary data sequence. The ordered data sequences corresponding to the initial data sequence and the supplementary data sequence are merged to obtain the target data sequence.

[0136] Each module in the aforementioned data sorting device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0137] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores merge depth values, ordered data sequences, and other data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When executed by the processor, the computer program implements a data sorting method.

[0138] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 9 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a data sorting method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.

[0139] Those skilled in the art will understand that Figure 8 , 9The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0140] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.

[0141] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.

[0142] In one embodiment, a computer program product or computer program is provided, the computer product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the steps in the above-described method embodiments.

[0143] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0144] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0145] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0146] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A data sorting method, characterized in that, The method includes: Obtain the initial data sequence from the database, and divide the initial data sequence into multiple basic sub-data sequences; If the data in the basic sub-data sequence is unordered, the basic sub-data sequence is sorted, and the sorted basic sub-data sequence is used as the initial sub-data sequence. If the data in the basic sub-data sequence is ordered, the basic sub-data sequence is used as the initial sub-data sequence, and adjacent initial sub-data sequences are combined according to a preset number to obtain multiple initial sub-data sequence combinations. Each initial sub-data sequence in the same initial sub-data sequence combination is merged and sorted to obtain intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination, and the merge depth value corresponding to the merged and sorted basic sub-data sequence is updated. The intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merge depth value. The merge depth value is used to determine the ordered range of each basic sub-data sequence based on the recorded depth value after the sorting process is interrupted and restarted, and to continue sorting from the point of interruption after the sorting is interrupted. The intermediate sub-data sequences are combined as the initial sub-data sequences. The steps of combining adjacent initial sub-data sequences according to a preset number are repeated until the termination condition is met, and the ordered data sequence corresponding to the initial data sequence is obtained. The ordered data sequence is written back to the database so that the records in the database are arranged in an orderly manner by key value, supporting the query operation of the database.

2. The method according to claim 1, characterized in that, The process of obtaining the initial data sequence of the database and dividing the initial data sequence into multiple basic sub-data sequences includes: Obtain the initial data sequence and the segment length corresponding to the initial data sequence; Based on the segment length, the initial data sequence is divided into multiple candidate sub-data sequences; Each candidate sub-data sequence is sorted to obtain the basic sub-data sequences corresponding to the initial data sequence.

3. The method according to claim 1, characterized in that, The step of combining the initial sub-data sequences to obtain multiple combinations of initial sub-data sequences includes: Obtain the even-numbered sub-data sequences corresponding to each odd-numbered sub-data sequence in each initial sub-data sequence; the even-numbered sub-data sequence corresponding to the odd-numbered sub-data sequence is the next initial sub-data sequence corresponding to the odd-numbered sub-data sequence. When an odd-numbered sub-data sequence has a corresponding even-numbered sub-data sequence, the odd-numbered sub-data sequence and the corresponding even-numbered sub-data sequence are combined to obtain the initial sub-data sequence combination. When there is no corresponding even-numbered sub-data sequence in the odd-numbered sub-data sequence, the odd-numbered sub-data sequence is used as the initial sub-data sequence combination.

4. The method according to claim 1, characterized in that, The method further includes: Obtain the number of combinations corresponding to the initial data sequence; the number of combinations is the number of initial sub-data sequences included in the combination of initial sub-data sequences; Based on the number of combinations and the number of merged basic sub-data sequences included in the intermediate sub-data sequence combination, the merging depth value corresponding to each merged basic sub-data sequence in the intermediate sub-data sequence combination is determined.

5. The method according to claim 1, characterized in that, The method further includes: When sorting is interrupted, record the merge depth value of each basic sub-data sequence at the current time. As the sorting continues, the first basic sub-data sequence corresponding to the initial data sequence is used as the reference sub-data sequence; Based on the merge depth value corresponding to the reference sub-data sequence and the number of combinations corresponding to the initial data sequence, the number of reference ordered sub-data sequences is determined. Based on the reference ordered quantity, determine the combination of intermediate sub-data sequences corresponding to the reference sub-data sequence to obtain the target sub-data sequence combination; The next basic sub-data sequence corresponding to the target sub-data sequence combination is used as the reference sub-data sequence. The step of determining the reference ordered number of the reference sub-data sequence based on the merge depth value corresponding to the reference sub-data sequence and the number of combinations corresponding to the initial data sequence is executed until all intermediate sub-data sequence combinations corresponding to the initial data sequence are obtained. The intermediate sub-data sequences are combined as the initial sub-data sequences, and the step of combining the initial sub-data sequences is returned to until the termination condition is met, resulting in an ordered data sequence corresponding to the initial data sequence.

6. The method according to claim 1, characterized in that, The step of merging and sorting the initial sub-data sequences in the same initial sub-data sequence combination to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination includes: The first item to be sorted in each of the initial sub-data sequences in the current combination of initial sub-data sequences is taken as each candidate data to be sorted. Sort each candidate unsorted data to obtain a candidate data sequence; Write the first candidate data in the candidate data sequence into the sorted data sequence, and return to the step of using the first unsorted data corresponding to each initial sub-data sequence in the current initial sub-data sequence combination as each candidate unsorted data, until the merging is completed; The current initial sub-data sequence combination is updated based on the sorted data sequence to obtain the intermediate sub-data sequence combination corresponding to the current initial sub-data sequence combination.

7. The method according to claim 1, characterized in that, The step of merging and sorting the initial sub-data sequences in the same initial sub-data sequence combination to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination includes: The initial sub-data sequences in different initial sub-data sequence combinations are merged and sorted in parallel to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination.

8. The method according to claim 1, characterized in that, The method further includes: Obtain the supplementary data sequence and the sequence length corresponding to the supplementary data sequence, and obtain the segment length corresponding to the initial data sequence; When the sequence length is greater than the segment length, the supplementary data sequence is sorted in the same way as the initial data sequence to obtain the ordered data sequence corresponding to the supplementary data sequence. When the sequence length is less than or equal to the segment length, the supplementary data sequence is sorted to obtain the ordered data sequence corresponding to the supplementary data sequence. The ordered data sequences corresponding to the initial data sequence and the supplementary data sequence are merged to obtain the target data sequence.

9. A data sorting device, characterized in that, The device includes: The data sequence acquisition module is used to acquire the initial data sequence of the database and divide the initial data sequence into multiple basic sub-data sequences; The data sequence combination module is used to sort the basic sub-data sequence if the data in the basic sub-data sequence is unordered, and use the sorted basic sub-data sequence as the initial sub-data sequence; if the data in the basic sub-data sequence is ordered, use the basic sub-data sequence as the initial sub-data sequence, and combine adjacent initial sub-data sequences according to a preset number to obtain multiple initial sub-data sequence combinations. The data sequence merging module is used to merge and sort the initial sub-data sequences in the same initial sub-data sequence combination to obtain the intermediate sub-data sequence combinations corresponding to each initial sub-data sequence combination, and update the merge depth value corresponding to the merged and sorted basic sub-data sequences. The intermediate sub-data sequence combination includes multiple merged basic sub-data sequences, and each merged basic sub-data sequence has a corresponding merge depth value. The merge depth value is used to determine the ordered range of each basic sub-data sequence based on the recorded depth value after the sorting process is interrupted and restarted, and to continue sorting from the point of interruption after the sorting is interrupted. The ordered sequence determination module is used to combine intermediate sub-data sequences as initial sub-data sequences, return the steps of combining adjacent initial sub-data sequences according to a preset number until the termination condition is met, obtain the ordered data sequence corresponding to the initial data sequence, and write the ordered data sequence back to the database so that the records in the database are arranged in an orderly manner by key value and support the query operation of the database.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.