A data query method and device

By receiving data query statements during database hardware acceleration, acquiring and amplifying target computation data for calculation, the problem of calculation errors of floating-point and fixed-point numbers during database hardware acceleration is solved, achieving high-precision calculation and accurate results.

CN115617836BActive Publication Date: 2026-06-26GUANGDONG INST OF ARTIFICIAL INTELLIGENCE & ADVANCED COMPUTING

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GUANGDONG INST OF ARTIFICIAL INTELLIGENCE & ADVANCED COMPUTING
Filing Date
2022-11-04
Publication Date
2026-06-26

Smart Images

  • Figure CN115617836B_ABST
    Figure CN115617836B_ABST
Patent Text Reader

Abstract

The application provides a data query method and device, the method comprises the following steps: receiving a data query statement; obtaining target operation data required to be executed in this query according to the data query statement; performing data amplification processing on the target operation data to obtain to-be-processed operation data; performing operation processing on the to-be-processed operation data to obtain an operation result; determining a query result of the data query statement according to the operation result; and outputting the query result. It can be seen that, by implementing this embodiment, high-precision operation can be better performed in the database hardware acceleration process, so that the calculation result is more accurate.
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 more specifically, to a data query method and apparatus. Background Technology

[0002] Currently, general-purpose computers typically use floating-point or fixed-point numbers for decimal calculations. However, floating-point numbers cannot accurately represent most decimal fractions, leading to the accumulation of unavoidable calculation errors and resulting in inaccurate results. On the other hand, fixed-point decimals have a very limited representable range, which restricts the accuracy of calculations performed using them. Therefore, neither of these methods is suitable for database hardware acceleration. Consequently, how to better perform high-precision calculations and achieve more accurate results during database hardware acceleration has become a pressing issue for engineers. Summary of the Invention

[0003] The purpose of this application is to provide a data query method and apparatus that can perform high-precision calculations better during database hardware acceleration, thereby making the calculation results more accurate.

[0004] The first aspect of this application provides a data query method, including:

[0005] Receive data query statements;

[0006] The target computation data to be performed in this query is obtained based on the data query statement.

[0007] The target computation data is amplified to obtain the computation data to be processed;

[0008] The data to be processed is used to perform calculations to obtain the calculation results;

[0009] The query result of the data query statement is determined based on the calculation result;

[0010] Output the query results.

[0011] In the above implementation process, this method can first receive a data query statement; then, obtain the target operation data to be performed in this query based on the data query statement; then, perform data amplification processing on the target operation data to obtain the operation data to be processed; then, perform operation processing using the operation data to obtain the operation result; then, determine the query result of the data query statement based on the operation result; finally, output the query result. It is evident that this method can better perform high-precision calculations during database hardware acceleration, thus making its calculation results more accurate.

[0012] Further, obtaining the target computation data to be performed in this query based on the data query statement includes:

[0013] Obtain the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan;

[0014] Extract the target operation data to be performed in this query based on the stated structure.

[0015] Furthermore, the method also includes:

[0016] Based on the data type defined in the preset data table and the target operation data, determine the upper and lower limits of the numerical calculation for this query;

[0017] Based on the preset numerical types supported by the acceleration hardware and the upper and lower limits of the numerical calculation, it is determined whether scaling the target computational data will cause an overflow.

[0018] If not, then perform the data amplification process on the target computational data to obtain the computational data to be processed.

[0019] Further, the step of amplifying the target computational data to obtain the computational data to be processed includes:

[0020] Determine whether the magnitude of the pure integer amplification of the target computational data exceeds a preset integer range;

[0021] If not, the target computational data is amplified to a pure integer to obtain the computational data to be processed.

[0022] Furthermore, the method also includes:

[0023] When it is determined that the magnitude of the pure integer amplification of the target operation data exceeds the preset integer range, the target operation data is converted into a floating-point number to obtain the operation data to be processed.

[0024] Further, determining the query result of the data query statement based on the calculation result includes:

[0025] Obtain the restoration coefficient of the calculation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data is converted to a floating-point number;

[0026] The calculation result is restored according to the restoration coefficient to obtain the restored calculation result;

[0027] The query result of the data query statement is determined based on the restored calculation result.

[0028] A second aspect of this application provides a data query device, the data query device comprising:

[0029] The receiving unit is used to receive data query statements;

[0030] The acquisition unit is used to acquire the target operation data to be performed in this query according to the data query statement;

[0031] The processing unit is used to perform data amplification processing on the target computational data to obtain computational data to be processed;

[0032] The arithmetic unit is used to perform arithmetic processing on the data to be processed and obtain the calculation result;

[0033] A query result determination unit is used to determine the query result of the data query statement based on the calculation result;

[0034] The output unit is used to output the query results.

[0035] In the above implementation process, the device can receive a data query statement through a receiving unit; obtain the target operation data to be performed in this query through an acquisition unit; amplify the target operation data through a processing unit to obtain operation data to be processed; perform operation processing using the operation data to be processed through a calculation unit to obtain the operation result; determine the query result of the data query statement through a query result determination unit; and output the query result through an output unit. It is evident that this device can perform high-precision calculations better during database hardware acceleration, thereby making its calculation results more accurate.

[0036] Furthermore, the acquisition unit includes:

[0037] The structure acquisition subunit is used to acquire the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan;

[0038] Extraction sub-units are used to extract the target operation data to be performed in this query based on the statement structure.

[0039] Furthermore, the data query device also includes:

[0040] The numerical limit determination unit is used to determine the upper and lower limits of the numerical calculation for this query based on the data type in the preset data table definition and the target operation data;

[0041] The judgment unit is used to determine whether scaling the target operation data will cause overflow based on the preset numerical type supported by the acceleration hardware and the upper and lower limits of the numerical calculation.

[0042] The processing unit is specifically used to perform data amplification processing on the target computation data to obtain the computation data to be processed, when scaling the target computation data will not cause overflow.

[0043] Furthermore, the processing unit includes:

[0044] The judgment subunit is used to determine whether the magnitude of the pure integer amplification of the target operation data exceeds a preset integer range.

[0045] The processing subunit is used to amplify the target computation data into a pure integer to obtain the computation data to be processed, when the magnitude of the pure integer amplification of the target computation data does not exceed a preset integer range.

[0046] Furthermore, the processing subunit is also configured to convert the target computation data into a floating-point number to obtain the computation data to be processed when the magnitude of the pure integer amplification of the target computation data exceeds the preset integer range.

[0047] Furthermore, the query result determination unit includes:

[0048] A coefficient acquisition subunit is used to acquire the restoration coefficient of the operation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data to be processed is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data to be processed is converted to a floating-point number;

[0049] The reduction subunit is used to perform reduction processing on the calculation result according to the reduction coefficient to obtain the reduced calculation result;

[0050] A subunit is defined for determining the query result of the data query statement based on the restored calculation result.

[0051] A third aspect of this application provides an electronic device, including a memory and a processor. The memory stores a computer program, and the processor runs the computer program to cause the electronic device to perform the data query method described in any one of the first aspects of this application.

[0052] A fourth aspect of this application provides a computer-readable storage medium storing computer program instructions, which, when read and executed by a processor, perform the data query method described in any one of the first aspects of this application. Attached Figure Description

[0053] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0054] Figure 1 A flowchart illustrating a data query method provided in an embodiment of this application;

[0055] Figure 2 This is a schematic diagram of the structure of a data query device provided in an embodiment of this application;

[0056] Figure 3 This is a schematic diagram of a numerical conversion provided in an embodiment of this application. Detailed Implementation

[0057] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0058] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0059] Example 1

[0060] Please refer to Figure 1 , Figure 1 This embodiment provides a flowchart illustrating a data query method. The data query method includes:

[0061] S101, Receive data query statement.

[0062] S102. Obtain the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan.

[0063] S103. Extract the target number of operations to be performed in this query based on the statement structure.

[0064] S104. Determine the upper and lower limits of the numerical calculation for this query based on the data type and target operation data in the preset data table definition.

[0065] S105. Determine whether scaling the target computation data will cause an overflow based on the preset numerical types and upper and lower limits of numerical calculation supported by the acceleration hardware. If yes, end this process; otherwise, proceed to step S106.

[0066] In this embodiment, the method can determine the computational scale based on the operations to be performed. In a database, the numerical operations in the query process mainly involve aggregation operations in the query statement. The operations required for this query can be obtained through the syntax tree, query plan, and other structures of the query statement. Combined with the data types in the data table definition, the upper and lower limits of the numerical calculations for this query can be obtained. The method also determines whether appropriately scaling up or down the data will lead to overflow based on the numerical types supported by the acceleration hardware. For example, in financial queries, monetary values ​​are typically represented by two decimal places, while 64-bit signed integers can represent up to 100000000000000000000, with a maximum representation scale of over quadrillions. Generally, it is safe to scale the value up to 100 times.

[0067] S106. Determine whether the magnitude of the pure integer amplification of the target operation data exceeds the preset integer range. If yes, execute steps S108 to S113; otherwise, execute steps S107 and S109 to S113.

[0068] S107. Magnify the target operation data into pure integers to obtain the operation data to be processed.

[0069] S108. Convert the target operation data into floating-point numbers to obtain the operation data to be processed.

[0070] S109. Perform calculations on the data to be processed to obtain the calculation results.

[0071] S110. Obtain the restoration coefficient of the calculation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data is converted to a floating-point number.

[0072] S111. Perform restoration processing on the calculation results according to the restoration coefficients to obtain the restored calculation results.

[0073] S112. Determine the query result of the data query statement based on the restored calculation result.

[0074] S113. Output the query results.

[0075] In this embodiment, the method can safely amplify all obtained values ​​to pure integers. Operations are performed using pure integers; when the value exceeds the integer range, it is converted to a floating-point number for subsequent operations: according to the floating-point format, bitwise operations are used to convert the precise value to the corresponding floating-point number. For example, IEEE 754 32-bit normalized decimals are used. Figure 3 The results before and after the numerical conversion are shown.

[0076] In this embodiment, when the method amplifies the value to an integer, the amplification factor must be a power of 10, i.e., 10. C Record the magnification count C, where C is the magnification factor as a power of 10. During the numerical calculations, adjust the scaling factor of the final result according to the mathematical rules of different operations. For example, addition and subtraction do not change the magnification count (e.g., when C=1, 1.2+3.4=(12+34) / 10^1); multiplication requires adding 1 to the magnification count (e.g., when C=1, (1.2×3.4)=(12×34) / 10^(1+1)).

[0077] When encountering operations that may produce decimals of arbitrary digits (e.g., division with an indefinite divisor or dividend), this method uses software to convert intermediate results into floating-point numbers for subsequent calculations. The conversion process is the same as described above. It's important to note that the converted floating-point value is an amplified value. To restore the floating-point number to its original value, divide by 10. C Because floating-point division can produce significant errors, the value is only restored when the final result is obtained. The amplification counter C also needs to be adjusted according to the operation during floating-point calculations.

[0078] In this embodiment, when no floating-point conversion occurs during the calculation process, the obtained value is an amplified and precise value. The accurate result value can be obtained based on the value size and the amplification count.

[0079] In this embodiment, when a floating-point conversion occurs during the calculation process, the resulting value is an amplified floating-point number, which needs to be restored based on the number of scaling operations.

[0080] In this embodiment, the subject executing the method can be a computing device such as a computer or server, and no limitation is made in this embodiment.

[0081] In this embodiment, the subject executing the method can also be a smart device such as a smartphone or tablet, and no limitation is made in this embodiment.

[0082] As can be seen, implementing the data query method described in this embodiment enables better high-precision calculations during database hardware acceleration, thereby making the calculation results more accurate.

[0083] Example 2

[0084] Please refer to Figure 2 , Figure 2 This is a schematic diagram of the structure of a data query device provided in this embodiment. Figure 2 As shown, the data query device includes:

[0085] The receiving unit 210 is used to receive data query statements;

[0086] Acquisition unit 220 is used to obtain the target operation data to be performed in this query based on the data query statement;

[0087] Processing unit 230 is used to amplify the target computation data to obtain the computation data to be processed;

[0088] The arithmetic unit 240 is used to perform arithmetic operations on the data to be processed and obtain the results.

[0089] The query result determination unit 250 is used to determine the query result of the data query statement based on the calculation result;

[0090] Output unit 260 is used to output the query results.

[0091] As an optional implementation, the acquisition unit 220 includes:

[0092] The structure acquisition subunit 221 is used to acquire the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan;

[0093] Extraction subunit 222 is used to extract the target operation data to be performed in this query based on the statement structure.

[0094] As an optional implementation, the data query device further includes:

[0095] The numerical limit determination unit 270 is used to determine the upper and lower limits of the numerical calculation for this query based on the data type and target operation data in the preset data table definition.

[0096] The judgment unit 280 is used to determine whether scaling the target operation data will cause overflow based on the preset numerical types and numerical calculation upper and lower limits supported by the acceleration hardware.

[0097] The processing unit 230 is specifically used to perform data amplification processing on the target computation data to obtain the computation data to be processed, when scaling the target computation data will not cause overflow.

[0098] As an optional implementation, the processing unit 230 includes:

[0099] Judgment subunit 231 is used to determine whether the magnitude of the pure integer amplification of the target operation data exceeds the preset integer range;

[0100] The processing subunit 232 is used to amplify the target operation data into a pure integer when the magnitude of the pure integer amplification of the target operation data does not exceed the preset integer range, so as to obtain the operation data to be processed.

[0101] As an optional implementation, the processing subunit 232 is also used to convert the target operation data into a floating-point number to obtain the operation data to be processed when the magnitude of the pure integer amplification of the target operation data exceeds a preset integer range.

[0102] As an optional implementation, the query result determination unit 250 includes:

[0103] The coefficient acquisition subunit 251 is used to acquire the restoration coefficients of the calculation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data to be processed is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data to be processed is converted to a floating-point number.

[0104] The reduction subunit 252 is used to perform reduction processing on the calculation result according to the reduction coefficient to obtain the reduced calculation result;

[0105] Determine subunit 253, which is used to determine the query result of the data query statement based on the restored calculation result.

[0106] In this embodiment, the explanation of the data query device can be referred to the description in Embodiment 1, and will not be repeated here.

[0107] As can be seen, implementing the data query device described in this embodiment can better perform high-precision calculations during database hardware acceleration, thereby making the calculation results more accurate.

[0108] This application provides an electronic device, including a memory and a processor. The memory stores a computer program, and the processor runs the computer program to enable the electronic device to perform the data query method in embodiment 1 of this application.

[0109] This application provides a computer-readable storage medium storing computer program instructions, which are read and executed by a processor to perform the data query method in embodiment 1 of this application.

[0110] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0111] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0112] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0113] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0114] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0115] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A data query method, characterized in that, include: Receive data query statements; The target computation data to be performed in this query is obtained based on the data query statement. The target computation data is amplified to obtain the computation data to be processed; When the magnitude of the target operation data after pure integer amplification does not exceed the preset integer range, the operation data to be processed is used for pure integer arithmetic to obtain the operation result; or when the magnitude of the target operation data after pure integer amplification exceeds the preset integer range, the operation data to be processed is used for floating-point arithmetic to obtain the operation result. The query result of the data query statement is determined based on the calculation result; Output the query results; The method further includes: Based on the data type defined in the preset data table and the target operation data, determine the upper and lower limits of the numerical calculation for this query; Based on the preset numerical types supported by the acceleration hardware and the upper and lower limits of the numerical calculation, it is determined whether scaling the target computational data will cause an overflow; wherein, the acceleration hardware is the database acceleration hardware; If not, then perform the data amplification process on the target computational data to obtain the computational data to be processed; The step of determining the query result of the data query statement based on the calculation result includes: Obtain the restoration coefficient of the calculation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data is converted to a floating-point number; The calculation result is restored according to the restoration coefficient to obtain the restored calculation result; The query result of the data query statement is determined based on the restored calculation result.

2. The data query method according to claim 1, characterized in that, The step of obtaining the target operation data to be performed in this query based on the data query statement includes: Obtain the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan; Extract the target computation data to be performed in this query based on the stated structure.

3. The data query method according to claim 1, characterized in that, The step of amplifying the target computational data to obtain the computational data to be processed includes: Determine whether the magnitude of the pure integer amplification of the target computational data exceeds a preset integer range; If not, the target computational data is amplified to a pure integer to obtain the computational data to be processed.

4. The data query method according to claim 3, characterized in that, The method further includes: When it is determined that the magnitude of the pure integer amplification of the target operation data exceeds the preset integer range, the target operation data is converted into a floating-point number to obtain the operation data to be processed.

5. A data query device, characterized in that, The data query device includes: The receiving unit is used to receive data query statements; The acquisition unit is used to acquire the target operation data to be performed in this query according to the data query statement; The processing unit is used to perform data amplification processing on the target computational data to obtain computational data to be processed; The arithmetic unit is configured to perform pure integer arithmetic on the target arithmetic data to obtain a result when the magnitude of the pure integer amplification of the target arithmetic data does not exceed a preset integer range; or to perform floating-point arithmetic on the target arithmetic data to obtain a result when the magnitude of the pure integer amplification of the target arithmetic data exceeds the preset integer range. A query result determination unit is used to determine the query result of the data query statement based on the calculation result; Output unit, used to output the query results; The data query device further includes: The numerical limit determination unit is used to determine the upper and lower limits of the numerical calculation for this query based on the data type in the preset data table definition and the target operation data; The judgment unit is used to determine whether scaling the target operation data will cause an overflow based on the preset numerical type supported by the acceleration hardware and the upper and lower limits of the numerical calculation; wherein, the acceleration hardware is the database acceleration hardware; The processing unit is specifically used to perform data amplification processing on the target computation data to obtain the computation data to be processed when scaling the target computation data will not cause overflow. The query result determination unit includes: A coefficient acquisition subunit is used to acquire the restoration coefficient of the operation result; wherein, when the data to be processed is a pure integer, the restoration coefficient is the magnification factor when the target data to be processed is magnified to a pure integer; when the data to be processed is a floating-point number, the restoration coefficient is the scaling factor when the target data to be processed is converted to a floating-point number; The reduction subunit is used to perform reduction processing on the calculation result according to the reduction coefficient to obtain the reduced calculation result; A subunit is defined for determining the query result of the data query statement based on the restored calculation result.

6. The data query device according to claim 5, characterized in that, The acquisition unit includes: The structure acquisition subunit is used to acquire the statement structure of the data query statement, wherein the statement structure includes at least a syntax tree and / or a query plan; Extraction sub-units are used to extract the target operation data to be performed in this query based on the statement structure.

7. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory being used to store a computer program, and the processor running the computer program to cause the electronic device to perform the data query method according to any one of claims 1 to 4.

8. A readable storage medium, characterized in that, The readable storage medium stores computer program instructions, which, when read and executed by a processor, perform the data query method according to any one of claims 1 to 4.