Method, device and electronic device for deleting data from distributed database
By receiving data deletion statements in a distributed database, determining the maximum number of rows in the target table, and selecting the deletion method based on the total number of rows to be deleted, the problem of low data deletion efficiency in a distributed database is solved, and a more efficient data deletion process is achieved.
Patent Information
- Application Number
- CN202210404387.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-18
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2042-04-18
AI Technical Summary
When existing distributed databases delete data with specified number of rows, it is difficult to ensure the efficiency of data deletion.
By receiving the data deletion statement, the maximum value of the total number of rows of the target table in each data node is determined, and the serial or parallel deletion method is determined based on the total number of rows to be deleted and the maximum number of target rows to be deleted, and finally the data of the target table stored by the target data node is deleted according to the determined method.
It improves the efficiency of deleting specified rows in a distributed database, and reduces the waiting time during the deletion process and the time to read node information by more accurately determining the deletion method.
Smart Images

Figure CN114840536B_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of distributed databases, and in particular, relates to a data deletion method, device, electronic device, and computer-readable storage medium for a distributed database. Background Art
[0002] As more and more data is stored in the database, the storage capacity of the database will be insufficient, and insufficient storage capacity will reduce the performance of the database. In this case, users generally choose to delete the data of the specified row to save resources and improve the performance of the database.
[0003] However, in a distributed database, since data is stored in a distributed manner on multiple nodes, different deletion methods will take different amounts of time. Summary of the invention
[0004] The embodiments of the present application provide a method, device and electronic device for deleting data in a distributed database, which can solve the problem that it is difficult to ensure the efficiency of data deletion when deleting a specified number of rows of data in an existing distributed database.
[0005] In a first aspect, an embodiment of the present application provides a method for deleting data in a distributed database, comprising:
[0006] Receive a first data deletion statement, the first data deletion statement including a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores data of the target table in the form of rows, and the target data node is a data node storing the target table;
[0007] Determine a first target number of rows, where the first target number of rows is the maximum value of the total number of rows corresponding to the data stored in each of the target data nodes of the target table;
[0008] Determining a target deletion mode according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion mode is a serial deletion mode or a parallel deletion mode, the serial deletion mode refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion mode refers to deleting the data of the target table stored in each target data node at the same time;
[0009] The data of the target table stored in the target data node is deleted according to the total number of rows to be deleted and the target deletion mode.
[0010] In a second aspect, an embodiment of the present application provides a data deletion device for a distributed database, comprising:
[0011] A first data deletion statement receiving module, configured to receive a first data deletion statement, wherein the first data deletion statement includes a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores data of the target table in the form of rows, and the target data node is a data node storing the target table;
[0012] A first target row number determination module, used to determine a first target row number, where the first target row number is the maximum value of the total number of rows corresponding to the data stored in each of the target data nodes of the target table;
[0013] a target deletion mode determination module, configured to determine a target deletion mode according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion mode is a serial deletion mode or a parallel deletion mode, wherein the serial deletion mode refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion mode refers to deleting the data of the target table stored in each target data node at the same time;
[0014] The data deletion module is used to delete the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion method.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the computer program.
[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0017] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the method described in the first aspect above.
[0018] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0019] In the embodiment of the present application, after receiving the first data deletion statement, the maximum value of the total number of rows of the target table data stored in each target data node is determined according to the unique identifier of the target table included in the first data deletion statement, and the first target number of rows is obtained, and the target deletion method is determined according to the total number of rows to be deleted and the first target number of rows included in the first data deletion statement, and finally the data of the target table stored in the target data node is deleted according to the total number of rows to be deleted and the target deletion method. Since the relationship between the maximum value of the total number of rows of the target table data stored in each target data node and the total number of rows to be deleted can reflect the number of target data nodes that need to delete the data of the target table, therefore, the accuracy of the determined target deletion method can be improved according to the total number of rows to be deleted and the first target number of rows. And since a more accurate target deletion method is conducive to improving the efficiency of deleting data, therefore, the data deletion method of the distributed database provided in the embodiment of the present application is conducive to improving the efficiency of deleting a specified number of rows in the distributed database. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0021] Figure 1 This is a flow chart of a method for deleting data in a distributed database provided by an embodiment of the present application;
[0022] Figure 2 It is a schematic diagram of the structure of a distributed database including 10 data nodes provided in an embodiment of the present application;
[0023] Figure 3 This is a flow chart of another distributed database data deletion method provided by an embodiment of the present application;
[0024] Figure 4 It is a structural diagram of a data deletion device for a distributed database provided by an embodiment of the present application;
[0025] Figure 5 It is a structural schematic diagram of an electronic device provided in another embodiment of the present application. DETAILED DESCRIPTION
[0026] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0027] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0028] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0029] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0030] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways.
[0031] Embodiment 1:
[0032] When the storage capacity of a distributed database is insufficient, users will choose to delete a specified number of rows of data to improve database performance. However, since data in the same table is usually stored in different data nodes, the time spent deleting data using different deletion methods is usually different. Therefore, it is necessary to select the corresponding deletion method based on the actual request.
[0033] In order to quickly delete a specified number of rows of data from a distributed database, an embodiment of the present application provides a method for deleting data in a distributed database.
[0034] In the data deletion method, if the first data deletion statement is detected, which data node in the distributed database stores the data of the target table is determined based on the unique identifier of the target table included in the first data deletion statement, and the data node storing the data of the target table is used as the target data node of the embodiment of the present application. The total number of rows corresponding to the data of the target table stored in these target data nodes is counted respectively, and then the maximum total number of rows is determined from these total number of rows as the first target number of rows in the embodiment of the present application, and the target deletion method is determined based on the total number of rows to be deleted included in the first data deletion statement and the first target number of rows, and finally the data of the target table stored in the above target data node is deleted according to the total number of rows to be deleted and the target deletion method.
[0035] The following describes the data deletion method of the distributed database provided by the embodiment of the present application in conjunction with the accompanying drawings.
[0036] Figure 1 A flow chart of a distributed database data deletion method provided by an embodiment of the present application is shown, and the details are as follows:
[0037] Step S11, receiving a first data deletion statement, wherein the first data deletion statement includes a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores the data of the target table in the form of rows, and the target data node is a data node storing the target table.
[0038] The first data deletion statement is a statement including the delete character, which is usually expressed in a structured query language (SQL). Figure 2 As shown, it is assumed that there are 10 data nodes in the distributed database, namely data node 1, data node 2, ..., data node 10. If the first data deletion statement is "DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 10", the unique identifier of the target table is "TABLE_A", and the total number of rows to be deleted is "10" corresponding to LIMIT. If these 10 data nodes all store the data of table TABLE_A, then these 10 data nodes are the target data nodes of the embodiment of the present application, that is, 10 rows of data in TABLE_A need to be deleted from one or more of these 10 data nodes.
[0039] Step S12, determining a first target number of rows, where the first target number of rows is the maximum value of the total number of rows corresponding to the data stored in the target table at each of the target data nodes.
[0040] Specifically, the total number of rows of data in the target table stored in each target data node is first counted, and then the largest value is selected from each total number of rows as the first target number of rows.
[0041] Step S13, determining the target deletion method according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion method is a serial deletion method or a parallel deletion method, the serial deletion method refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion method refers to deleting the data of the target table stored in each of the target data nodes at the same time.
[0042] In the embodiment of the present application, when it is necessary to delete the data of the target table stored in a certain target data node, it is necessary to read the information of the target data node before deleting the data of the target table stored therein. Since the process of reading the information of the target data node takes a certain amount of time, it is necessary to determine whether to delete the data of the target table stored in the target data node one by one or to delete the data of the target table stored in each target data node at the same time according to actual needs, so as to achieve the purpose of deleting the data of the total number of rows to be deleted more quickly.
[0043] After analysis, the inventor of the present application knows that the relationship between the maximum total number of rows of the target table data stored by each target data node and the total number of rows to be deleted has a certain guiding significance for the deletion method. For example, when the difference between the total number of rows to be deleted and the above maximum value is greater, it indicates that only deleting the data of the target table stored by a limited number of target data nodes can achieve the purpose of deleting the total number of rows to be deleted. The higher the probability, at this time, the serial deletion method can be selected to reduce the number of target data nodes that need to read information, thereby improving the deletion efficiency. On the contrary, it indicates that only deleting the data of the target table stored by a limited number of target data nodes can achieve the purpose of deleting the total number of rows to be deleted. The lower the probability, at this time, the parallel deletion method can be selected. Since each target data node performs the deletion operation at the same time, the deletion efficiency can be improved.
[0044] Step S14: deleting the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion method.
[0045] Specifically, since the total number of rows to be deleted is set by the user through the first data deletion statement, the total number of rows to be deleted may be equal to the total number of rows corresponding to the data of the target table stored by all target data nodes, or may not be equal to the total number of rows corresponding to the data of the target table stored by all target data nodes. Therefore, when performing a deletion operation, it is necessary to delete the data of the target table according to the total number of rows to be deleted and the target deletion method.
[0046] In the embodiment of the present application, after receiving the first data deletion statement, the maximum value of the total number of rows of the target table data stored in each target data node is determined according to the unique identifier of the target table included in the first data deletion statement, and the first target number of rows is obtained, and the target deletion method is determined according to the total number of rows to be deleted and the first target number of rows included in the first data deletion statement, and finally the data of the target table stored in the target data node is deleted according to the total number of rows to be deleted and the target deletion method. Since the relationship between the maximum value of the total number of rows of the target table data stored in each target data node and the total number of rows to be deleted can reflect the number of target data nodes that need to delete the data of the target table, therefore, the accuracy of the determined target deletion method can be improved according to the total number of rows to be deleted and the first target number of rows. And since a more accurate target deletion method is conducive to improving the efficiency of deleting data, therefore, the data deletion method of the distributed database provided in the embodiment of the present application is conducive to improving the efficiency of deleting a specified number of rows in the distributed database.
[0047] In some embodiments, the above step S13 includes:
[0048] A1. If the ratio of the total number of rows to be deleted to the first target number of rows is less than a preset ratio threshold, it is determined that the target deletion method is a serial deletion method.
[0049] The preset ratio threshold is a value less than 0.001. For example, the ratio threshold can be set to 0.0001, that is, the preset ratio threshold cannot be too large.
[0050] A2. If the ratio of the total number of rows to be deleted to the first target number of rows is not less than a preset ratio threshold, the target deletion method is determined to be a parallel deletion method.
[0051] In the embodiment of the present application, when the ratio of the total number of rows to be deleted to the first target number of rows is less than the preset ratio threshold, it indicates that the target data node corresponding to the first target number of rows stores more data in the target table, that is, only deleting the data of the target table stored by a limited number of target data nodes can achieve the purpose of deleting the total number of rows to be deleted. The higher the probability, at this time, by deleting the data of the target table stored by the target data node one by one, the information of the target data node to be read can be reduced, thereby improving the efficiency of deleting data. In addition, when the ratio of the total number of rows to be deleted to the first target number of rows is not less than the preset ratio threshold, it indicates that the target data node corresponding to the first target number of rows stores less data in the target table, that is, only deleting the data of the target table stored by a limited number of target data nodes can achieve the purpose of deleting the total number of rows to be deleted. The lower the probability, at this time, executing the operation of deleting the data of the target table from each target data node at the same time can reduce the waiting time, thereby helping to improve the efficiency of data deletion.
[0052] In some embodiments, when the target deletion method is a serial deletion method, the step S14 includes:
[0053] B1. Sort the total number of rows corresponding to the data stored in each of the target data nodes in the target table in descending order to obtain a sorting result.
[0054] B2. According to the above sorting result, the data of the target table stored in the above target data nodes are deleted from the front to the back until the stop deletion condition is met. The above stop deletion condition includes: the cumulative value of the number of rows of deleted data is equal to the total number of rows to be deleted or all target data nodes have deleted the data corresponding to the target table stored therein.
[0055] For example, assuming that the total number of rows corresponding to the data of the target table stored in target data node 1 is 10 rows, the total number of rows corresponding to the data of the target table stored in target data node 2 is 11 rows, and the total number of rows corresponding to the data of the target table stored in target data node 3 is 12 rows, the sorting results obtained are target data node 3, target data node 2 and target data node 1. When performing a delete operation, first delete the data of the target table stored in target data node 3. If the stop deletion condition is met after the delete operation is performed, for example, the cumulative value of the number of rows of the deleted data is equal to the total number of rows to be deleted, then the delete operation is no longer performed on target data node 2 and target data node 1. Of course, if the stop deletion condition is not met after the delete operation is performed, it is necessary to delete the data of the target table stored in target data node 2 again, and judge again whether the stop deletion condition is currently met. If it is still not met, it is necessary to continue to delete the data of the target table stored in target data node 1.
[0056] It should be pointed out that when deleting the data of the target table on the target data node one by one, that is, when deleting the data of the target table on the next target data node, it is necessary to first count the number of rows of data in the target table to be deleted at the next target data node, and then delete the corresponding data in the target table of the next target data node based on the counted number of rows. Among them, the number of rows counted is determined according to the difference between the total number of rows to be deleted and the number of rows of data successfully deleted by all target data nodes that have performed the deletion operation. For example, assuming that the number of rows of data successfully deleted at the first target data node is H1, the number of rows to be deleted at the second target data node is (the total number of rows to be deleted - H1), and if the number of rows of data successfully deleted at the second target data node is H2, the number of rows to be deleted at the third target data node is (the total number of rows to be deleted - H1 - H2).
[0057] In some embodiments, when the target deletion mode is a parallel deletion mode, the above step S14 includes:
[0058] C1. Calculate the cumulative value of the total number of rows corresponding to the data stored in the target table at each of the target data nodes to obtain a target cumulative value.
[0059] For example, assuming that there are three target data nodes, namely target data node 1, target data node 2 and target data node 3, and the total number of rows corresponding to the data of the target table stored in target data node 1 is Y1, the total number of rows corresponding to the data of the target table stored in target data node 2 is Y2, and the total number of rows corresponding to the data of the target table stored in target data node 3 is Y3, then the cumulative value of the total number of rows corresponding to the data stored in the target table in target data node 1, target data node 2 and target data node 3 is (Y1+Y2+Y3).
[0060] C2. If the total number of rows to be deleted is not less than the target cumulative value, directly delete the data stored in the target table at each of the target data nodes in a parallel deletion manner.
[0061] C3. If the total number of rows to be deleted is less than the target cumulative value, first determine the second target number of rows corresponding to each of the target data nodes, and then use the second target number of rows as a basis to delete the data in the target table of each of the target data nodes in parallel, wherein each of the second target numbers of rows is the total number of rows of data in the target table that needs to be deleted at each of the target data nodes, which is determined based on the total number of rows to be deleted.
[0062] In some embodiments, the above step C2 includes:
[0063] C21. Detect whether the first data deletion statement includes a conditional clause.
[0064] The conditional clause may be a clause containing "where".
[0065] C22. If the first data deletion statement includes the conditional clause, a second data deletion statement is generated, wherein the second data deletion statement does not include the total number of rows to be deleted corresponding to the target table.
[0066] For example, if the first data deletion statement is "DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 10", since the first data deletion statement includes "WHERE rq<'2020-01-01'", it is determined that the first data deletion statement includes a conditional clause. At this time, the first data deletion statement is converted into a delete statement "DELETE FROM TABLE_A WHERE rq<'2020-01-01'" without a limited number of rows, and a second data deletion statement corresponding to the first data deletion statement is obtained.
[0067] C23. According to the second data deletion statement, the data of the corresponding target table is deleted in parallel at each of the target data nodes.
[0068] Specifically, each target data node deletes the data of the target table stored therein in parallel according to the second data deletion statement. Since the second data deletion statement does not include the total number of rows to be deleted corresponding to the target table, no matter how much data of the target table is actually stored in each target data node, these target data nodes can delete the data of the target table stored therein according to the second data deletion statement.
[0069] C24. If the first data deletion statement does not include the conditional clause, a third data deletion statement is generated, wherein the third data deletion statement is used to delete the data of the entire target table stored in the target data node.
[0070] The third data deletion statement may be a statement including truncate table, which can quickly delete the contents of the entire target table, thereby restoring the space occupied by the target table in its corresponding target data node.
[0071] C25. According to the third data deletion statement, the data of the corresponding target table is deleted in parallel at each of the target data nodes.
[0072] In the embodiment of the present application, after it is determined that the total number of rows to be deleted is not less than the target cumulative value, it indicates that the data of the target table stored in all target data nodes needs to be deleted. In the embodiment of the present application, since when it is determined that the first data deletion statement includes a conditional clause, a second data deletion statement that does not include the total number of rows to be deleted corresponding to the target table is generated according to the first data deletion statement, therefore, when each target data node performs a deletion operation according to the second data deletion statement, it can be free from the restriction of the total number of rows to be deleted corresponding to the target table. In addition, since when it is determined that the first data deletion statement does not include a conditional clause, a third data deletion statement for deleting the data of the entire target table stored in the target data node is generated according to the first data deletion statement, therefore, when each target data node performs a deletion operation according to the third data deletion statement, the data of the corresponding target table can be quickly deleted. That is, in the embodiment of the present application, since different data deletion statements are generated according to whether the first data deletion statement includes a conditional clause, not only the accuracy of the deleted data can be guaranteed, but also the efficiency of the deletion can be guaranteed.
[0073] In some embodiments, when determining the second target number of rows corresponding to each of the target data nodes, step C3 includes:
[0074] According to the total number of rows corresponding to the data stored in the target table at each of the target data nodes and the total number of rows to be deleted, the total number of rows of data in the target table to be deleted at each of the target data nodes is determined respectively to obtain the second target number of rows corresponding to each of the target data nodes.
[0075] In the embodiment of the present application, considering that the more the total number of rows of data stored in the target data node, the more the number of rows that can be deleted is usually, therefore, when determining the second target number of rows corresponding to each target data node, the total number of rows corresponding to the data stored in the target data node is combined, and the accuracy of the second target number of rows obtained can be improved. For example, for any target data node, the second target number of rows corresponding to the target data node can be calculated according to the following formula: the (total number of rows of data stored in the target data node / the total number of rows corresponding to the data stored in the target table in each of the above target data nodes) * the total number of rows to be deleted, if the obtained value is not an integer, the obtained value is rounded down as the second target number of rows corresponding to the target data node. For example, assuming that there are target data nodes 1, 2, and 3, and the total number of rows of data in the target table stored by these three target data nodes is Y1, Y2, and Y3 respectively, and the total number of rows of data to be deleted is M, then the second target number of rows corresponding to the target data node 1 is: [Y1 / (Y1+Y2+Y3)]*M.
[0076] In some embodiments, respectively determining the total number of rows of data in the target table to be deleted at each of the target data nodes to obtain a second target number of rows corresponding to each of the target data nodes includes:
[0077] D1. Determine the total number of rows of data in the target table that needs to be deleted at each of the target data nodes, and obtain an initial second target number of rows corresponding to each of the target data nodes;
[0078] D2, counting the sum of the initial second target row numbers mentioned above;
[0079] Specifically, each second target row number is added together to obtain the above-mentioned sum value.
[0080] D3, determining whether the initial second target number of rows needs to be corrected according to the sum and the total number of rows to be deleted;
[0081] Specifically, when the sum value is not equal to the total number of rows to be deleted, it indicates that the obtained second target number of rows needs to be corrected.
[0082] D4. If correction is required, the initial second target row number corresponding to one of the target data nodes is corrected to obtain a corrected second target row number corresponding to one of the target data nodes;
[0083] D5. Determine the final second target row number corresponding to each of the target data nodes according to the corrected second target row number and each initial second target row number that does not need to be corrected.
[0084] In this embodiment, when the second target number of rows corresponding to each target data node is determined by rounding down, if the sum is not equal to the total number of rows to be deleted, the difference between the sum and the total number of rows to be deleted will not be very large. At this time, in order to reduce the number of corrections, only the second target number of rows corresponding to one of the target data nodes is corrected. Of course, the target data nodes corresponding to the corrected second target number of rows will perform data deletion operations according to the corrected second target number of rows, while the target data nodes corresponding to the second target number of rows that do not need to be corrected will perform data deletion operations according to the originally determined second target number of rows.
[0085] In some embodiments, when the above-mentioned D3 corrects the second target row number corresponding to one of the target data nodes, it corrects the second target row number of the target data node corresponding to the maximum value of the total number of rows corresponding to the data of the stored target table, and the corrected second target row number is determined specifically according to the following formula: the total number of rows to be deleted - (the sum of the second target row numbers corresponding to other target data nodes except the target data node that needs to be corrected).
[0086] In the embodiment of the present application, considering that the sum is not equal to the total number of rows to be deleted, the probability that the second target number of rows determined by the target data node corresponding to the maximum value of the total number of rows corresponding to the data of the stored target table needs to be corrected is relatively high. Therefore, directly correcting the second target number of rows corresponding to the target data node corresponding to the maximum value of the total number of rows corresponding to the data of the stored target table can not only ensure the accuracy of the second target number of rows corresponding to other target data nodes, but also ensure the efficiency of the correction.
[0087] In order to more clearly describe the data deletion method of the distributed database provided in the embodiment of the present application, a specific application example is described below.
[0088] Figure 3 A flow chart showing another method for deleting data in a distributed database is shown.
[0089] Assume that four first data deletion statements are received, namely:
[0090] ①DELETE FROM TABLE_A WHERE rq<'2020-01-01'LIMIT 10
[0091] ②DELETE FROM TABLE_A WHERE rq<'2020-01-01'LIMIT 2000000
[0092] ③DELETE FROM TABLE_A LIMIT 2000000
[0093] ④DELETE FROM TABLE_A WHERE rq<'2020-01-01'LIMIT 1000000
[0094] In this embodiment, it is assumed that the distributed database has 10 data nodes, namely data node 1, data node 2, ..., data node 10. Referring to Table 1, the number of rows of data in table TABLE_A on these data nodes is 100000 rows, 101000 rows, 102000 rows ... 109000 rows of data. That is, for table TABLE_A, data node 1, data node 2, ..., data node 10 are all target data nodes in the embodiment of the present application.
[0095] Table 1:
[0096] Data Node 1 100000 Data Node 2 101000 Data Node 3 102000 ... ... Data Node 10 109000
[0097] (I) For the first data deletion statement "DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 10", the execution logic flow is as follows:
[0098] 1) Parse the delete statement and extract from the LIMIT 10 clause that the total number of rows to be deleted is 10, that is, limit_number = 10. Corresponding process Figure 3 The sequence number is 1.
[0099] 2) Query the total number of rows in TABLE_A in each data node (i.e. the total number of rows corresponding to the data stored in the target table in each of the above target data nodes), and record the structure and data of node_number_map in the map container as shown in Table 1. Corresponding process Figure 3 The serial number 2 in .
[0100] 3) Calculate the ratio of limit_number to the maximum total number of rows in node_number_map (i.e., the first target number of rows), i.e., p = 10 / 109000 = 0.000092. Corresponding process Figure 3 The serial number 3 in .
[0101] 4) Assuming the preset ratio threshold is 0.0001, then p < ratio threshold (0.0001). Corresponding process Figure 3 The serial number 4 in .
[0102] 5) Sort the data nodes in node_number_map in descending order according to the number of data rows, that is, the output list node_order_list is ['data node 10', 'data node 9', 'data node 8'...'data node 1']. Corresponding process Figure 3 The serial number is 5.
[0103] 6) Select the first node in node_order_list, that is, 'data node 10' as the target node for executing the delete statement. Corresponding process Figure 3 The serial number is 6.
[0104] 7) Generate a new delete statement based on the current limit_number value, such as DELETE FROM TABLE_AWHERE rq<'2020-01-01' LIMIT limit_number. Corresponding process Figure 3 The serial number is 7.
[0105] 8) Send the delete statement in the previous step to 'data node 10' for execution. Corresponding process Figure 3 The serial number is 8.
[0106] 9) Data node 10 returns the number of successfully deleted data rows, ok_number. Figure 3 Serial number 9 in .
[0107] 10) Recalculate the total number of rows to be deleted: limit_number = limit_number - ok_number. Corresponding process Figure 3 The serial number is 10.
[0108] 11) If limit_number = 0, it means that the specified number of rows of data have been successfully deleted and the process ends. Otherwise, select the next node from node_order_list and repeat 7) to 10) until the recalculated limit_number = 0 or all data nodes have been traversed and processed. Figure 3 Serial numbers 11 to 13.
[0109] (II) The execution logic flow for the second first data deletion statement "DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 2000000" is as follows:
[0110] 1) Parse the delete statement and extract from the LIMIT 2000000 clause that the total number of rows to be deleted is 2000000, that is, limit_number = 2000000. Corresponding process Figure 3 The sequence number is 1.
[0111] 2) Query the total number of rows in each data node of table TABLE_A and record the structure and data of node_number_map in the map container as shown in Table 1. Figure 3 The serial number 2 in .
[0112] 3) Calculate the ratio of limit_number to the maximum total number of rows in node_number_map, that is, p = 2000000 / 109000 = 18.3. Corresponding process Figure 3 The serial number 3 in .
[0113] 4) p>ratio threshold (0.0001). Corresponding process Figure 3 The serial number 4 in .
[0114] 5) The cumulative value of the total number of rows in node_number_map (i.e. the target cumulative value) = 100000 + 101000 + 102000 + ... + 109000 = 1055000, so limit_number>the cumulative value of the total number of rows in node_number_map. Corresponding process Figure 3 The serial number is 21.
[0115] Since the delete statement contains the WHERE clause WHERE rq<'2020-01-01', it is converted into a delete statement without a row limit, and the second data deletion statement "DELETE FROM TABLE_A WHERE rq<'2020-01-01'" is obtained. This second data deletion statement is sent to all data nodes for parallel execution. Corresponding process Figure 3 The serial numbers 22 and 23 in the.
[0116] (III) For the third first data deletion statement "DELETE FROM TABLE_A LIMIT2000000", the execution logic flow is as follows:
[0117] 1) Parse the delete statement and extract from the LIMIT 2000000 clause that the total number of rows to be deleted is 2000000, that is, limit_number = 2000000. Corresponding process Figure 3 The sequence number is 1.
[0118] 2) Query the total number of rows in each data node of table TABLE_A and record the structure and data of node_number_map in the map container as shown in Table 1. Figure 3 The serial number 2 in .
[0119] 3) Calculate the ratio of limit_number to the maximum total number of rows in node_number_map, that is, p = 2000000 / 109000 = 18.3. Corresponding process Figure 3 The serial number 3 in .
[0120] 4) p>ratio threshold (0.0001). Corresponding process Figure 3 The serial number 4 in .
[0121] 5) The cumulative value of the total number of rows in node_number_map (i.e. the target cumulative value) = 100000 + 101000 + 102000 + ... + 109000 = 1055000, so limit_number>the cumulative value of the total number of rows in node_number_map. Corresponding process Figure 3 The serial number is 21.
[0122] 6) The delete statement does not contain a WHERE clause, which means that the statement is actually equivalent to clearing the data in table TABLE_A. Therefore, it can be converted into a more efficient table data clearing statement truncate table statement to obtain the third data deletion statement "TRUNCATE TABLE TABLE_A", which is sent to all data nodes for parallel execution. Corresponding process Figure 3 The serial numbers 22 and 24 in the.
[0123] (IV) For the fourth first data deletion statement "DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 1000000", the execution logic flow is as follows:
[0124] 1) Parse the delete statement and extract from the LIMIT 1000000 clause that the total number of rows to be deleted is 1000000, that is, limit_number = 1000000. Corresponding process Figure 3 The sequence number is 1.
[0125] 2) Query the total number of rows in each data node of table TABLE_A and record the structure and data of node_number_map in the map container as shown in Table 1. Figure 3 The serial number 2 in .
[0126] 3) Calculate the ratio of limit_number to the maximum total number of rows in node_number_map, that is, p = 1000000 / 109000 = 9.2. Corresponding process Figure 3 The serial number 3 in .
[0127] 4) Ratio threshold (0.0001). Corresponding to step Figure 3 number 4 in the process
[0128] 5) The cumulative value of the total number of rows in node_number_map (i.e., the target cumulative value) = 100000 + 101000 + 102000 +... + 109000 = 1055000. Therefore, limit_number < the cumulative value of the total number of rows in node_number_map. Corresponding to step Figure 3 number 21 in the process
[0129] 6) Calculate the number of rows to be deleted for each data node in node_number_map (i.e., the second target number of rows) as follows: (Corresponding to step Figure 3 number 31 in the process.)
[0130] The number of rows to be deleted for 'data node 1' = (100000 / 1055000) * 1000000 = 94786
[0131] The number of rows to be deleted for 'data node 2' = (101000 / 1055000) * 1000000 = 95734
[0132] The number of rows to be deleted for 'data node 3' = (102000 / 1055000) * 1000000 = 96682 ...........
[0133] The number of rows to be deleted for 'data node 10' = (109000 / 1055000) * 1000000 = 103317
[0134] 7) Adjust the number of rows to be deleted for the data node with the maximum number of data rows (i.e., 'data node 10'), (Corresponding to step Figure 3 number 32 in the process.)
[0135] The number of rows to be deleted for 'data node 10' = 1000000 - (94786 + 95734 + 96682 +..) = 103325 (Note that this data is an example data and not obtained through precise calculation).
[0136] 8) Generate the delete statement for each data node based on the calculated number of rows to be deleted for each data node and send it to its respective data node for parallel execution. That is, the delete statements for each data node are as follows: (Corresponding to step Figure 3 number 33 in the process.)
[0137] The delete statement for 'data node 1' is: DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 94786
[0138] The delete statement for 'data node 2' is: DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 95734
[0139] The delete statement for 'data node 3' is: DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 96682 ...........
[0140] The delete statement for 'data node 10' is: DELETE FROM TABLE_A WHERE rq<'2020-01-01' LIMIT 103325
[0141] 9) Collect the number of rows successfully deleted from each data node, and remove the data nodes whose number of rows successfully deleted is less than the number of rows to be deleted from node_number_map. Assuming that only the number of rows successfully deleted by 'data node 2' (5734) is less than the number of rows to be deleted (95734), then remove 'data node 2' from node_number_map. (This means: 'data node 2' has no data that meets the conditions to be deleted). Corresponding process Figure 3 Serial number 34 in.
[0142] 10) Recalculate limit_number = 1000000-(94768+5734+96682+103325) = 90000. Corresponding process Figure 3 Serial number 35 in the.
[0143] 11) limit_number = 90000 means that 90000 rows of data need to be deleted from the new node_number_map, that is, 6) to 10) are repeated until limit_number = 0 or node_number_map is empty. Corresponding process Figure 3 Serial number 36 in the.
[0144] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0145] Embodiment 2:
[0146] Corresponding to the data deletion method of a distributed database described in the above embodiment, Figure 4 A structural block diagram of a data deletion device for a distributed database provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.
[0147] Reference Figure 4 The distributed database data deletion device 4 includes: a first data deletion statement receiving module 41, a first target row number determination module 42, a target deletion method determination module 43, and a data deletion module 44. Among them:
[0148] The first data deletion statement receiving module 41 is used to receive the first data deletion statement, wherein the first data deletion statement includes a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores the data of the target table in the form of rows, and the target data node is a data node storing the target table.
[0149] The first target row number determination module 42 is used to determine a first target row number, where the first target row number is the maximum value of the total number of rows corresponding to the data stored in each of the target data nodes in the target table.
[0150] The target deletion method determination module 43 is used to determine the target deletion method according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion method is a serial deletion method or a parallel deletion method. The serial deletion method refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion method refers to deleting the data of the target table stored in each of the target data nodes at the same time.
[0151] The data deletion module 44 is used to delete the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion method.
[0152] In the embodiment of the present application, after receiving the first data deletion statement, the maximum value of the total number of rows of the target table data stored in each target data node is determined according to the unique identifier of the target table included in the first data deletion statement, and the first target number of rows is obtained, and the target deletion method is determined according to the total number of rows to be deleted and the first target number of rows included in the first data deletion statement, and finally the data of the target table stored in the target data node is deleted according to the total number of rows to be deleted and the target deletion method. Since the relationship between the maximum value of the total number of rows of the target table data stored in each target data node and the total number of rows to be deleted can reflect the number of target data nodes that need to delete the data of the target table, therefore, the accuracy of the determined target deletion method can be improved according to the total number of rows to be deleted and the first target number of rows. And since a more accurate target deletion method is conducive to improving the efficiency of deleting data, therefore, the data deletion method of the distributed database provided in the embodiment of the present application is conducive to improving the efficiency of deleting a specified number of rows in the distributed database.
[0153] In some embodiments, the target deletion method determination module 43 includes:
[0154] The serial deletion determination unit is used to determine that the target deletion mode is a serial deletion mode if the ratio of the total number of rows to be deleted to the first target number of rows is less than a preset ratio threshold.
[0155] The preset ratio threshold is a value less than 0.001. For example, the ratio threshold can be set to 0.0001, that is, the preset ratio threshold cannot be too large.
[0156] The parallel deletion determination unit is used to determine that the target deletion mode is a parallel deletion mode if the ratio of the total number of rows to be deleted to the first target number of rows is not less than a preset ratio threshold.
[0157] In some embodiments, when the target deletion method is a serial deletion method, the data deletion module 44 includes:
[0158] The sorting result generating unit is used to sort the total number of rows corresponding to the data stored in the target table at each of the target data nodes in order from high to low to obtain a sorting result.
[0159] A one-by-one deletion unit is used to delete the data of the target table stored in the target data node from front to back according to the sorting result, until the stop deletion condition is met. The stop deletion condition includes: the cumulative value of the number of rows of deleted data is equal to the total number of rows to be deleted or all target data nodes have deleted the data corresponding to the target table stored therein.
[0160] In some embodiments, when the target deletion mode is a parallel deletion mode, the data deletion module 44 includes:
[0161] The target cumulative value calculation unit is used to calculate the cumulative value of the total number of rows corresponding to the data stored in the target table at each of the target data nodes to obtain the target cumulative value.
[0162] The data direct deletion unit is used to directly delete the data stored in each of the target data nodes of the target table in a parallel deletion manner if the total number of rows to be deleted is not less than the target accumulated value.
[0163] The data indirect deletion unit is used to first determine the second target number of rows corresponding to each of the above target data nodes if the above total number of rows to be deleted is less than the above target cumulative value, and then use the above second target number of rows as the basis to delete the data in the target table of each of the above target data nodes in a parallel deletion manner, wherein each of the above second target numbers of rows is the total number of rows of data in the target table that needs to be deleted at each of the above target data nodes, which is determined according to the above total number of rows to be deleted.
[0164] In some embodiments, when the data direct deletion unit directly deletes the data of the target table stored in each of the target data nodes in a parallel deletion manner, it is specifically used to:
[0165] Detecting whether the first data deletion statement includes a conditional clause;
[0166] If the first data deletion statement includes the conditional clause, a second data deletion statement is generated, wherein the second data deletion statement does not include the total number of rows to be deleted corresponding to the target table;
[0167] According to the second data deletion statement, the data of the corresponding target table is deleted in parallel at each of the target data nodes;
[0168] If the first data deletion statement does not include the conditional clause, a third data deletion statement is generated, wherein the third data deletion statement is used to delete the data of the entire target table stored in the target data node;
[0169] According to the third data deletion statement, the data of the corresponding target table is deleted in parallel at each of the target data nodes.
[0170] In some embodiments, when determining the second target number of rows corresponding to each of the target data nodes, the data indirect deletion unit is specifically configured to:
[0171] According to the total number of rows corresponding to the data stored in the target table at each of the target data nodes and the total number of rows to be deleted, the total number of rows of data in the target table to be deleted at each of the target data nodes is determined respectively to obtain the second target number of rows corresponding to each of the target data nodes.
[0172] In some embodiments, respectively determining the total number of rows of data in the target table to be deleted at each of the target data nodes to obtain the second target number of rows corresponding to each of the target data nodes includes:
[0173] Determine the total number of rows of data in the target table that needs to be deleted at each of the target data nodes, and obtain an initial second target number of rows corresponding to each of the target data nodes;
[0174] Count the sum of the initial second target row numbers mentioned above;
[0175] Determine whether the initial second target number of rows needs to be corrected according to the sum and the total number of rows to be deleted;
[0176] If correction is required, the initial second target row number corresponding to one of the target data nodes is corrected to obtain a corrected second target row number corresponding to one of the target data nodes;
[0177] According to the corrected second target number of rows and each initial second target number of rows that does not need to be corrected, the final second target number of rows corresponding to each of the target data nodes is determined.
[0178] In this embodiment, when the second target number of rows corresponding to each target data node is determined by rounding down, if the sum is not equal to the total number of rows to be deleted, the difference between the sum and the total number of rows to be deleted will not be very large. At this time, in order to reduce the number of corrections, only the second target number of rows corresponding to one of the target data nodes is corrected. Of course, the target data nodes corresponding to the corrected second target number of rows will perform data deletion operations according to the corrected second target number of rows, and the target data nodes corresponding to the second target number of rows that do not need to be corrected will perform data deletion operations according to the originally determined second target number of rows.
[0179] In some embodiments, when correcting the second target row number corresponding to one of the target data nodes, the second target row number of the target data node corresponding to the maximum value of the total number of rows corresponding to the data of the stored target table is corrected, and the corrected second target row number is determined specifically according to the following formula: the total number of rows to be deleted - (the sum of the second target row numbers corresponding to other target data nodes except the target data node that needs to be corrected).
[0180] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0181] Embodiment three:
[0182] Figure 5 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: at least one processor 50 ( Figure 5 Only one processor is shown in the figure), a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50, wherein the processor 50 implements the steps in any of the above-mentioned method embodiments when executing the computer program 52.
[0183] The electronic device 5 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The electronic device may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 5 and does not constitute a limitation on the electronic device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0184] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0185] In some embodiments, the memory 51 may be an internal storage unit of the electronic device 5, such as a hard disk or memory of the electronic device 5. In other embodiments, the memory 51 may also be an external storage device of the electronic device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the electronic device 5. The memory 51 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program. The memory 51 may also be used to temporarily store data that has been output or is to be output.
[0186] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0187] An embodiment of the present application also provides a network device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, wherein the processor implements the steps in any of the above-mentioned method embodiments when executing the computer program.
[0188] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0189] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0190] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / electronic device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, RandomAccess Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0191] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0192] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0193] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0194] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0195] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for deleting data in a distributed database, characterized in that: include: Receive a first data deletion statement, the first data deletion statement including a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores data of the target table in the form of rows, and the target data node is a data node storing the target table; Determine a first target number of rows, where the first target number of rows is the maximum value of the total number of rows corresponding to the data stored in each of the target data nodes of the target table; Determining a target deletion mode according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion mode is a serial deletion mode or a parallel deletion mode, the serial deletion mode refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion mode refers to deleting the data of the target table stored in each target data node at the same time; Deleting the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion method; The determining the target deletion method according to the total number of rows to be deleted and the first target number of rows includes: If the ratio of the total number of rows to be deleted to the first target number of rows is less than a preset ratio threshold, determining that the target deletion mode is a serial deletion mode; If the ratio of the total number of rows to be deleted to the first target number of rows is not less than a preset ratio threshold, it is determined that the target deletion mode is a parallel deletion mode.
2. The method for deleting data in a distributed database according to claim 1, characterized in that: In the case where the target deletion mode is a serial deletion mode, deleting the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion mode includes: Sorting the total number of rows corresponding to the data stored in each of the target data nodes of the target table in descending order to obtain a sorting result; According to the sorting result, the data of the target table stored in the target data nodes are deleted from front to back until a stop deletion condition is met, wherein the stop deletion condition includes: the cumulative value of the number of rows of deleted data is equal to the total number of rows to be deleted or all target data nodes have deleted the data corresponding to the target table stored therein.
3. The method for deleting data in a distributed database according to claim 1, characterized in that: In the case where the target deletion mode is a parallel deletion mode, deleting the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion mode includes: Calculate the cumulative value of the total number of rows corresponding to the data stored in each of the target data nodes of the target table to obtain a target cumulative value; If the total number of rows to be deleted is not less than the target accumulated value, directly delete the data stored in each target data node of the target table in a parallel deletion manner; If the total number of rows to be deleted is less than the target cumulative value, first determine the second target number of rows corresponding to each target data node, and then use the second target number of rows as a basis to delete the data in the target table of each target data node in a parallel deletion manner, wherein each second target number of rows is the total number of rows of data in the target table that needs to be deleted at each target data node, which is determined according to the total number of rows to be deleted.
4. The method for deleting data in a distributed database as claimed in claim 3, characterized in that: The directly deleting the data of the target table stored in each of the target data nodes in a parallel deletion manner includes: Detecting whether the first data deletion statement includes a conditional clause; If the first data deletion statement includes the conditional clause, generating a second data deletion statement, wherein the second data deletion statement does not include the total number of rows to be deleted corresponding to the target table; According to the second data deletion statement, deleting the data of the corresponding target table in parallel at each of the target data nodes; If the first data deletion statement does not include the conditional clause, a third data deletion statement is generated, wherein the third data deletion statement is used to delete the data of the entire target table stored in the target data node; According to the third data deletion statement, data of the corresponding target table is deleted in parallel at each of the target data nodes.
5. The method for deleting data in a distributed database as claimed in claim 3, characterized in that: The determining the second target number of rows corresponding to each of the target data nodes includes: According to the total number of rows corresponding to the data stored in each target data node of the target table and the total number of rows to be deleted, the total number of rows of data in the target table to be deleted at each target data node is determined respectively, and a second target number of rows corresponding to each target data node is obtained.
6. The method for deleting data in a distributed database as claimed in claim 5, characterized in that: The respectively determining the total number of rows of data in the target table to be deleted at each of the target data nodes to obtain a second target number of rows corresponding to each of the target data nodes includes: Determine the total number of rows of data in the target table that need to be deleted at each target data node, and obtain an initial second target number of rows corresponding to each target data node; Counting the sum of the initial second target row numbers; Determining whether the initial second target number of rows needs to be corrected according to the sum and the total number of rows to be deleted; If correction is required, the initial second target row number corresponding to one of the target data nodes is corrected to obtain a corrected second target row number corresponding to one of the target data nodes; According to the corrected second target number of rows and each initial second target number of rows that does not need to be corrected, a final second target number of rows corresponding to each target data node is determined.
7. A data deletion device for a distributed database, characterized in that: include: A first data deletion statement receiving module, configured to receive a first data deletion statement, wherein the first data deletion statement includes a unique identifier of a target table and a total number of rows to be deleted corresponding to the target table, wherein each target data node in the distributed database stores data of the target table in the form of rows, and the target data node is a data node storing the target table; A first target row number determination module, used to determine a first target row number, where the first target row number is the maximum value of the total number of rows corresponding to the data stored in each of the target data nodes of the target table; a target deletion mode determination module, configured to determine a target deletion mode according to the total number of rows to be deleted and the first target number of rows, wherein the target deletion mode is a serial deletion mode or a parallel deletion mode, wherein the serial deletion mode refers to deleting the data of the target table stored in the target data node one by one, and the parallel deletion mode refers to deleting the data of the target table stored in each target data node at the same time; A data deletion module, used to delete the data of the target table stored in the target data node according to the total number of rows to be deleted and the target deletion method; The target deletion mode determination module includes: A serial deletion determination unit, configured to determine that the target deletion mode is a serial deletion mode if the ratio of the total number of rows to be deleted to the first target number of rows is less than a preset ratio threshold; The parallel deletion determination unit is used to determine that the target deletion mode is a parallel deletion mode if the ratio of the total number of rows to be deleted to the first target number of rows is not less than a preset ratio threshold.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
device FOR FIXING A WHEEL ON THE LEGS OR SUPPORTS OF CHAIRS POL CUTTERS TROLLEYS, CONTAINERS AND SIMILAR
IT1000000B1
Data processing method and device, equipment and storage medium
CN112765169A