Database operation statement processing method and related product

By pre-designing the number table in the database to record the addition and deletion operations of the data table, and converting the counting statement to the sum statement to query the number table, the problem of inefficient single table counting operation is solved, the fast counting function is realized, and the query efficiency is significantly improved.

CN119917544APending Publication Date: 2025-05-02CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411981498.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

In existing database technology, for counting a single table such as count(*), a full table scan is usually required, resulting in inefficient query, especially when the data volume is large.

Method used

By pre-designing a number table (pre-designed number table) in the database, it is used to record the data row addition and deletion operations corresponding to the data table with the fast counting function enabled. For the target count statement, the converted to the target sum statement is queried in the predesigned number table to obtain the count record, and the total number of records obtained in the target data table is calculated.

Benefits of technology

Converting the full table scan of a table to an index scan of a specified table greatly shortens the query time, especially in large-scale data scenarios, with significant efficiency improvement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917544A_ABST
    Figure CN119917544A_ABST
Patent Text Reader

Abstract

The invention provides a database operation statement processing method and a related product. The method comprises the following steps: acquiring a database operation statement; judging whether the database operation statement is a target counting statement or not; if yes, a counting record corresponding to the target data table is inquired in a preset counting table according to the database operation statement, the total record number of the target data table is calculated according to the counting record, and the preset counting table is used for recording data row addition and deletion operation corresponding to the data table with the rapid counting function started. Through the method, full table scanning of one table can be converted into index scanning of the specified table, the query time is greatly shortened, and the efficiency improvement effect is more remarkable especially for a scene with large-scale data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a method for processing database operation statements and related products. Background Art

[0002] In current common database technology, counting operations such as count(*) on a single table are generally implemented by scanning the entire table. Therefore, query efficiency is closely related to the amount of data in the table. The larger the amount of data in the table, the slower the query. Therefore, a method is needed to reduce the query time required for counting in order to improve database performance. Summary of the invention

[0003] In view of the above problems, the present invention proposes a method for processing database operation statements and related products that overcome the above problems or at least partially solve the above problems.

[0004] An object of the present invention is to improve the counting query efficiency of a single table.

[0005] A further object of the present invention is to avoid the query time required for single table counting being affected by the amount of data.

[0006] In particular, the present invention provides a method for processing a database operation statement, comprising:

[0007] Get database operation statements;

[0008] Determine whether the database operation statement is a target counting statement;

[0009] If so, the count record corresponding to the target data table is queried in the preset count table according to the database operation statement, and the total number of records in the target data table is calculated based on the count record. The preset count table is used to record the data row addition and deletion operations corresponding to the data table for which the fast counting function has been enabled.

[0010] Optionally, the step of determining whether the database operation statement is a target counting statement includes:

[0011] Determine whether the database operation statement is a query statement;

[0012] If yes, determine whether the query target of the database operation statement is a single data table;

[0013] When the query target of the database operation statement is a single data table, determine whether the target column of the database operation statement is only a count aggregation function;

[0014] When the target column is only a count aggregation function, determine whether there are grouping operations and filtering conditions in the database operation statement;

[0015] When there is no grouping operation and filtering condition in the database operation statement, it is determined that the database operation statement is a target counting statement.

[0016] Optionally, the step of querying a preset count table to obtain count records corresponding to the target data table according to a database operation statement, and calculating the total number of records of the target data table according to the count records includes:

[0017] Convert the database operation statement into a target summation statement, which is used to query the count records in the preset count table and perform sum calculation on the count records;

[0018] Execute the target sum statement to get the total number of records in the target data table.

[0019] Optionally, the step of converting the database operation statement into a target summation statement includes:

[0020] Convert the target column in the database operation statement from a count aggregation function to a sum function;

[0021] Convert the target data table in the database operation statement into a preset count table;

[0022] Add filtering conditions to the database operation statement. The filtering conditions are used to filter the count records belonging to the target data table in the preset count table.

[0023] Optionally, the preset counting table includes: a data table identification column, a counting slot identification column, and an addition and deletion record column;

[0024] The update process of the preset count table includes:

[0025] Determine whether there is a data table in the database to enable the fast counting function;

[0026] If yes, insert the corresponding record of the data table into the preset count table;

[0027] When a data row addition or deletion operation occurs in a data table, the operation results of the data row addition or deletion operation are recorded in a preset counting table.

[0028] Optionally, the step of inserting a record corresponding to the data table into the preset counting table includes:

[0029] Determine the target data table identifier corresponding to the data table itself;

[0030] Get the number of counting slots corresponding to the data table;

[0031] Insert target data rows in the preset counting table in the same number as the number of counting slots according to the target data table identifier;

[0032] A data row is selected from the target data rows to record the current data row number of the target data table in the add / delete record column, and the values ​​of other data rows in the add / delete record column are set as default values.

[0033] Optionally, when a data row addition or deletion operation occurs in a data table, the step of recording the operation result of the data row addition or deletion operation into a preset counting table includes:

[0034] Determine the target data table identifier corresponding to the data table itself;

[0035] Determine the target counting slot identifier corresponding to the data row addition and deletion operations in the preset counting table;

[0036] Determine the record row to be modified, added or deleted in the preset counting table according to the target data table identifier and the target counting slot identifier;

[0037] Determine the number of added or deleted data rows according to the operation results corresponding to the data row addition or deletion operations;

[0038] Combine the number of added and deleted data rows with the number of data rows in the added and deleted record rows to be modified.

[0039] Optionally, the step of determining a target counting slot identifier corresponding to the data row add / delete operation in a preset counting table includes:

[0040] The target counting slot identifier corresponding to the thread is calculated based on the thread executing the data row addition and deletion operation in combination with a preset algorithm.

[0041] According to another aspect of the present invention, a computer program product is provided, which includes a computer program. When the computer program is executed by a processor, the steps of any one of the above-mentioned methods for processing database operation statements are implemented.

[0042] According to another aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, and the processor implements the steps of any of the above-mentioned database operation statement processing methods when executing the machine executable program.

[0043] The method for processing database operation statements of the present invention first obtains database operation statements; then determines whether the database operation statements are target counting statements; if so, queries a preset counting table according to the database operation statements to obtain counting records corresponding to the target data table, and calculates the total number of records in the target data table according to the counting records, wherein the preset counting table is used to record the data row addition and deletion operations corresponding to the data table for which the fast counting function has been enabled. Through this method, a full table scan of a table can be converted into an index scan of a specified table, which greatly shortens the query time, and the efficiency improvement effect is more significant, especially for large-scale data scenarios.

[0044] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:

[0046] Figure 1 is a flowchart of a method for processing database operation statements according to an embodiment of the present invention;

[0047] Figure 2 is a schematic diagram of a database operation statement judgment flow according to an embodiment of the present invention;

[0048] Figure 3 It is a schematic diagram of a process of adding corresponding records to a data table according to an embodiment of the present invention;

[0049] Figure 4 is a schematic diagram of a computer program product according to an embodiment of the present invention;

[0050] Figure 5 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and

[0051] Figure 6 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0052] It should be understood by those skilled in the art that the embodiments described below are only some embodiments of the present invention, rather than all embodiments of the present invention, and these embodiments are intended to explain the technical principles of the present invention, rather than to limit the protection scope of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should still fall within the protection scope of the present invention.

[0053] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein can be considered as a sequenced list of executable instructions for implementing logical functions, which can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or equipment (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or equipment and execute instructions), or used in combination with these instruction execution systems, devices or equipment.

[0054] The present invention provides a method for processing database operation statements. Figure 1 FIG. 1 is a flow chart of a method for processing a database operation statement according to an embodiment of the present invention. Figure 1 As shown, the method for processing the database operation statement at least includes the following steps S101 to S104.

[0055] Step S101, obtaining database operation statements. An optional example is SQL (Structured Query Language). SQL statements have multiple functions such as data manipulation and data definition. This language has interactive characteristics and can provide great convenience for users. In this step, the way to receive database operation statements can generally be active input by the user, or automatically generated by the database program during operation due to business needs. Those skilled in the art can decide the way to receive database operation statements according to actual conditions.

[0056] Step S102, determining whether the database operation statement is a target counting statement.

[0057] In some optional embodiments, the step of determining whether a database operation statement is a target counting statement may generally include: determining whether the database operation statement is a query statement; if so, determining whether the query target of the database operation statement is a single data table; in the case where the query target of the database operation statement is a single data table, determining whether the target column of the database operation statement is only a counting aggregation function; in the case where the target column is only a counting aggregation function, determining whether there are grouping operations and filtering conditions in the database operation statement; in the case where there are no grouping operations and filtering conditions in the database operation statement, determining that the database operation statement is a target counting statement. Among them, judging whether the database operation statement is a query statement generally refers to judging whether SQL is a select statement; judging whether the query target of the database operation statement is a single data table generally refers to judging whether the data table corresponding to the from keyword in the SQL statement is only a single data table; judging whether the target column of the database operation statement is only a counting aggregation function generally refers to judging whether there is only one target column in the target column after the select keyword, and the target column is a counting aggregation function. The counting aggregation function is generally a function such as count(*) or count(1). Such counting aggregation functions are usually used to count the number of data rows that meet the filtering conditions in the target data table; judging whether there are grouping operations and filtering conditions in the database operation statement generally requires that there are no filtering conditions in the SQL statement, that is, there are no where keywords and other grouping operations.

[0058] The final target counting statement example that meets the conditions is generally shown in Formula 1:

[0059] select count(*)from table_nameFormula 1

[0060] The target counting statement shown in Formula 1 is usually used to count the number of record rows in the target data table table_name, that is, to obtain the total number of data in the table. When the database executes this statement, it scans the table_name table row by row. Each time a row is scanned, the count result is increased by 1 until the entire table is scanned. Finally, the total number of records is obtained and returned. However, when the amount of data is large, the efficiency of this full scan query method will be reduced. Among them, count(*) can also be a function such as count(constant), which can achieve the effect of counting the total number of rows in the entire table.

[0061] Step S103, query the preset count table according to the database operation statement to obtain the count record corresponding to the target data table. The preset count table is used to record the data row addition and deletion operations corresponding to the data table for which the fast counting function has been enabled. In order to avoid the occurrence of full table scan, the method of the present invention chooses to store the count record corresponding to the target data table through the preset count table. Each time the specified table is added or deleted, the number of records operated will be recorded in the preset count table.

[0062] In some optional embodiments, the preset count table (countbucket table) may generally include: a data table identification column (table_oid), a counting slot identification column (buckets_id), and an addition and deletion record column (recnum), wherein the data table identification column and the counting slot identification column are used to locate the addition and deletion record column, and thus may generally be used as a joint primary key to ensure uniqueness. The addition and deletion record column is used to store the number of records added or deleted in each operation.

[0063] An optional way to create a preset count table is to add a plug-in to the database, define a SQL statement in the plug-in, and generate a preset count table after the plug-in is created (the table cannot be added or deleted by ordinary users).

[0064] Step S104, calculating the total number of records in the target data table according to the count records.

[0065] Optionally, the steps of querying a preset counting table to obtain counting records corresponding to a target data table according to a database operation statement, and calculating the total number of records in the target data table according to the counting records may generally include: converting the database operation statement into a target summation statement, the target summation statement is used to query a preset counting table to obtain counting records, and sum the counting records; executing the target summation statement to obtain the total number of records in the target data table.

[0066] Optionally, the step of converting the database operation statement into a target summation statement may generally include: converting the target column in the database operation statement from a counting aggregation function to a summation function; converting the target data table in the database operation statement into a preset counting table; adding a filtering condition to the database operation statement, the filtering condition being used to filter the counting records belonging to the target data table in the preset counting table. Still taking the SQL statement shown in Formula 1 as an example, the target summation statement after the conversion of the SQL statement shown in Formula 1 is shown in Formula 2:

[0067] select sum(recnum) from countbucket where oid = table_name_oid Formula 2

[0068] The statement shown in Formula 2 is used to sum the field values ​​of the added and deleted record column (recnum) of the records that meet specific conditions in the preset count table (countbucket table), so as to obtain the total number of records corresponding to the target data table (table_name).

[0069] Finally, after actual testing, the time consumed by the database when executing the SQL statement shown in Formula 1 is 123.148ms. After using this method, the database will convert the SQL statement shown in Formula 1 into the SQL statement shown in Formula 2 when executing the SQL statement shown in Formula 2, and the time consumed when executing the SQL statement shown in Formula 2 is 0.659ms. This shows that the query speed is greatly improved.

[0070] This method can convert a full table scan of a table into an index scan of a specified table (countbucket table), thereby improving query efficiency and avoiding the query time required for single table counts affected by the amount of data.

[0071] In order to distinguish whether the fast counting function is enabled in the data table, an optional method is to add a storage parameter (such as fastcount) as a mark. If the storage parameter is true, it means that the fast counting function is enabled.

[0072] If you want to enable the fast counting function when creating a data table, an optional method is to use with to specify the storage parameters of the data table, and fastcount_number as the specified recnum number, which defaults to 512. The specific example is the SQL statement shown in Formula 3:

[0073] create table t1 (id int) with (fastcount = true, fastcount_number = 100) Formula 3

[0074] When creating a data table, if you enter the SQL statement shown in Formula 3, the database will insert 100 records in the preset count table (countbucket table) according to the OID of the t1 table after creating the data table. The recnum of each record defaults to 0.

[0075] If the data table has been created and you want to enable the quick count function, one option is to use the alter command to set the storage parameter to true to add the function. After adding the function, the database will update the preset count table. The update process of the preset count table can generally include: determining whether there is a data table in the database with the quick count function enabled; if so, inserting the corresponding record of the data table into the preset count table; when a data row addition or deletion operation occurs in the data table, recording the operation results of the data row addition or deletion operation in the preset count table.

[0076] Optionally, the step of inserting records corresponding to the data table in the preset counting table may generally include: determining the target data table identifier corresponding to the data table itself; obtaining the number of counting slots corresponding to the data table; inserting the same number of target data rows as the number of counting slots in the preset counting table according to the target data table identifier; selecting a data row from the target data row to record the current number of data rows of the target data table in the add and delete record column, and setting the values ​​of other data rows in the add and delete record column to the default value. The number of counting slots can be set by those skilled in the art according to actual conditions. An optional example is to set the default value of the number of counting slots to 512, and the database will insert 512 records according to the oid of the t1 table in the preset counting table, and each record defaults to 0 in recnum, and randomly modify the recnum value of a record to the current number of records in the t1 table. The reason for setting multiple counting slots is that most current databases are run synchronously by multiple threads, and multiple threads may perform add and delete operations on the same table at the same time. At this time, it is necessary to record the number of data rows added and deleted by each thread to the table at the same time, so that each thread can be recorded in different slots.

[0077] Optionally, the step of recording the operation results of the data row addition and deletion operation into the preset counting table may generally include: determining the target data table identifier corresponding to the data table itself; determining the target counting slot identifier corresponding to the data row addition and deletion operation in the preset counting table; determining the to-be-modified addition and deletion record row in the preset counting table according to the target data table identifier and the target counting slot identifier; determining the number of added and deleted data rows according to the operation results corresponding to the data row addition and deletion operation; merging the number of added and deleted data rows with the number of data rows in the to-be-modified addition and deletion record row. For example, the number of added records is recorded as +XXX. At this time, the database will determine the current target data table identifier and the target counting slot identifier, and modify the data corresponding to t1 in the preset counting (countbukets) table so that the number of newly added records is added to the number of data rows in the original to-be-modified addition and deletion record row. Assuming that the target data table identifier is 16500 and the target counting slot identifier is 1, the modified statement can be shown as Formula 4:

[0078] update countbuckets set recnum=recnum+XXX where table_oid=16500andbucket_id=1 Formula 4

[0079] If it is a delete operation, the number of deleted records can be recorded as -XXX, and the data corresponding to t1 can be modified in the preset count (countbuckets) table so that the number of newly added records is subtracted from the number of data rows in the original record row to be modified. Assuming that the target data table is marked as 16500 and the target count slot is marked as 1, the modification statement can be shown as formula 5:

[0080] update countbuckets set recnum=recnum-XXX where table_oid=16500andbucket_id=1 Formula 5

[0081] The step of determining the target counting slot identifier may generally include: calculating the target counting slot identifier corresponding to the thread according to the thread executing the data row addition and deletion operation in combination with a preset algorithm. Those skilled in the art may determine a specific algorithm (such as a hash algorithm, a random algorithm, a polling algorithm, etc.) according to actual conditions so that different threads correspond to different counting slots, thereby achieving synchronous recording.

[0082] Figure 2 FIG. 1 is a schematic diagram of a database operation statement judgment flow according to an embodiment of the present invention. Figure 2 As shown, the database operation statement judgment process at least includes the following steps S201 to S207.

[0083] Step S201, obtaining a database operation statement.

[0084] Step S202, determine whether the database operation statement is a query statement. This step generally refers to determining whether the sql is a select statement.

[0085] Step S203, if the judgment in step S202 is yes, determine whether the query target of the database operation statement is a single data table. This step generally refers to determining whether the data table corresponding to the from keyword in the SQL statement is only a single data table.

[0086] Step S204, if the judgment in step S203 is yes, determine whether the target column of the database operation statement is only a counting aggregation function. This step generally refers to determining whether there is only one target column in the target column after the select keyword, and the target column is a counting aggregation function, wherein the counting aggregation function is generally a function such as count(*) or count(1), and such counting aggregation functions are usually used to count the number of data rows in the target data table that meet the filtering conditions.

[0087] Step S205, if the judgment in step S204 is yes, it is determined whether there is a grouping operation and a filtering condition in the database operation statement. This step generally requires that there is no filtering condition in the SQL statement, that is, there is no where keyword and other grouping operations.

[0088] Step S206: If the judgment in step S205 is no, determine that the database operation statement is a target counting statement, and perform subsequent operations.

[0089] Step S207: If any of step S202, step S203 and step S204 is judged as no or step S205 is judged as yes, it is determined that the database operation statement is not a target counting statement, and this method is skipped. The target counting statement example that finally meets the conditions is generally shown in Formula 1.

[0090] This method can accurately filter out target counting statements from numerous database operation statements. This precise screening ensures that only statements that meet specific formats and conditions (single-table query, target columns that are only counting aggregate functions, query statements without grouping operations and filtering conditions) are identified as target counting statements, avoiding misjudgment and allowing subsequent optimization operations based on target counting statements (such as using preset counting tables to efficiently query the number of records, etc.) to be accurately applied to appropriate statement scenarios.

[0091] Figure 3 FIG. 1 is a flow chart of adding corresponding records to a data table according to an embodiment of the present invention. Figure 3As shown, the method for processing the database operation statement at least includes the following steps S301 to S305.

[0092] Step S301, determine whether there is a data table in the database to enable the fast counting function.

[0093] Step S302: when the result of step S301 is yes, determine the target data table identifier corresponding to the data table itself.

[0094] Step S303, obtaining the number of counting slots corresponding to the data table.

[0095] Step S304: inserting target data rows whose number is the same as the number of counting slots into the preset counting table according to the target data table identifier.

[0096] Step S305 , selecting a data row from the target data rows and recording the current number of data rows in the target data table in the add / delete record column, and setting the values ​​of other data rows in the add / delete record column as default values.

[0097] The number of counting slots can be set by technicians in this field according to actual conditions. An optional example is to set the default value of the number of counting slots to 512. The database will insert 512 records in the preset counting table according to the oid of the t1 table. The recnum of each record defaults to 0, and the recnum value of a record is randomly modified to the current number of records in the t1 table. The reason for setting multiple counting slots is that most current databases run synchronously with multiple threads. At the same time, multiple threads may perform add and delete operations on the same table. At this time, it is necessary to record the number of data rows added and deleted by each thread at the same time, so different slots corresponding to each thread can be recorded.

[0098] Through this method, the scope of objects that need special counting processing is determined. Then, when it is confirmed to be enabled, a dedicated "counting space" is opened in the preset counting table for each data table with the fast counting function enabled, and an infrastructure for efficient counting based on the preset counting table is built, so that these data rows can be used later to accurately record the operation status of the data table.

[0099] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.

[0100] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.

[0101] This embodiment also provides a computer program product 10 , a computer readable storage medium 20 , and a computer device 30 . Figure 4 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Figure 5 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention, Figure 6 is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned methods for processing database operation statements when executed by a processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11, which implements the steps of any of the above-mentioned methods for processing database operation statements when executed by a processor 32. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.

[0102] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages ​​and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.

[0103] For the purposes of the description of the present embodiment, the computer program product 10 is a related product that includes the computer program 11. For the purposes of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which may be any device that can contain, store, communicate, propagate or transmit the program 11 for use with or in conjunction with an instruction execution system, device or apparatus. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the foregoing.

[0104] The computer device 30 may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device 30 may be a cloud computing node. The computer device 30 may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device 30 may be implemented in a distributed cloud computing environment where remote processing devices linked via a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.

[0105] The computer device 30 may include a processor 32 adapted to execute stored instructions, and a memory 31 providing temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory 31 may include a random access memory (RAM), a read-only memory, a flash memory, or any other suitable storage system.

[0106] The computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows data to be input and output with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is typically shown as a communication network.

[0107] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.

Claims

1. A method for processing a database operation statement, comprising: Obtaining the database operation statement; Determining whether the database operation statement is a target counting statement; If so, the count record corresponding to the target data table is queried in the preset count table according to the database operation statement, and the total number of records in the target data table is calculated based on the count record. The preset count table is used to record the data row addition and deletion operations corresponding to the data table for which the quick counting function has been enabled.

2. The method for processing database operation statements according to claim 1, wherein: The step of determining whether the database operation statement is a target counting statement comprises: Determining whether the database operation statement is a query statement; If yes, determining whether the query target of the database operation statement is a single data table; In the case where the query target of the database operation statement is a single data table, determining whether the target column of the database operation statement is only a counting aggregation function; In the case where the target column is only a counting aggregation function, determining whether there is a grouping operation and a filtering condition in the database operation statement; When there is no grouping operation and filtering condition in the database operation statement, it is determined that the database operation statement is the target counting statement.

3. The method for processing database operation statements according to claim 2, wherein: The step of querying a preset count table to obtain a count record corresponding to a target data table according to the database operation statement, and calculating the total number of records of the target data table according to the count record comprises: Converting the database operation statement into a target summation statement, wherein the target summation statement is used to query the preset count table to obtain the count record and perform sum calculation on the count record; Execute the target sum statement to obtain the total number of records in the target data table.

4. The method for processing database operation statements according to claim 3, wherein: The step of converting the database operation statement into a target summation statement comprises: Converting the target column in the database operation statement from the counting aggregation function to a summation function; Converting the target data table in the database operation statement into the preset counting table; A filtering condition is added to the database operation statement, and the filtering condition is used to filter the counting records belonging to the target data table in the preset counting table.

5. The method for processing database operation statements according to claim 1, wherein: The preset counting table includes: a data table identification column, a counting slot identification column, and an addition and deletion record column; The updating process of the preset counting table includes: Determine whether there is a data table in the database to enable the fast counting function; If yes, inserting the record corresponding to the data table into the preset counting table; When the data row addition and deletion operations occur in the data table, the operation results of the data row addition and deletion operations are recorded in the preset counting table.

6. The method for processing database operation statements according to claim 5, wherein: The step of inserting the record corresponding to the data table into the preset counting table comprises: Determine a target data table identifier corresponding to the data table itself; Obtain the number of counting slots corresponding to the data table; Inserting the same number of target data rows as the number of the counting slots into the preset counting table according to the target data table identifier; A data row is selected from the target data rows to record the current number of data rows in the target data table in the add / delete record column, and the values ​​of other data rows in the add / delete record column are set as default values.

7. The method for processing database operation statements according to claim 6, wherein: When the data row addition and deletion operation occurs in the data table, the step of recording the operation result of the data row addition and deletion operation into the preset counting table includes: Determine a target data table identifier corresponding to the data table itself; Determine the target counting slot identifier corresponding to the data row addition and deletion operation in the preset counting table; Determine the record row to be modified, added or deleted in the preset counting table according to the target data table identifier and the target counting slot identifier; Determine the number of added or deleted data rows according to the operation result corresponding to the data row addition or deletion operation; The number of added and deleted data rows is combined with the number of data rows in the added and deleted record row to be modified.

8. The method for processing database operation statements according to claim 7, wherein: The step of determining the target counting slot identifier corresponding to the data row addition and deletion operation in the preset counting table includes: The target counting slot identifier corresponding to the thread is calculated based on the thread executing the data row addition and deletion operation in combination with a preset algorithm.

9. A computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method for processing a database operation statement according to any one of claims 1 to 8.

10. A computer device comprising a memory, a processor, and a machine executable program stored in the memory and running on the processor, wherein the processor implements the steps of the method for processing database operation statements according to any one of claims 1 to 8 when executing the machine executable program.

Citation Information

Cited By

  • Method for improving count operation efficiency in database whole table encryption scene

    CN121070963A