OpenGauss database sorting optimization method

By Normalize the different types of data in the openGauss database, and sorting them using the memcmp function of the standard C library and the low-time complexity sorting algorithm, the problem that the traditional sorting framework is not suitable for the current CPU architecture is solved, and the sorting performance of the database is significantly improved.

CN120011346APending Publication Date: 2025-05-16广州海量数据库技术有限公司
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510225140.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-27
Publication Date
2025-05-16

AI Technical Summary

Technical Problem

The traditional database sorting framework is not suitable for the current CPU architecture, and it is impossible to use algorithms with lower time complexity, resulting in low sorting performance.

Method used

An optimization method for openGauss database sorting is proposed, which normalizes different types of data to make their length fixed, and then sorts using the memcmp function of the standard C library and low-time complexity sorting algorithms (such as quicksort, heapsort, etc.).

Benefits of technology

It significantly improves the data sorting performance of openGauss database, improves data access performance and sorting efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120011346A_ABST
    Figure CN120011346A_ABST
Patent Text Reader

Abstract

The invention relates to an optimization method for sorting an openGauss database. The method comprises the following steps of: acquiring various different types of data such as int, float, numeric, varlar and the like from a data source, carrying out Normalization processing on the acquired data, and then putting the data subjected to Normalization processing into a sorting space; sorting and comparing the data in the sorting space by using a memcmp function of a standard C library, and exchanging Normalize data participating in comparison according to a comparison result; and orderly data are directly obtained from the sorting space in sequence. According to the method, the data is directly sorted instead of being indexed through rowid, so that the data access performance and sorting efficiency of the openGauss database can be remarkably improved. According to the method, the data are all subjected to Normalization, and the data length is a fixed value, so that a sorting algorithm with lower time complexity can be used.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of database sorting methods, and in particular relates to an optimization method for sorting an openGauss database. Background Art

[0002] Sorting is a basic operation for data calculation in database systems. Almost all SQL statements involve data sorting. Sorted data is more conducive to analysis, so the quality of sorting performance has a crucial impact on the execution performance of the database.

[0003] Sorting in a database is the process of sorting data in one or more columns of a table according to specified sorting rules. The sorting process needs to consider data type, data value status, sorting direction, column priority, regional comparison rules and other conditions to maximize the speed of data processing under limited resources.

[0004] Traditional sorting algorithms generally use quick sorting algorithms, such as Figure 1 As shown in the figure, variable-length data is put into a sorting space, indexed by a rowid, and then compared and exchanged (exchanged rowid of data). After sorting, the data is read by rowid. However, the traditional sorting framework is no longer suitable for the current CPU architecture, and it is impossible to use an algorithm with lower time complexity (compared with the quick sort algorithm). Therefore, it is necessary to develop a new sorting framework that is more efficient than the traditional sorting framework to improve the execution efficiency of the sorting process. Summary of the invention

[0005] In order to overcome the defects that the traditional sorting framework is not suitable for the current CPU architecture and cannot use algorithms with lower time complexity, and to further improve the execution efficiency of the sorting process, the present invention proposes a new openGauss database sorting optimization method, which can significantly improve the data sorting performance of the openGauss database.

[0006] It should be noted that in the description of the present invention, only the process of data sorting is involved, without discussing what the data source is and where the data is used after being sorted, and the present invention assumes that the resources of the environment are sufficient.

[0007] Specifically, the present invention provides an optimization method for sorting an openGauss database, such as Figure 7 As shown, the method comprises the following steps: S1. Obtain different types of data from the data source, normalize the obtained data, and then put the normalized data into the sorting space; S2. Use the memcmp function of the standard C library to sort and compare the data in the sorting space, and exchange the Normalized data involved in the comparison according to the comparison results; S3. Get the ordered data directly from the sorted space in order.

[0008] Furthermore, the different types of data described in step S1 of the openGauss database sorting optimization method of the present invention include, but are not limited to: int type, float type, numeric type, and varchar type.

[0009] Furthermore, in the optimization method for sorting the openGauss database of the present invention, for int type data, the normalization of the int type data is achieved by exchanging the contents of the high and low bytes of the int type and flipping the highest bit.

[0010] Furthermore, in the optimization method for sorting the openGauss database of the present invention, for float type data, normalization of the float type data is achieved by flipping each bit and the sign bit.

[0011] Furthermore, in the optimization method for sorting the openGauss database of the present invention, for numeric type data, normalization of the numeric type data is achieved by multiplying the data in digits with a multiplier.

[0012] Furthermore, in the step S2 of the openGauss database sorting optimization method of the present invention, the data in the sorting space are sorted and compared, and the sorting algorithms used include but are not limited to: quicksort algorithm, heapsort algorithm, insertsort algorithm, radixsort algorithm, mergesort algorithm.

[0013] On the other hand, the present invention also provides an openGauss database sorting optimization system, which implements the steps of the openGauss database sorting optimization method mentioned above when the system is running.

[0014] In addition, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the steps of the above-mentioned openGauss database sorting optimization method are implemented.

[0015] In summary, the optimization method for sorting the openGauss database of the present invention has the following advantages: (1) The method of the present invention directly sorts data instead of indexing data by rowid, thus significantly improving data access performance and sorting efficiency.

[0016] (2) The data in the method of the present invention are all normalized and the data length is a fixed value, so a sorting algorithm with lower time complexity can be used. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the background technology and the technical solution of the present invention, the following briefly introduces the drawings required for use in the description of the background technology and the embodiments of the present invention. Obviously, the following drawings are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.

[0018] Figure 1 Schematic diagram of the implementation of the traditional sorting algorithm.

[0019] Figure 2 Schematic diagram of the Normalize method for int type data in the method of the present invention.

[0020] Figure 3 Schematic diagram of the Normalize method for float type data in the method of the present invention.

[0021] Figure 4 It is a schematic diagram of the Normalize method of numeric type data in the method of the present invention.

[0022] Figure 5 This is an example diagram of the operation of putting the Normalized data into the sorting space sortline in the method of the present invention.

[0023] Figure 6 It is a performance parameter diagram of various sorting algorithms used in the method of the present invention.

[0024] Figure 7 The figure is a flow chart of the overall implementation of the method of the present invention. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. The present invention can also be implemented or applied through other different specific implementation methods. The details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.

[0026] At the same time, it should be understood that the protection scope of the present invention is not limited to the specific embodiments described below; it should also be understood that the terms used in the embodiments of the present invention are for describing specific embodiments rather than for limiting the protection scope of the present invention.

[0027] Embodiment: A method for optimizing sorting of openGauss database The implementation of the present invention consists of three steps: Step 1: Get data from the data source and put it into the sorting space.

[0028] Step 2: Sort the data in the sorting space.

[0029] Step 3: Get ordered data from the sorting space.

[0030] (I) Obtain data from the data source and put it into the sorting space The process of putting different types of data into the sort space is called data normalization. Different types of data have different normalization methods. Common types include int type, float type, numeric type, varchar type, and other types are not listed one by one.

[0031] (1) int type like Figure 2 As shown, for int type data, Normalize the int type data by exchanging the contents of the high and low bytes of the int type and flipping the highest bit.

[0032] (2) float type like Figure 3 As shown, for float type data, normalization of float type data is achieved by flipping each bit and the sign bit.

[0033] (3) Numeric type like Figure 4 As shown, for numeric type data, the normalization of numeric type data is achieved by multiplying the data in digits by the multiplier.

[0034] (4) varchar type The data characters of the varchar type meet the Normalize requirements and do not require special processing.

[0035] (II) Sorting the data in the sorting space like Figure 5As shown, the Normalized data is put into the sorting space sortline.

[0036] The data in the sorting space is sorted and compared using the memcmp function of the standard C library, and the Normalized data involved in the comparison is exchanged according to the comparison result.

[0037] Since the data put into the sorting space is normalized, the data is of fixed length. For fixed-length data, you can use a sorting algorithm with lower time complexity, such as quicksort, heapsort, insertsort, radixsort, mergesort, etc. The performance parameters of each algorithm are as follows: Figure 6 shown.

[0038] (III) Obtaining ordered data from the sorting space Since the data is directly sorted, there is no rowid logic in traditional sorting, and the data can be directly obtained in order from the sorting space.

[0039] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Any technician familiar with the profession can make some changes or modifications to the technical contents disclosed above without departing from the scope of the technical solution of the present invention to obtain equivalent embodiments of equivalent changes. However, any simple modification, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. An optimization method for sorting an openGauss database, characterized in that: The method comprises: S1. Obtain different types of data from the data source, normalize the obtained data, and then put the normalized data into the sorting space; S2. Use the memcmp function of the standard C library to sort and compare the data in the sorting space, and exchange the Normalized data involved in the comparison according to the comparison results; S3. Get the ordered data directly from the sorted space in order.

2. The openGauss database sorting optimization method according to claim 1, characterized in that: The different types of data described in step S1 include: int type, float type, numeric type, and varchar type.

3. The openGauss database sorting optimization method according to claim 2, characterized in that: For int type data, Normalize the int type data by swapping the contents of the high and low bytes of the int type and flipping the highest bit.

4. The openGauss database sorting optimization method according to claim 2, characterized in that: For float type data, normalize the float type data by flipping each bit and the sign bit.

5. The openGauss database sorting optimization method according to claim 2, characterized in that: For numeric data, normalize the numeric data by multiplying the data in digits by the multiplier.

6. The openGauss database sorting optimization method according to claim 1, characterized in that: The sorting and comparison of the data in the sorting space described in step S2 uses the following sorting algorithms: quicksort algorithm, heapsort algorithm, insertsort algorithm, radixsort algorithm, mergesort algorithm.

7. An openGauss database sorting optimization system, characterized in that: When the system is running, the steps of the openGauss database sorting optimization method described in any one of claims 1 to 6 are implemented.

8. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the program implements the steps of the openGauss database sorting optimization method according to any one of claims 1 to 6.

Citation Information

Cited By

  • OpenGauss database single-column sorting performance optimization method and system

    CN120950540A

  • Method, system and equipment for preventing double writing under open of openGauss maximum available mode

    CN121117102A