Data updating method and device, storage medium and electronic equipment
By pre-saving equivalence classes in the database system and updating the target equivalence classes according to the changes in the target data, the query efficiency problem when the database instance changes is solved, achieving low-cost query optimization and performance improvement.
Patent Information
- Application Number
- CN202510638205.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-16
- Publication Date
- 2025-10-31
AI Technical Summary
Existing technologies struggle to effectively leverage weak equivalence relations to improve query efficiency in database systems, especially when database instances are constantly changing. How to update query equivalence classes at low cost to improve query performance is a pressing issue that needs to be addressed.
By pre-saving equivalence classes, the target data that has changed in the database is identified, and the target equivalence classes are updated according to the way the target data has changed. Only the changed equivalence classes are updated, instead of rebuilding all equivalence classes, thus reducing resource consumption by using a bypass query mechanism.
It effectively reduced the pressure on the database system, improved query efficiency, reduced the need to rebuild equivalence classes, and enhanced the overall performance of the database system.
Smart Images

Figure CN120873007A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a data update method, apparatus, storage medium, and electronic device. Background Technology
[0002] Currently, database systems are widely used in various fields, and how to improve the query efficiency of database systems is an eternal topic in database technology.
[0003] Query optimization is a crucial technique for improving query efficiency, and multi-query optimization focuses on reducing redundant query execution by identifying and utilizing overlapping parts between multiple query statements, thereby improving overall performance. Therefore, query equivalence verification methods for determining whether the results of two queries are identical are key techniques in multi-query optimization.
[0004] Weak equivalence relations are defined as follows: different queries do not have an equivalence relation, but when querying the data currently stored in the database system (i.e., within the current database instance), these different queries will yield the same results. How to leverage weak equivalence relations and improve query efficiency at low cost as the database instance continuously changes is a problem that urgently needs to be solved. Summary of the Invention
[0005] This specification provides a data update method, apparatus, storage medium, and electronic device to partially solve the problems existing in the prior art.
[0006] The embodiments in this specification adopt the following technical solutions:
[0007] This specification provides a data update method that pre-stores several equivalence classes, where the query statements within an equivalence class have weak equivalence relations; the method includes:
[0008] Identify the data in the database that has been changed and use it as the target data;
[0009] Based on the target data and the query statements contained in each equivalence class, determine the equivalence class that matches the target data, and use it as the target equivalence class;
[0010] The target equivalence class is updated according to the way the target data is changed.
[0011] This specification provides a data updating device, the device comprising:
[0012] The storage module is used to pre-store several equivalence classes, where the query statements contained in an equivalence class have weak equivalence relations.
[0013] The data determination module is used to identify the data in the database that has been changed, and use it as the target data.
[0014] The equivalence class determination module is used to determine the equivalence class that matches the target data based on the target data and the query statements contained in each equivalence class, and use it as the target equivalence class;
[0015] The update module is used to update the target equivalence class according to the change method of the target data.
[0016] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described data update method.
[0017] This specification provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described data update method.
[0018] The above-described at least one technical solution adopted in the embodiments of this specification can achieve the following beneficial effects:
[0019] This specification discloses a data update method. When data stored in a database changes, the method identifies the target data that has changed and determines the target equivalence class that matches the target data. Based on the change method of the target data, the target equivalence class is updated. This method only requires updating the target equivalence class, making the updated equivalence classes adaptable to the changed database, without needing to rebuild all equivalence classes, effectively reducing the pressure on the database system. Attached Figure Description
[0020] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:
[0021] Figure 1 A flowchart of a data query method provided in the embodiments of this specification;
[0022] Figure 2 This is a flowchart of a data update method provided in an embodiment of this specification;
[0023] Figure 3 A schematic diagram of a data update device provided in the embodiments of this specification;
[0024] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this specification. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0026] Generally speaking, the verification of whether two query statements are equivalent is very strict. It requires that the query results of the two query statements are the same in any database instance (i.e., regardless of the data distribution stored in the database) before it can be determined that the two query statements are equivalent.
[0027] For example, consider two queries: `SELECT * FROM Employees WHERE salary > 5000 AND department = 'IT'` and `SELECT * FROM Employees WHERE department = 'IT' AND salary > 5000`. Logically, the two queries are simply reversed in the order of the filter conditions "salary > 5000" and "department = 'IT'". The results of these two queries will be identical in any database instance; therefore, they are equivalent. Thus, these two queries only need to be executed once, improving query efficiency.
[0028] However, in real-world applications, some queries do not possess equivalence, yet their results are identical in a specific database instance. This specification will break away from the aforementioned definition of equivalence and define a new type of equivalence, which we will call weak equivalence. For example, consider the queries `SELECT * FROM Employees WHERE salary > 3000` and `SELECT * FROM Employees WHERE salary > 5000`. Logically, these queries do not possess equivalence, but if the database instance is as shown in Table 1, the results of these two queries will still be the same.
[0029] ID salary 001 2000 002 6000 003 7000
[0030] Table 1
[0031] As shown in Table 1 above, both queries return two records with IDs 002 and 003. For queries with weak equivalence relationships, the following approach can be used: Figure 1 The method shown is used to query data.
[0032] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0033] Figure 1 A flowchart of a data query method provided in this specification includes the following steps:
[0034] S100: Retrieves the filter conditions from the query statement to be executed.
[0035] In the embodiments of this specification, the following are used: Figure 1 The data query execution entity shown can be a database system, specifically an electronic device, such as a server, that supports or hosts the database system. The following explanation uses a server as an example only.
[0036] The server can pre-store several equivalence classes. Specifically, it can determine whether there are weak equivalence relations between the historically received queries, group queries with weak equivalence relations into the same equivalence class, and group queries without weak equivalence relations into different equivalence classes.
[0037] In this specification, the weak equivalence relation described in the embodiments refers to the following: different query statements do not have an equivalence relation, but when querying the data currently stored in the database system, that is, under the current database instance, the query results of these different query statements are the same.
[0038] Therefore, the server can save all the query statements received in history and the query results obtained by executing these query statements, and identify the query statements with the same query results as query statements with weak equivalence relations, so as to divide equivalence classes accordingly.
[0039] In addition, the server also needs to cache the query results corresponding to each equivalence class. Since the query statements in an equivalence class have weak equivalence relationships with each other, that is, under the current database instance, the query results of the query statements in an equivalence class are all the same. Therefore, when the server caches the query results corresponding to an equivalence class, it can cache only the query result of any one query statement in that equivalence class as the query result corresponding to that equivalence class.
[0040] To facilitate the server's partitioning and storage of equivalence classes, the concept of a query grid is introduced in the embodiments of this specification. A query grid is essentially a storage space composed of several storage units, called cells, each storing a query statement. The server can store historically received query statements in their respective cells and, based on whether the query statements have weak equivalence relations, divide these cells into equivalence classes. Query statements stored in cells within an equivalence class have weak equivalence relations. Then, for each equivalence class, the query results of any query statement stored in any cell within that equivalence class are cached. A mapping relationship is established between the cached query results and the equivalence class, thus realizing the storage of equivalence classes and the caching of corresponding query results.
[0041] When the server receives a query statement to be executed, it can obtain the filtering conditions in the query statement. The filtering conditions described in the embodiments of this specification include, but are not limited to, the WHERE clause in the query statement, that is, the filtering condition predicate in the query statement.
[0042] For example, if the received query statement to be executed is SELECT * FROM Employees WHERE salary>4000, then "salary>4000" is the filter condition in the query statement to be executed.
[0043] S102: Based on the filtering conditions, determine whether the query statement to be executed belongs to any of the pre-saved equivalence classes. If yes, proceed to step S104; otherwise, proceed to step S106.
[0044] After the server uses the above query lattice to partition and store equivalence classes, it can further organize each equivalence class. For a database instance, if the query range of query statement Q1 is greater than that of query statement Q2, but these two query statements have a weak equivalence relationship under this database instance, then generally, query statements whose query range is between Q1 and Q2 also have a weak equivalence relationship with Q1 and Q2. Let's take Table 1 as an example for further explanation.
[0045] Assuming the database instance is shown in Table 1, Q1 is SELECT * FROM Employees WHERE salary > 3000, and Q2 is SELECT * FROM Employees WHERE salary > 5000. The query range of Q1 is greater than that of Q2, but in the database instance shown in Table 1, the two have a weak equivalence relationship.
[0046] Assuming Q3 is defined as SELECT * FROM Employees WHERE salary > 4000, and the query range is between Q1 and Q2, then as shown in Table 1, Q3 also has a weak equivalence relationship with both Q1 and Q2.
[0047] Therefore, the largest query range among all queries in an equivalence class can be determined as the upper bound of the equivalence class, and the smallest query range can be determined as the lower bound of the equivalence class.
[0048] In step S102, after the server obtains the filtering conditions from the received query statement to be executed, it can determine whether the query statement to be executed belongs to a pre-saved equivalence class based on the pre-saved upper and lower bounds of each equivalence class and the filtering conditions of the query statement to be executed. Specifically, for each pre-saved equivalence class, the server can determine whether the filtering conditions of the query statement to be executed are contained within the upper bound of the equivalence class and the lower bound of the equivalence class. If so, the query statement to be executed is determined to belong to the equivalence class; otherwise, the query statement to be executed is determined not to belong to the equivalence class.
[0049] It should be noted that if the statement to be executed belongs to an equivalence class, it means that the query statement to be executed must have a weak equivalence relationship with the query statements in that equivalence class. However, if the statement to be executed does not belong to an equivalence class, it does not necessarily mean that the query statement to be executed does not have a weak equivalence relationship with the query statements in that equivalence class. Whether a weak equivalence relationship exists can only be determined after querying the statement to be executed and obtaining the query results.
[0050] Continuing with the previous example, since Q1 and Q2 have a weak equivalence relation in the database instance shown in Table 1, the server can group Q1 and Q2 into the same equivalence class, using the query range of Q1 (greater than 3000) as the upper bound of this equivalence class and the query range of Q2 (greater than 5000) as the lower bound. Since the query range of Q3 is greater than 4000, it is included in both the upper and lower bounds of this equivalence class; therefore, Q3 belongs to this equivalence class.
[0051] Assuming Q4 is `SELECT * FROM Employees WHERE salary > 5500` and Q5 is `SELECT * FROM Employees WHERE salary > 2200`, then:
[0052] Although Q4 is contained in the upper bound of the equivalence class, it is not contained in the lower bound of the equivalence class. Therefore, Q4 does not belong to the equivalence class.
[0053] Although Q5 contains the lower bound of the equivalence class, it is not contained in the upper bound of the equivalence class, therefore Q5 does not belong to the equivalence class.
[0054] S104: Return the pre-saved query results corresponding to the equivalence class as the query results of the query statement to be executed.
[0055] In the embodiments of this specification, if the server determines that the query statement to be executed received in step S100 belongs to a pre-saved equivalence class, then since the query result of the query statement to be executed in the current database instance must be the same as the query result of any query statement in the equivalence class, the pre-cached query result corresponding to the equivalence class can be returned directly without executing the query statement to be executed. Through the bypass query mechanism shown in step S104, the resources required to execute the query can be effectively reduced and the query efficiency can be improved.
[0056] S106: Execute the query statement to be executed, obtain the query result and return it, and update the pre-saved equivalence class according to the query result.
[0057] If the server determines that the query statement to be executed received in step S100 does not belong to any pre-saved equivalence class, then the conclusion that "the query statement to be executed has a weak equivalence relationship with the query statement in a pre-saved equivalence class" cannot be proven or disproven solely based on the filtering conditions (or their first-order logical expressions) of the query statement to be executed and the upper / lower bounds (or their first-order logical expressions) of each equivalence class. Therefore, the server can only execute the query statement to be executed, obtain the query result, and then return the query result.
[0058] Furthermore, the equivalence classes pre-saved in the embodiments of this specification are not static even when the data stored in the database remains unchanged, but rather change dynamically as the query statement to be executed is continuously executed. After executing step S106, that is, after the query statement to be executed is executed and the query result is obtained, the pre-saved equivalence classes can be updated based on the obtained query result and the query results corresponding to each pre-cached equivalence class.
[0059] Specifically, the server can use the query results corresponding to each equivalence class that are saved in advance as cached query results, compare the query results obtained by executing the query statement to be executed with each cached query result, and update the saved equivalence class according to the comparison results.
[0060] If any cached query result is identical to the result obtained from executing the query statement to be executed, then that identical cached query result is selected as the chosen query result. The query statement to be executed is added to the equivalence class corresponding to the selected query result, and the upper or lower bound of the equivalence class corresponding to the selected query result is updated according to the filtering conditions of the query statement to be executed. If the filtering conditions of the query statement to be executed include the upper bound of the equivalence class corresponding to the selected query result, then the upper bound of the equivalence class corresponding to the selected query result is updated to the filtering conditions of the query statement to be executed. If the filtering conditions of the query statement to be executed include the lower bound of the equivalence class corresponding to the selected query result, then the lower bound of the equivalence class corresponding to the selected query result is updated to the filtering conditions of the query statement to be executed.
[0061] Continuing with the previous example, the upper bound of the equivalence class formed by Q1 and Q2 is greater than 3000, and the lower bound is greater than 5000. Q3 belongs to this equivalence class, so the query result corresponding to this equivalence class can be returned directly without updating the equivalence class. As for Q4, although it does not belong to this equivalence class, according to Table 1, in the database instance shown in Table 1, the query result for Q4 is still the two data points with IDs 002 and 003, the same as Q1 and Q2. Therefore, Q4 actually has a weak equivalence relationship with Q1 and Q2. After the server executes a query on Q4 and returns the query result (i.e., the two data points with IDs 002 and 003), Q4 can be added to this equivalence class. At this point, since the equivalence class contains Q1, Q2, and Q4, and the query range of Q4 (greater than 5500) is contained within the lower bound of the equivalence class (greater than 5000), the minimum query range in this equivalence class should now be greater than 5500. Therefore, the query range of Q4 can be redefined as the lower bound of the equivalence class. The query statements stored in the two cells of this equivalence class are no longer Q1, Q2, and Q4.
[0062] Similarly, for Q5, although it does not belong to this equivalence class, as shown in Table 1, in the database instance shown in Table 1, the query result for Q5 is still the two data points with IDs 002 and 003, the same as Q1, Q2, and Q4. Therefore, Q5 actually has a weak equivalence relationship with Q1, Q2, and Q4. After the server executes a query on Q5 and returns the query result (i.e., the two data points with IDs 002 and 003), Q5 can be added to this equivalence class. At this time, since this equivalence class contains Q1, Q2, Q4, and Q5, and the query range of Q5 (greater than 2200) includes the upper bound of this equivalence class (greater than 3000), the largest query range in this equivalence class should be greater than 2200. Therefore, the query range of Q5 can be redefined as the upper bound of this equivalence class.
[0063] As can be seen, the upper / lower bounds of this equivalence class have been expanded from the original greater than 3000 to greater than 5000 to the current greater than 2200 to greater than 5500. Subsequent queries to be executed are more likely to belong to this equivalence class. Therefore, with the execution of Q4 and Q5, the query efficiency of the database system will continue to improve.
[0064] If none of the cached query results are identical to the result obtained from executing the query statement to be executed, a new equivalence class can be created, and the query statement to be executed can be added to the new equivalence class. Based on the filtering conditions of the query statement to be executed, the upper and lower bounds of the new equivalence class can be determined. Specifically, the filtering conditions of the query statement to be executed can be used as both the upper and lower bounds of the new equivalence class. At the same time, the query results of the query statement to be executed are cached, and a mapping relationship is established between the cached query results and the new equivalence class.
[0065] Continuing with the previous example, the equivalence class now contains queries Q1, Q2, Q4, and Q5. Q5's filter condition is the upper bound, and Q4's filter condition is the lower bound. There are no other equivalence classes besides this one in the query cells. Suppose the server receives a query Q6 to be executed: `SELECT * FROM Employees WHERE salary > 6300`. Since Q6 does not belong to this equivalence class, and the query result for Q6 is only one record with ID 003, which differs from the pre-cached query result for this equivalence class, the server needs to create a new equivalence class and store Q6 in a cell of this new equivalence class. Because this new equivalence class only contains one query, Q6, the filter condition for Q6 can be used as both the upper and lower bounds of the new equivalence class. In other words, only if a subsequent received query statement is completely equivalent to Q6 will the server determine that it belongs to the newly created equivalence class. Otherwise, it can only wait for the subsequent received query statement to be executed, and only when the query result obtained is the same as the query result corresponding to the newly created equivalence class, will the upper or lower bound of the newly created equivalence class be updated according to the filtering conditions of the subsequent received query statement.
[0066] As can be seen from the above data query process, this process relies heavily on the construction of equivalence classes. Whether each query statement in an equivalence class has a weak equivalence relation depends entirely on the current database instance, i.e., the data currently stored in the database. Once the data stored in the database changes, the weak equivalence relations between the query statements may change. Continuing with the previous example, if a record with "ID 004, salary 4000" is added to the database instance shown in Table 1, as shown in Table 2, then Q1 and Q2, which originally had a weak equivalence relation, will no longer have a weak equivalence relation. This is because the query result for Q1 is now three records with IDs 002, 003, and 004, while the query result for Q2 is two records with IDs 002 and 003.
[0067] ID salary 001 2000 002 6000 003 7000 004 4000
[0068] Table 2
[0069] Therefore, the embodiments of this specification can be implemented as follows: Figure 2 The method shown aims to keep the original equivalence class unchanged as much as possible when the database instance changes, that is, to update the original equivalence class as little as possible, so that the updated equivalence class can still be applied to the changed database instance.
[0070] Figure 2 A flowchart of a data update method provided in this specification includes the following steps:
[0071] S200: Identify the data in the database that has been changed, and use it as the target data.
[0072] In the embodiments described in this specification, the data in the database can be modified in any of the following ways: adding, deleting, or altering. That is, the target data can be newly added data, deleted data, or altered data in the database.
[0073] S202: Based on the target data and the query statements contained in each equivalence class, determine the equivalence class that matches the target data, and use it as the target equivalence class.
[0074] In the embodiments of this specification, whether an equivalence class matches target data can be determined based on whether there is a query statement in the equivalence class that satisfies a specified condition. The specified condition is that when the query statement is used to query in the database after the data has changed, the query result includes the target data. If an equivalence class contains at least one query statement that satisfies the specified condition, then the equivalence class matches the target data; if the equivalence class contains no query statements that satisfy the specified condition, then the equivalence class does not match the target data.
[0075] Continuing with the previous example, since the equivalence class contains query statements Q1, Q2, Q4, and Q5, and Q1 and Q5 satisfy the specified conditions, while Q2 and Q4 do not, there is a query statement in this equivalence class that satisfies the specified conditions and matches the target data (data with ID 004).
[0076] It should be noted that there may be more than one equivalence class that matches a target data. As long as there is a query statement in an equivalence class that meets the above-specified conditions, that equivalence class is the target equivalence class that matches the target data.
[0077] S204: Update the target equivalence class according to the change method of the target data.
[0078] The reason why changes to target data in a database can affect the weak equivalence relationships between queries within an equivalence class is that the changed target data may influence the query results within that class. For example, in the case of Q1 and Q2 above, the addition of target data with ID 004 changes the query result for Q1, thus breaking the original weak equivalence relationship between Q1 and Q2. Therefore, when updating the target equivalence class in this embodiment, the main consideration is which query results have changed due to the change in the target data. The equivalence classes whose query results have changed are the ones that may need to be updated.
[0079] Therefore, the target equivalence classes that match the target data determined in step S202 are the equivalence classes that contain the query statements whose query results have changed. These equivalence classes are the ones that we may need to update. On the other hand, the query statements contained in the equivalence classes that do not match the target data have not changed due to the change in the target data. Therefore, there is no need to update these equivalence classes.
[0080] Furthermore, updating the target equivalence class mainly involves the following two aspects:
[0081] First, update the query statements in the target equivalence class. Since the upper / lower bound of an equivalence class depends on the query statements with the largest and smallest ranges within that equivalence class, updating the query statements in the target equivalence class also means updating the upper or lower bound of the target equivalence class.
[0082] 2. Update the query results corresponding to the target equivalence class (hereinafter referred to as the target query results).
[0083] The method of updating the target equivalence class varies depending on how the target data in the database is modified. These will be explained separately below.
[0084] Scenario 1: No target equivalence class matching the target data was determined in step S202. This indicates that the change to the target data in the database has not affected the query results of any query statement in any equivalence class. Therefore, regardless of the method of change of the target data, all equivalence classes can remain unchanged, and no equivalence class will be updated.
[0085] Scenario 2: The change method for the target data is deletion. In this case, updating the target query results corresponding to the target equivalence class can be done by deleting the target data from the target query results. This is because if the change method for the target data is deletion, it means that the original query results of each query statement in the target equivalence class contained the target data. After deleting the target data from the database, the query results of each query statement in the target equivalence class should no longer contain the target data. Therefore, the target data can be directly deleted from the target query results.
[0086] The way to update the query statement in the target equivalence class depends on the target query result after deleting the target data.
[0087] Specifically, if the target query result is an empty set after deleting the target data, it means that the query statements in the target equivalence class can no longer retrieve any data, and the target equivalence class will also lose its meaning. The target equivalence class can be deleted directly, that is, all query statements in the target equivalence class can be deleted.
[0088] If, after deleting the target data, the target query result is not an empty set, but there exists another equivalence class (hereinafter referred to as the equivalence class to be merged) with the same query result as the target query result after deleting the target data, it indicates that the query statements in the target equivalence class and the query statements in the equivalence class to be merged have a weak equivalence relationship after the target data was deleted from the database. Therefore, the target equivalence class and the equivalence class to be merged can be merged into one equivalence class. The merged equivalence class contains both the original query statements from the target equivalence class and the original query statements from the equivalence class to be merged. Furthermore, the upper bound of the merged equivalence class is the query range corresponding to the query statement with the largest query range contained within it, and the lower bound is the query range corresponding to the query statement with the smallest query range contained within it.
[0089] If the target query result is not an empty set after deleting the target data, and there is no corresponding equivalence class in other equivalence classes with the same query result as the target query result after deleting the target data, then the query statement in the target equivalence class remains unchanged, that is, the upper / lower bound of the target equivalence class remains unchanged.
[0090] Scenario 3: The target data is added. For newly added target data, its impact on the query statement in the target equivalence class is one of two things: either the target data is added to the query result, in which case the query statement satisfies the specified conditions mentioned above, such as Q1 in the example above; or the query result remains unchanged, without adding the target data, in which case the query statement does not satisfy the specified conditions mentioned above, such as Q2 in the example above.
[0091] If all queries in the target equivalence class satisfy the specified conditions, it means that the query results remain the same after the target data is added to the database, indicating a weak equivalence relationship. Therefore, updating the queries in the target equivalence class involves keeping all queries unchanged, i.e., maintaining the upper / lower bounds of the target equivalence class. Updating the target query results corresponding to the target equivalence class involves directly adding the target data to the query results corresponding to that target equivalence class.
[0092] If not all queries in the target equivalence class satisfy the specified conditions, but some do not, it means that not all queries in the target equivalence class have a weak equivalence relation. In this case, the target equivalence class needs to be split based on the queries that satisfy and do not satisfy the specified conditions.
[0093] Specifically, when splitting the target equivalence class, the equivalence class formed by query statements that do not meet the specified conditions can be identified as the first equivalence class split from the target equivalence class. The upper bound of the first equivalence class is determined based on the query statement with the largest query range, and the lower bound is determined based on the query statement with the smallest query range. The target query result (excluding target data) corresponding to the target equivalence class is then used as the query result corresponding to the first equivalence class. Simultaneously, the equivalence class formed by query statements that meet the specified conditions can be identified as the second equivalence class split from the target equivalence class. The upper bound of the second equivalence class is determined based on the query statement with the largest query range, and the lower bound is determined based on the query statement with the smallest query range. Target data is added to the target query result corresponding to the target equivalence class, and the target query result with the added target data is then used as the query result corresponding to the second equivalence class. Finally, the target equivalence class is deleted. In other words, the target equivalence class is split into the first equivalence class and the second equivalence class mentioned above. The first equivalence class consists of all query statements in the original target equivalence class that do not meet the specified conditions, and the second equivalence class consists of all query statements in the original target equivalence class that meet the specified conditions. The upper and lower bounds of the two equivalence classes are still determined by the maximum and minimum query ranges in their respective query statements.
[0094] Continuing with the previous example, after the database instance changes from Table 1 to Table 2, Q1 and Q5 in the equivalence classes satisfy the specified conditions mentioned above, while Q2 and Q4 do not. That is to say, the weak equivalence relationship that originally existed between {Q1, Q5} and {Q2, Q4} has been broken by the newly added target data with ID 004. However, the query results for Q1 and Q5 are all data with IDs 002, 003, and 004, so they still have a weak equivalence relationship. The query results for Q2 and Q4 are all data with IDs 002 and 003, so they also have a weak equivalence relationship. Therefore, the first equivalence class formed by Q2 and Q4 has an upper bound of a query range greater than 5000 for Q2 and a lower bound of a query range greater than 5500 for Q4. The query result is the same as the query result of the original target equivalence class, which is data with IDs 002 and 003. The second equivalence class formed by Q1 and Q5 has an upper bound of a query range greater than 2200 for Q5 and a lower bound of a query range greater than 3000 for Q1. The query result is the original target equivalence class query result plus the target data, which is data with IDs 002, 003, and 004.
[0095] Scenario 4: The target data is changed by modification. In this case, the database is equivalent to first deleting the target data before modification and then adding the target data after modification. Therefore, the server can first treat the target data before modification as the target data with the modification method of deletion, and update the target equivalence class using the method corresponding to Scenario 2 above. Then, treat the target data after modification as the target data with the modification method of addition, and update the target equivalence class using the method corresponding to Scenario 3 above.
[0096] Using the above method, when data in the database changes, only the target equivalence class needs to be updated, while other non-target equivalence classes do not need to be updated. This can keep the number of equivalence classes affected by data changes to a minimum, eliminating the need to rebuild all equivalence classes and effectively reducing the pressure on the database system.
[0097] The above is a data update method provided by the embodiments of this specification. Based on the same idea, this specification also provides corresponding devices, storage media and electronic devices.
[0098] Figure 3 This is a schematic diagram of a data update device provided in an embodiment of this specification. The device includes:
[0099] The storage module 304 is used to pre-store several equivalence classes, where the query statements contained in an equivalence class have weak equivalence relations.
[0100] The data determination module 301 is used to determine the data that has been changed in the database as the target data.
[0101] The equivalence class determination module 302 is used to determine the equivalence class that matches the target data based on the target data and the query statements contained in each equivalence class, and use it as the target equivalence class;
[0102] The update module 303 is used to update the target equivalence class according to the change method of the target data.
[0103] Optionally, the equivalence class determination module 302 is specifically used to determine, for each pre-saved equivalence class, whether there is at least one query statement in the equivalence class that satisfies the specified conditions. If so, the equivalence class is determined to match the target data; otherwise, the equivalence class is determined not to match the target data. Wherein, for any query statement, if the query statement is executed in the database after the data change and the query result contains the target data, then the query statement is a query statement that satisfies the specified conditions.
[0104] Optionally, the target data can be modified in the following ways: deletion, addition, and alteration.
[0105] When the target data is changed in the manner of modification, the target data before modification is treated as the target data with the modification method of deletion, and the target data after modification is treated as the target data with the modification method of addition.
[0106] Optionally, the update module 303 is specifically used to, when the change method of the target data is deletion, take the pre-saved query result corresponding to the target equivalence class as the target query result, and delete the target data from the target query result; and update the target equivalence class according to the target query result after deleting the target data.
[0107] Optionally, the update module 303 is specifically used to delete the target equivalence class when the target query result after deleting the target data is an empty set; when the target query result after deleting the target data is not an empty set, determine the equivalence class in other equivalence classes whose corresponding query result is the same as the target query result after deleting the target data, and use it as the equivalence class to be merged, and merge the target equivalence class with the equivalence class to be merged.
[0108] Optionally, the update module 303 is specifically used to determine whether there are query statements in the target equivalence class that do not meet the specified conditions when the change method of the target data is addition; if so, split the target equivalence class according to the query statements that meet the specified conditions and the query statements that do not meet the specified conditions; otherwise, add the target data to the query results corresponding to the pre-saved target equivalence class.
[0109] Optionally, the update module 303 is specifically configured to: determine an equivalence class consisting of query statements that do not meet the specified conditions in the target equivalence class as a first equivalence class; determine the upper bound of the first equivalence class based on the query statement with the largest query range in the first equivalence class; determine the lower bound of the first equivalence class based on the query statement with the smallest query range in the first equivalence class; and use the target query result corresponding to the target equivalence class as the query result corresponding to the first equivalence class; furthermore, determine an equivalence class consisting of query statements that meet the specified conditions in the target equivalence class as a second equivalence class; determine the upper bound of the second equivalence class based on the query statement with the largest query range in the second equivalence class; determine the lower bound of the second equivalence class based on the query statement with the smallest query range in the second equivalence class; add the target data to the target query result corresponding to the target equivalence class; use the target query result with the added target data as the query result corresponding to the second equivalence class; and delete the target equivalence class.
[0110] Optionally, the update module 303 is further configured to keep the pre-saved equivalence classes unchanged when the equivalence class determination module 302 fails to determine any equivalence class that matches the target data.
[0111] This specification also provides a computer-readable storage medium storing a computer program that, when executed by a processor, can be used to perform the data update method provided above.
[0112] based on Figure 2 The data update method shown in this specification is further provided in the embodiments. Figure 4 The diagram shows the structure of the electronic device. Figure 4 At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the data update method described above.
[0113] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A data update method, comprising pre-saving several equivalence classes, wherein the query statements contained in an equivalence class have weak equivalence relations; the method comprising: Identify the data in the database that has been changed and use it as the target data; Based on the target data and the query statements contained in each equivalence class, determine the equivalence class that matches the target data, and use it as the target equivalence class; The target equivalence class is updated according to the way the target data is changed.
2. The method as described in claim 1, wherein determining the equivalence class matching the target data specifically includes: For each pre-saved equivalence class, determine whether there is at least one query statement in the equivalence class that satisfies the specified conditions. If so, determine that the equivalence class matches the target data; otherwise, determine that the equivalence class does not match the target data. Specifically, for any query statement, if executing the query statement in the database after data changes results in the target data, then the query statement is a query statement that satisfies the specified conditions.
3. The method as described in claim 2, wherein the modification methods of the target data include deletion, addition, and alteration; When the target data is changed in the manner of modification, the target data before modification is treated as the target data with the modification method of deletion, and the target data after modification is treated as the target data with the modification method of addition.
4. The method as described in claim 3, wherein updating the target equivalence class according to the change method of the target data specifically includes: When the target data is changed by deletion, the query results corresponding to the pre-saved target equivalence class are used as the target query results, and the target data is deleted from the target query results. The target equivalence class is updated based on the target query results after deleting the target data.
5. The method as described in claim 4, wherein updating the target equivalence class based on the target query result after deleting the target data specifically includes: When the target query result after deleting the target data is an empty set, delete the target equivalence class; When the target query result after deleting the target data is not an empty set, the equivalence class whose corresponding query result is the same as the target query result after deleting the target data is determined in other equivalence classes, and is taken as the equivalence class to be merged. The target equivalence class and the equivalence class to be merged are then merged.
6. The method as described in claim 3, wherein updating the target equivalence class according to the change method of the target data specifically includes: When the target data is changed by adding new data, determine whether there is a query statement in the target equivalence class that does not meet the specified conditions; If so, the target equivalence class is split according to the query statements that satisfy the specified conditions and the query statements that do not satisfy the specified conditions in the target equivalence class; Otherwise, the target data is added to the query results corresponding to the pre-saved target equivalence class.
7. The method as described in claim 6, wherein the target equivalence class is split based on query statements that satisfy the specified conditions and query statements that do not satisfy the specified conditions, specifically including: An equivalence class consisting of query statements that do not meet the specified conditions in the target equivalence class is determined as the first equivalence class. The upper bound of the first equivalence class is determined based on the query statement with the largest query range in the first equivalence class, and the lower bound of the first equivalence class is determined based on the query statement with the smallest query range in the first equivalence class. The target query result corresponding to the target equivalence class is then used as the query result corresponding to the first equivalence class. Furthermore, an equivalence class consisting of query statements that meet the specified conditions in the target equivalence class is determined as the second equivalence class. The upper bound of the second equivalence class is determined based on the query statement with the largest query range in the second equivalence class, and the lower bound of the second equivalence class is determined based on the query statement with the smallest query range in the second equivalence class. The target data is then added to the target query result corresponding to the target equivalence class, and the target query result with the added target data is used as the query result corresponding to the second equivalence class. Delete the target equivalence class.
8. The method of claim 1, further comprising: If no equivalence class matching the target data is determined, the pre-saved equivalence classes remain unchanged.
9. A data updating apparatus, the apparatus comprising: The storage module is used to pre-store several equivalence classes, where the query statements contained in an equivalence class have weak equivalence relations. The data determination module is used to identify the data in the database that has been changed, and use it as the target data. The equivalence class determination module is used to determine the equivalence class that matches the target data based on the target data and the query statements contained in each equivalence class, and use it as the target equivalence class; The update module is used to update the target equivalence class according to the change method of the target data.
10. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method according to any one of claims 1-8.