A sentence detection method and related apparatus
Patent Information
- Application Number
- CN202210296579.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-24
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2042-03-24
AI Technical Summary
[0003]在相关技术中,虽然DML语句被广泛应用在数据库中,但是缺乏对DML语句的有效分析和检测,难以保障对数据的稳定处理
[0045] As can be seen from the above technical solution, when performing statement detection, the data manipulation statement to be detected and the corresponding statement rule can be obtained first. This statement rule can identify the first target database field required by the manipulation statement to be detected. That is, in order for the data manipulation statement to be detected to run normally under this statement rule, an index for the first target database field is required. Based on this statement rule, it can be determined whether a corresponding first target database table has been established for the first target database field, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. This allows for the automatic detection of the data manipulation statement to be detected, analysis to determine whether the data manipulation statement to be detected can run stably, thereby ensuring the stability of database operation. Furthermore, the entire process requires no manual intervention, reducing the need for manpower and improving the efficiency of statement detection.
Smart Images

Figure CN116842033B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data detection technology, and in particular to a detection method and related apparatus. Background Technology
[0002] Data Manipulation Language (DML) is a set of programming statements used for database operations, performing access operations on objects and data within a database. It is typically a subset of database-specific programming languages. Therefore, the correctness and performance of DML statements play a crucial role in ensuring that data is processed correctly and efficiently.
[0003] In related technologies, although DML statements are widely used in databases, the lack of effective analysis and detection of DML statements makes it difficult to ensure stable data processing. Summary of the Invention
[0004] To address the aforementioned technical issues, this application provides a statement detection method. The processing device can perform compliance checks on data manipulation statements based on the statement rules corresponding to the data manipulation statements, thereby improving the stability of the data manipulation statements.
[0005] The embodiments of this application disclose the following technical solutions:
[0006] In a first aspect, embodiments of this application disclose a statement detection method, the method comprising:
[0007] Obtain the data manipulation statement to be detected, and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected.
[0008] The data manipulation statement to be detected is subjected to compliance checks according to the statement rules. The compliance checks are used to determine whether the first target database field has a corresponding first target database table, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table.
[0009] Secondly, embodiments of this application disclose a statement detection device, the device comprising a first acquisition unit, a first determination unit, and a first response unit:
[0010] The first acquisition unit is used to acquire the data manipulation statement to be detected and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected.
[0011] The first determining unit is used to determine, according to the statement rules, whether a corresponding first target database table is established for the first target database field, and to determine whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. The first target database table is used to store the first target database field, and the first target index is used to sort the first target database table.
[0012] The first response unit is configured to determine that the data manipulation statement to be detected does not conform to the statement rules in response to the fact that no corresponding first target database table has been established for the first target database field, or that the data manipulation statement to be detected does not have the first target index.
[0013] In one possible implementation, the first acquisition unit is specifically used for:
[0014] Retrieve multiple initial data manipulation statements;
[0015] Determine the fingerprint identifiers corresponding to the plurality of initial data manipulation statements, and the fingerprint identifiers corresponding to the same initial data manipulation statements are the same;
[0016] For each fingerprint identifier, a unique initial data manipulation statement is obtained as the data manipulation statement to be detected.
[0017] In one possible implementation, the device further includes a second determining unit and an adding unit.
[0018] The second determining unit is used to determine the candidate index corresponding to the data manipulation statement to be detected, wherein the candidate index is a first target index that is not present in the data manipulation statement to be detected;
[0019] The adding unit is used to add the candidate index to the data manipulation statement to be detected.
[0020] In one possible implementation, the device further includes a third determining unit and a first detecting unit:
[0021] The third determining unit is used to determine the second target index required by the data manipulation statement to be detected at runtime;
[0022] The first detection unit is used to detect whether the data manipulation statement to be detected includes the second target index.
[0023] In one possible implementation, the apparatus further includes a second acquisition unit, a fourth determination unit, and a second response unit:
[0024] The second acquisition unit is used to acquire the third target index included in the data manipulation statement to be detected;
[0025] The fourth determining unit is used to determine the database field to be detected corresponding to the third target index;
[0026] The second response unit is used to remove the third target index in response to the fact that the amount of data in the database field to be detected is less than a preset threshold.
[0027] In one possible implementation, the device further includes a third acquisition unit and a second detection unit:
[0028] The third acquisition unit is used to acquire the library table information corresponding to the data manipulation statement to be detected, and the library table information is used to identify the second target library table involved in the data manipulation statement to be detected.
[0029] The second detection unit is used to perform performance testing on the data manipulation statements to be tested based on the database table information.
[0030] In one possible implementation, the second detection unit is specifically used for:
[0031] Determine whether the second target table has a field that has been indexed repeatedly;
[0032] In response to the second target table having a field that is indexed repeatedly, an error message is generated for the second target table.
[0033] In one possible implementation, the device further includes a fourth acquisition unit:
[0034] The fourth acquisition unit is used to acquire the index usage information corresponding to the database table information. The index usage information is used to identify the use of the index by the data manipulation statement to be detected during the execution of the index.
[0035] The second detection unit is specifically used for:
[0036] Based on the index usage information, determine whether there are any unused indexes in the index corresponding to the second target database table;
[0037] In response to the presence of an unused index in the index corresponding to the second target database table, an error message is generated for the second target database table.
[0038] In one possible implementation, the second target database table includes multiple tables, which are identical tables distributed across different databases. The apparatus further includes a third response unit.
[0039] The third response unit is used to cancel the error message in response to a mismatch between the number of error messages for the second target database table and the number of the second target database table.
[0040] Thirdly, embodiments of this application disclose a computer device, the device including a processor and a memory:
[0041] The memory is used to store program code and transmit the program code to the processor;
[0042] The processor is configured to execute the statement detection method described in any one of the first aspects according to the instructions in the program code.
[0043] Fourthly, embodiments of this application disclose a computer-readable storage medium for storing a computer program for executing the statement detection method described in any one of the first aspects.
[0044] Fifthly, embodiments of this application disclose a computer program product including instructions that, when run on a computer, cause the computer to execute the statement detection method described in any one of the first aspects.
[0045] As can be seen from the above technical solution, when performing statement detection, the data manipulation statement to be detected and the corresponding statement rule can be obtained first. This statement rule can identify the first target database field required by the manipulation statement to be detected. That is, in order for the data manipulation statement to be detected to run normally under this statement rule, an index for the first target database field is required. Based on this statement rule, it can be determined whether a corresponding first target database table has been established for the first target database field, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. This allows for the automatic detection of the data manipulation statement to be detected, analysis to determine whether the data manipulation statement to be detected can run stably, thereby ensuring the stability of database operation. Furthermore, the entire process requires no manual intervention, reducing the need for manpower and improving the efficiency of statement detection. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 A schematic diagram illustrating a statement detection method in a practical application scenario provided by an embodiment of this application;
[0048] Figure 2 A flowchart of a statement detection method provided in an embodiment of this application;
[0049] Figure 3 An architecture diagram provided for an embodiment of this application;
[0050] Figure 4 A schematic diagram of a statement detection method provided in an embodiment of this application;
[0051] Figure 5 A structural block diagram of a statement detection device provided in an embodiment of this application;
[0052] Figure 6 A structural diagram of a terminal provided in an embodiment of this application;
[0053] Figure 7 This is a structural diagram of a server provided in an embodiment of this application. Detailed Implementation
[0054] The embodiments of this application will now be described with reference to the accompanying drawings.
[0055] The stable and efficient execution of Data Manipulation (DML) statements directly determines the performance of a database. Therefore, performance testing of DML statements helps improve database efficiency and stability. However, effective methods for testing DML statements are lacking in current technologies.
[0056] To address the aforementioned technical issues, this application provides a statement detection method. The processing device can perform compliance checks on data manipulation statements based on the statement rules corresponding to the data manipulation statements, thereby improving the stability of data manipulation statements.
[0057] Understandably, this method can be applied to processing devices capable of statement detection, such as terminal devices or servers with statement detection functionality. This method can be executed independently by a terminal device or server, or it can be applied in network scenarios where a terminal device and a server communicate, executing in cooperation. The terminal device can be a computer, mobile phone, or similar device. The server can be an application server or a web server; in actual deployment, this server can be a standalone server or a cluster server.
[0058] To facilitate understanding of the technical solutions provided in the embodiments of this application, the following will introduce a statement detection method provided in the embodiments of this application in conjunction with a practical application scenario.
[0059] See Figure 1 , Figure 1This is a schematic diagram of a statement detection method in a practical application scenario provided by an embodiment of this application. In this practical application scenario, the processing device is a server 101 with statement detection function.
[0060] After obtaining the data manipulation statement to be detected, in order to analyze whether the statement can run stably, server 101 can obtain the statement rule corresponding to the statement. This statement rule is used to identify the first target database field required by the statement, that is, the database field that the statement must index when running under this statement rule. Therefore, server 101 can perform compliance checks on the statement based on this statement rule. On the one hand, it can check whether the first target database field has a corresponding first target database table; on the other hand, it can check whether the statement has a first target index corresponding to the first target. Thus, it can detect whether the statement can normally index the first target database field during operation, thereby achieving automatic detection of the statement.
[0061] Next, with reference to the accompanying drawings, a statement detection method provided by an embodiment of this application will be described.
[0062] See Figure 2 , Figure 2 A flowchart of a statement detection method provided in this application embodiment, the method including:
[0063] S201: Obtain the data manipulation statement to be detected, and the statement rule corresponding to the data manipulation statement to be detected.
[0064] The data manipulation statements to be detected refer to the data manipulation statements that need to be detected. Specifically, such as... Figure 3 As shown in the architecture, the processing device (i.e., the processor) can obtain the data manipulation statements to be detected from business logs and database logs through the information collection unit. There are two main ways to obtain the data manipulation statements to be detected. The first is to directly check if the log file contains a delimiter that meets the configuration and supports pattern extraction. This delimiter can be added by relevant personnel when developing the data manipulation statements to identify them in the log. If it meets the requirements, the processing device can directly extract the complete data manipulation statement from the log file through pattern extraction. The second method is for the processing device to find the starting position of the first data manipulation statement in the log file, and then subtract characters sequentially from the end until a complete Abstract Syntax Tree (AST) can be generated, indicating that a complete data manipulation statement has been obtained.
[0065] It is understood that data manipulation statements need to meet certain statement rules to run stably in a database. Therefore, in this embodiment, in order to analyze whether a data manipulation statement to be detected can run stably, the processing device can obtain the statement rule corresponding to the data manipulation statement to be detected. This statement rule is used to identify the first target database field required by the data manipulation statement to be detected. That is, the data manipulation statement to be detected needs to have the ability to index the first target database field in order to run stably under this statement rule.
[0066] S202: Based on the statement rules, determine whether the first target database field has a corresponding first target database table, and determine whether the data manipulation statement to be detected has a first target index corresponding to the first target database table.
[0067] It is understandable that an index is a separate, physical storage structure that sorts the values of one or more columns in a database table. A database table is a storage unit for database data fields. Therefore, for a data manipulation statement to be tested to have the ability to index the first target database field, the database must first have a first target database table for that first target database field, and that first target database table must have a corresponding index, which must be applied in the data manipulation statement to be tested. Specifically, the first target database table is used to store the first target database field, and the first target index is used to sort the first target database table.
[0068] Based on this, the processing device can perform compliance checks on the data manipulation statement to be detected according to the statement rules. This compliance check can determine whether a corresponding first target database table has been created for the first target database field, and whether the data manipulation statement to be detected has a first target index corresponding to that first target database table. This allows the device to detect whether the data manipulation statement to be detected can run stably under the statement rules. For example, if the first target database field does not have a corresponding first target database table, or the data manipulation statement to be detected does not have a first target index corresponding to that first target database table, it can be determined that the data manipulation statement to be detected may have operational problems. The processing device can then output a detection report for relevant personnel to analyze, or perform automatic repair based on the detection report.
[0069] S203: In response to the fact that no corresponding first target database table has been established for the first target database field, or that the data manipulation statement to be detected does not have a first target index, it is determined that the data manipulation statement to be detected does not conform to the statement rules.
[0070] When the data manipulation statement under test has the above-mentioned problems, it will prevent the statement from using the first target database field through the index during execution, thus failing to meet the requirements of the statement rule for data manipulation statements. The processing device can complete the compliance detection of the data manipulation statement under test in this way.
[0071] As can be seen from the above technical solution, when performing statement detection, the data manipulation statement to be detected and the corresponding statement rule can be obtained first. This statement rule can identify the first target database field required by the manipulation statement to be detected. That is, in order for the data manipulation statement to be detected to run normally under this statement rule, an index for the first target database field is required. Based on this statement rule, it can be determined whether a corresponding first target database table has been established for the first target database field, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. This allows for the automatic detection of the data manipulation statement to be detected, analysis to determine whether the data manipulation statement to be detected can run stably, thereby ensuring the stability of database operation. Furthermore, the entire process requires no manual intervention, reducing the need for manpower and improving the efficiency of statement detection.
[0072] It is understandable that, in the log information awaiting detection of data manipulation statements, there may be multiple identical data manipulation statements. In one possible implementation, to improve statement detection efficiency, the processing device can first acquire multiple initial data manipulation statements, and then determine the fingerprint identifier corresponding to each initial data manipulation statement. This fingerprint identifier corresponds one-to-one with the data manipulation statement; identical initial data manipulation statements correspond to the same fingerprint identifier. Based on this, the processing device can perform deduplication of data manipulation statements using the fingerprint identifier. That is, for each fingerprint identifier, the processing device can obtain a unique initial data manipulation statement as the data manipulation statement to be detected, thereby avoiding repeated detection of identical data manipulation statements and improving statement detection efficiency.
[0073] Furthermore, the method by which processing devices collect log information can vary depending on the type of log information. For business logs, see [link to relevant documentation]. Figure 4 , Figure 4This illustration shows a business log acquisition method provided in this application embodiment. The processing device can be deployed on the machine via an agent to collect logs. After receiving an information collection command, the agent can call its own configuration service to generate a task queue, then call the file service to poll the log files to be detected in the task queue for any unprocessed data manipulation statements. Then, it calls the core service to perform lexical analysis on the data manipulation statements to be detected, generate the corresponding abstract syntax tree and the corresponding fingerprint identifier, and finally obtain the data manipulation statements to be detected after deduplication based on the fingerprint identifier.
[0074] Regarding database logs, the processing device can modify the database configuration by issuing an initialization task through the control center, then turn on the slow query log printing switch and set the log generation path. When the processing device issues a collection task through the control center, it can report the collected slow query log information to the processing device.
[0075] In one possible implementation, to improve the stability of the data manipulation statement, the processing device can also proactively repair the problematic data manipulation statement to be detected. For example, the processing device can determine a candidate index corresponding to the data manipulation statement to be detected, which is a first target index that is not present in the data manipulation statement to be detected. The processing device can add the candidate index to the data manipulation statement to be detected, thereby further ensuring the stable operation of the data manipulation statement to be detected.
[0076] Furthermore, since statement rules may be updated, to improve the accuracy of statement detection based on statement rules, the processing device can analyze whether the statement rules are up-to-date when acquiring them. For example, the processing device can use a web crawler to check if there are any changes to the statement rule website. If changes exist, the system administrator can update the statement rules corresponding to the data manipulation statements in a timely manner, ensuring timely and efficient compliance detection. During detection, the FIT specification code is coded using the above update method, and then it checks whether the corresponding database fields have been created in the database table, and whether the database table has a corresponding index in the data manipulation statement to be detected, thus achieving compliance detection of the data manipulation statement to be detected. This compliance detection can be achieved through... Figure 3 The rules engine in the architecture shown is used to accomplish this.
[0077] In addition to compliance checks, the processing device can also perform various other statement checks. For example, in one possible implementation, the processing device can determine a second target index required by the data manipulation statement to be detected at runtime. This second target index is an index that should be added to make the data manipulation statement to be detected run more stably and efficiently. It is understood that this second target index differs from the first target index and may not be an index absolutely necessary for the execution of the data manipulation statement to be detected, but rather an index that can be added to improve the performance of the data manipulation statement to be detected. The processing device can detect whether the data manipulation statement to be detected includes the second target index, thereby detecting whether the manipulation statement to be detected has high runtime performance. That is, if the data manipulation statement to be detected includes the second target index, it has relatively high runtime performance; if it does not include it, its runtime performance is poor.
[0078] Specifically, the processing equipment can be... Figure 3 The architecture shown uses a dependency engine to implement this detection step. The processing device can analyze the data manipulation statement to be detected using a secondary development tool within the dependency engine: the SQLOptimizer and Rewriter (SOAR). This tool will suggest which indexes should exist in the data manipulation statement for optimal performance. However, this tool only analyzes the statement itself and does not necessarily mean that these indexes actually exist in the database (DB). Therefore, the processing device can connect to the DB to check for the existence of such indexes, thus providing a deterministic result.
[0079] Furthermore, some fields in the database may have small amounts of data. When indexes are created for these fields, the database sorts all indexed fields. However, since these fields have small amounts of data, sorting is less useful, leading to a waste of processing resources. Therefore, to further optimize database resource consumption, in one possible implementation, the processing device can obtain a third target index included in the data manipulation statement to be detected. This third target index is the index involved in the execution of the data manipulation statement. Subsequently, the processing device can determine the database field to be detected corresponding to the third target index. If the amount of data in the database field to be detected is less than a preset threshold, it indicates that the amount of data in the database field to be detected is small and does not need to be sorted using an index. At this point, the processing device can remove the third target index, thereby reducing database resource consumption.
[0080] For example, processing devices can also use the soar tool to analyze data manipulation statements and determine whether an index does not need to be created based on the amount of data in a database field.
[0081] In addition to statement detection based on the data manipulation statement itself, as described above, the processing device can further perform statement detection based on the database table dimension. In one possible implementation, the processing device can obtain the database table information corresponding to the data manipulation statement, which identifies the second target database table involved in the statement, and then perform performance testing on the statement based on this database table information.
[0082] Specifically, this performance testing can include two aspects: firstly, the processing device can detect whether there are duplicate or redundant indexes in the database tables; secondly, it can detect whether the database tables contain indexes that are not used by the data manipulation statements being tested. As mentioned above, the database sorts all indexes during runtime. Since redundant and unused indexes are likely to be removable, detecting these types of indexes helps to further optimize database resource consumption.
[0083] In one possible implementation, the processing device can determine whether the second target table has a field that is indexed repeatedly, i.e., multiple indexes have been created for that field, thus causing repeated sorting of that field during database runtime and wasting database resources. In response to the presence of a duplicated index in the second target table, the processing device can generate an error message for the second target table to indicate that there is an indexing problem.
[0084] For example, in Figure 3 In the architecture shown, the processing device can perform performance testing through its core engine. The processing device can use relevant tools (such as the duplicate index detector pt-duplicate-key-checker) to output whether duplicate and redundant indexes exist. During detection, the processing device can perform lexical analysis on the database tables, call open-source frameworks to generate abstract syntax trees, eliminate the influence of database tables, reduce the number of analysis sets, and reduce the time spent on manual analysis.
[0085] In another possible implementation, the processing device can obtain the index usage information corresponding to the database table information. This index usage information can be used to identify the index usage during the execution of the detection data manipulation statement. For example, the processing device can obtain the database table interface information through the interface of the database under test. This database table interface information can be automatically reported to the processing device after the processing device issues the retrieval task, facilitating later analysis. Additionally, the processing device can obtain partial index usage information from the database logs for analysis.
[0086] The processing device can determine whether there are unused indexes in the indexes corresponding to the second target table based on the index usage information. In response to the presence of unused indexes in the second target table, the processing device can also generate error messages for that second target table. For example, the processing device can use the index usage detection tool (pt_index_usage) to detect the existence of unused indexes in the output. Of course, as mentioned in the previous scheme, due to the need to conform to statement rules, the data manipulation statement to be detected may contain necessary indexes, and these indexes may also be unused. Therefore, the processing device can determine whether any of the identified unused indexes correspond to the statement rule based on the statement rule. If so, it can cancel the error messages generated based on these indexes, thereby reducing the probability of false alarms.
[0087] It's understandable that databases may be sharded, meaning the same table might be stored in multiple databases. Normally, since the fields and indexes of these tables are identical, the number of error messages for that table should match the number of errors for that table—for example, they should be consistent or an integer multiple of the number of tables. That is, if there are multiple second target tables, and these second target tables are the same table distributed across different databases, a mismatch between the number of error messages for a given second target table and the number of tables indicates an error has occurred, and the processing device can retract that error message.
[0088] The reasons for the mismatch in the number of error messages may vary depending on the specific circumstances. For example, when detecting duplicate or redundant indexes, a mismatch between the number of error messages and the number of tables might be due to incomplete updates to all identical tables during table updates. This results in some tables having updated fields and indexes while others do not, leading to duplicate indexes in some tables and non-existent indexes in others. Conversely, for detecting unused indexes, the difference might be due to varying execution progress across different databases. In some tables, indexes might already be in use, while identical indexes in other tables may not yet be used, resulting in error messages indicating unused indexes in some tables.
[0089] Finally, the processing device can integrate the error information generated during the above process and, based on historical processing experience, automatically match the solution strategy by analyzing key fields related to the problem in the error information. This allows for automatic repair or the combination of the strategy and error information into a complete report to notify relevant personnel for repair. The entire process of the statement detection method provided in this application can reduce the probability of false alarms and reduce the need for manpower, thereby lowering the threshold for statement detection and improving its efficiency.
[0090] Based on the statement detection method provided in the above embodiments, this application also provides a statement detection device, see [link to relevant documentation]. Figure 5 , Figure 5 This application provides a structural block diagram of a statement detection device 500, which includes a first acquisition unit 501, a first determination unit 502, and a first response unit 503.
[0091] The first acquisition unit 501 is used to acquire the data manipulation statement to be detected and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected.
[0092] The first determining unit 502 is used to determine, according to the statement rules, whether the first target database field has a corresponding first target database table, and to determine whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. The first target database table is used to store the first target database field, and the first target index is used to sort the first target database table.
[0093] The first response unit 503 is used to determine that the data manipulation statement to be detected does not conform to the statement rules in response to the fact that no corresponding first target database table has been established for the first target database field, or that the data manipulation statement to be detected does not have the first target index.
[0094] In one possible implementation, the first acquisition unit 501 is specifically used for:
[0095] Retrieve multiple initial data manipulation statements;
[0096] Determine the fingerprint identifiers corresponding to the plurality of initial data manipulation statements, and the fingerprint identifiers corresponding to the same initial data manipulation statements are the same;
[0097] For each fingerprint identifier, a unique initial data manipulation statement is obtained as the data manipulation statement to be detected.
[0098] In one possible implementation, the device further includes a second determining unit and an adding unit.
[0099] The second determining unit is used to determine the candidate index corresponding to the data manipulation statement to be detected, wherein the candidate index is a first target index that is not present in the data manipulation statement to be detected;
[0100] The adding unit is used to add the candidate index to the data manipulation statement to be detected.
[0101] In one possible implementation, the device further includes a third determining unit and a first detecting unit:
[0102] The third determining unit is used to determine the second target index required by the data manipulation statement to be detected at runtime;
[0103] The first detection unit is used to detect whether the data manipulation statement to be detected includes the second target index.
[0104] In one possible implementation, the apparatus further includes a second acquisition unit, a fourth determination unit, and a second response unit:
[0105] The second acquisition unit is used to acquire the third target index included in the data manipulation statement to be detected;
[0106] The fourth determining unit is used to determine the database field to be detected corresponding to the third target index;
[0107] The second response unit is used to remove the third target index in response to the fact that the amount of data in the database field to be detected is less than a preset threshold.
[0108] In one possible implementation, the device further includes a third acquisition unit and a second detection unit:
[0109] The third acquisition unit is used to acquire the library table information corresponding to the data manipulation statement to be detected, and the library table information is used to identify the second target library table involved in the data manipulation statement to be detected.
[0110] The second detection unit is used to perform performance testing on the data manipulation statements to be tested based on the database table information.
[0111] In one possible implementation, the second detection unit is specifically used for:
[0112] Determine whether the second target table has a field that has been indexed repeatedly;
[0113] In response to the second target table having a field that is indexed repeatedly, an error message is generated for the second target table.
[0114] In one possible implementation, the device further includes a fourth acquisition unit:
[0115] The fourth acquisition unit is used to acquire the index usage information corresponding to the database table information. The index usage information is used to identify the use of the index by the data manipulation statement to be detected during the execution of the index.
[0116] The second detection unit is specifically used for:
[0117] Based on the index usage information, determine whether there are any unused indexes in the index corresponding to the second target database table;
[0118] In response to the presence of an unused index in the index corresponding to the second target database table, an error message is generated for the second target database table.
[0119] In one possible implementation, the second target database table includes multiple tables, which are identical tables distributed across different databases. The apparatus further includes a third response unit.
[0120] The third response unit is used to cancel the error message in response to a mismatch between the number of error messages for the second target database table and the number of the second target database table.
[0121] This application also provides a computer device, which will be described below with reference to the accompanying drawings. Please refer to... Figure 6 As shown in the figure, this application provides a device, which can also be a terminal device. The terminal device can be any smart terminal, including mobile phones, tablets, personal digital assistants (PDAs), point-of-sale (POS) terminals, in-vehicle computers, etc. Taking a mobile phone as an example:
[0122] Figure 6 This diagram illustrates a partial structural representation of a mobile phone related to the terminal device provided in this embodiment. (Reference) Figure 6 The mobile phone includes components such as a radio frequency (RF) circuit 710, a memory 720, an input unit 730, a display unit 740, a sensor 750, an audio circuit 760, a wireless Fidelity (WiFi) module 770, a processor 780, and a power supply 790. Those skilled in the art will understand that... Figure 6 The mobile phone structure shown does not constitute a limitation on the mobile phone and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0123] The following is combined Figure 6 A detailed introduction to each component of a mobile phone:
[0124] RF circuit 710 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and processes it with processor 780; additionally, it transmits uplink data to the base station. Typically, RF circuit 710 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), and a duplexer. Furthermore, RF circuit 710 can also communicate wirelessly with networks and other devices. The aforementioned wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, and Short Messaging Service (SMS).
[0125] The memory 720 can be used to store software programs and modules. The processor 780 executes various mobile phone functions and data processing by running the software programs and modules stored in the memory 720. The memory 720 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 720 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0126] The input unit 730 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of the mobile phone. Specifically, the input unit 730 may include a touch panel 731 and other input devices 732. The touch panel 731, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 731), and drive the corresponding connected devices according to a pre-set program. Optionally, the touch panel 731 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 780, and can also receive and execute commands sent by the processor 780. In addition, the touch panel 731 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 731, the input unit 730 may also include other input devices 732. Specifically, other input devices 732 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0127] The display unit 740 can be used to display information input by the user or information provided to the user, as well as various menus of the mobile phone. The display unit 740 may include a display panel 741, which may optionally be configured as a Liquid Crystal Display (LCD), Organic Light-Emitting Diode (OLED), or similar display panel. Further, a touch panel 731 may cover the display panel 741. When the touch panel 731 detects a touch operation on or near it, it transmits the information to the processor 780 to determine the type of touch event. Subsequently, the processor 780 provides corresponding visual output on the display panel 741 based on the type of touch event. Although in Figure 6 In this embodiment, the touch panel 731 and the display panel 741 are two separate components to realize the input and output functions of the mobile phone. However, in some embodiments, the touch panel 731 and the display panel 741 can be integrated to realize the input and output functions of the mobile phone.
[0128] The mobile phone may also include at least one sensor 750, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 741 according to the ambient light level, and the proximity sensor can turn off the display panel 741 and / or backlight when the phone is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used for applications that recognize the phone's posture (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition-related functions (such as pedometer, taps), etc. Other sensors that may be configured in the mobile phone, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here.
[0129] Audio circuit 760, speaker 761, and microphone 762 provide an audio interface between the user and the mobile phone. Audio circuit 760 converts received audio data into electrical signals and transmits them to speaker 761, where speaker 761 converts them into sound signals for output. On the other hand, microphone 762 converts collected sound signals into electrical signals, which are received by audio circuit 760, converted into audio data, and then processed by processor 780 before being transmitted via RF circuit 710 to, for example, another mobile phone, or the audio data can be output to memory 720 for further processing.
[0130] WiFi is a short-range wireless transmission technology. Through the WiFi module 770, mobile phones can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 6 The WiFi module 770 is shown, but it is understood that it is not an essential component of a mobile phone and can be omitted as needed without changing the essence of the invention.
[0131] The processor 780 is the control center of the mobile phone, connecting various parts of the phone through various interfaces and lines. It executes software programs and / or modules stored in the memory 720, and calls data stored in the memory 720 to perform various functions and process data, thereby performing overall detection of the phone. Optionally, the processor 780 may include one or more processing units; preferably, the processor 780 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 780.
[0132] The mobile phone also includes a power supply 790 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 780 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.
[0133] Although not shown, mobile phones may also include a camera, Bluetooth module, etc., which will not be described in detail here.
[0134] In this embodiment, the processor 780 included in the terminal device also has the following functions:
[0135] Obtain the data manipulation statement to be detected, and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected.
[0136] The data manipulation statement to be detected is subjected to compliance checks according to the statement rules. The compliance checks are used to determine whether the first target database field has a corresponding first target database table, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table.
[0137] This application also provides a server; please refer to [link / reference]. Figure 7 As shown, Figure 7 This is a structural diagram of a server 800 provided in an embodiment of this application. The server 800 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 822 (e.g., one or more processors) and a memory 832, and one or more storage media 830 (e.g., one or more mass storage devices) for storing application programs 842 or data 844. The memory 832 and storage media 830 can be temporary or persistent storage. The program stored in the storage media 830 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the CPU 822 may be configured to communicate with the storage media 830 and execute the series of instruction operations in the storage media 830 on the server 800.
[0138] Server 800 may also include one or more power supplies 826, one or more wired or wireless network interfaces 850, one or more input / output interfaces 858, and / or one or more operating systems 841, such as Windows Server. TM Mac OS X TM Unix TM Linux TM FreeBSDTM etc.
[0139] The steps performed by the server in the above embodiments can be based on Figure 7 The server structure shown.
[0140] According to one aspect of this application, a computer-readable storage medium is provided for storing program code for executing the statement detection methods described in the foregoing embodiments.
[0141] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the statement detection method provided in various optional implementations of the above embodiments.
[0142] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium can be at least one of the following media: read-only memory (ROM), RAM, magnetic disk, or optical disk, etc., and other media capable of storing program code.
[0143] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0144] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A statement detection method, characterized in that, The method includes: Obtain the data manipulation statement to be detected, and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected. According to the statement rules, it is determined whether the first target database field has a corresponding first target database table, and whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. The first target database table is used to store the first target database field, and the first target index is used to sort the first target database table. In response to the fact that no corresponding first target database table has been established for the first target database field, or that the data manipulation statement to be detected does not have the first target index, it is determined that the data manipulation statement to be detected does not conform to the statement rules. Determine the second target index required by the data manipulation statement to be detected at runtime; The system detects whether the data manipulation statement to be tested includes the second target index. If the data manipulation statement to be tested includes the second target index, it is determined that the execution performance of the data manipulation statement to be tested is good; otherwise, it is determined that the execution performance of the data manipulation statement to be tested is poor. Obtain the third target index included in the data manipulation statement to be detected; Determine the database field to be detected corresponding to the third target index; In response to the fact that the amount of data in the database field to be detected is less than a preset threshold, the third target index is removed; Obtain the index usage information of the index corresponding to the second target database table involved in the data manipulation statement to be detected; Based on the index usage information, determine whether there are any unused indexes in the index corresponding to the second target database table; In response to the presence of an unused index in the index corresponding to the second target database table, an error message is generated for the second target database table. Based on the statement rule, it is determined whether there is an index corresponding to the statement rule among the identified unused indexes. If so, the error message is canceled.
2. The method according to claim 1, characterized in that, The manipulation statements for acquiring the data to be detected include: Retrieve multiple initial data manipulation statements; Determine the fingerprint identifiers corresponding to the plurality of initial data manipulation statements, and the fingerprint identifiers corresponding to the same initial data manipulation statements are the same; For each fingerprint identifier, a unique initial data manipulation statement is obtained as the data manipulation statement to be detected.
3. The method according to claim 1, characterized in that, The method further includes: Determine the candidate index corresponding to the data manipulation statement to be detected, wherein the candidate index is a first target index that is not present in the data manipulation statement to be detected; Add the candidate index to the data manipulation statement to be detected.
4. The method according to claim 1, characterized in that, The method further includes: Obtain the library table information corresponding to the data manipulation statement to be detected, wherein the library table information is used to identify the second target library table involved in the data manipulation statement to be detected; The performance of the data manipulation statements to be tested is performed based on the database table information.
5. The method according to claim 4, characterized in that, The performance testing of the data manipulation statements to be tested based on the database table information includes: Determine whether the second target table has a field that has been indexed repeatedly; In response to the second target table having a field that is indexed repeatedly, an error message is generated for the second target table.
6. The method according to claim 4, characterized in that, The index usage information is used to identify how the data manipulation statement to be detected uses the index during its execution.
7. The method according to any one of claims 5 to 6, characterized in that, The second target database table includes multiple tables, which are identical tables distributed across different databases. The method further includes: In response to a mismatch between the number of error messages for the second target database table and the number of the second target database tables, the error messages are revoked.
8. A statement detection device, characterized in that, The device includes a first acquisition unit, a first determination unit, a first response unit, a third determination unit, a first detection unit, a second acquisition unit, a fourth determination unit, a second response unit, a fourth acquisition unit, and a second detection unit. The first acquisition unit is used to acquire the data manipulation statement to be detected and the statement rule corresponding to the data manipulation statement to be detected. The statement rule is used to identify the first target database field required by the data manipulation statement to be detected. The first determining unit is used to determine, according to the statement rules, whether a corresponding first target database table is established for the first target database field, and to determine whether the data manipulation statement to be detected has a first target index corresponding to the first target database table. The first target database table is used to store the first target database field, and the first target index is used to sort the first target database table. The first response unit is configured to determine that the data manipulation statement to be detected does not conform to the statement rules in response to the fact that no corresponding first target database table has been established for the first target database field, or that the data manipulation statement to be detected does not have the first target index. The third determining unit is used to determine the second target index required by the data manipulation statement to be detected at runtime; The first detection unit is used to detect whether the data manipulation statement to be detected includes the second target index. If the data manipulation statement to be detected includes the second target index, it is determined that the running performance of the data manipulation statement to be detected is good. Otherwise, it is determined that the execution performance of the data manipulation statement to be detected is poor; The second acquisition unit is used to acquire the third target index included in the data manipulation statement to be detected; The fourth determining unit is used to determine the database field to be detected corresponding to the third target index; The second response unit is used to remove the third target index in response to the fact that the amount of data in the database field to be detected is less than a preset threshold; The fourth acquisition unit is used to acquire the index usage information of the index corresponding to the second target database table involved in the data manipulation statement to be detected; The second detection unit is used to determine whether there is an unused index in the index corresponding to the second target database table based on the index usage information; in response to the existence of an unused index in the index corresponding to the second target database table, it generates an error message for the second target database table; based on the statement rule, it determines whether there is an index corresponding to the statement rule among the determined unused indexes; if so, it cancels the error message.
9. The apparatus according to claim 8, characterized in that, The first acquisition unit is specifically used for: Retrieve multiple initial data manipulation statements; Determine the fingerprint identifiers corresponding to the plurality of initial data manipulation statements, and the fingerprint identifiers corresponding to the same initial data manipulation statements are the same; For each fingerprint identifier, a unique initial data manipulation statement is obtained as the data manipulation statement to be detected.
10. The apparatus according to claim 8, characterized in that, The device further includes a second determining unit and an adding unit: The second determining unit is used to determine the candidate index corresponding to the data manipulation statement to be detected, wherein the candidate index is a first target index that is not present in the data manipulation statement to be detected; The adding unit is used to add the candidate index to the data manipulation statement to be detected.
11. The apparatus according to claim 8, characterized in that, The device further includes a third acquisition unit: The third acquisition unit is used to acquire the library table information corresponding to the data manipulation statement to be detected, and the library table information is used to identify the second target library table involved in the data manipulation statement to be detected. The second detection unit is also used to perform performance testing on the data manipulation statements to be tested based on the database table information.
12. The apparatus according to claim 11, characterized in that, The second detection unit is also used for: Determine whether the second target table has a field that has been indexed repeatedly; In response to the second target table having a field that is indexed repeatedly, an error message is generated for the second target table.
13. The apparatus according to claim 11, characterized in that, The index usage information is used to identify how the data manipulation statement to be detected uses the index during its execution.
14. The apparatus according to any one of claims 12 to 13, characterized in that, The second target database table includes multiple tables, which are identical tables distributed across different databases. The device also includes a third response unit. The third response unit is used to cancel the error message in response to a mismatch between the number of error messages for the second target database table and the number of the second target database table.
15. A computer device, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the statement detection method according to any one of claims 1-7 according to the instructions in the program code.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program for executing the statement detection method according to any one of claims 1-7.
17. A computer program product comprising instructions that, when run on a computer, causes the computer to perform the statement detection method according to any one of claims 1-7.
Citation Information
Patent Citations
Method and device for SQL statements and system for improving database reliability
CN102053961A