Index anomaly detection method and device, equipment, medium and product
By left-associating the database data table and the index information table, the index deletion and expansion are detected, which solves the problem of reduced query efficiency caused by index abnormalities, enables timely discovery and repair, and improves system stability and efficiency.
Patent Information
- Application Number
- CN202410751492.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-06
AI Technical Summary
Index deletion and index expansion lead to reduced database query efficiency, and it is difficult to effectively detect and solve these problems with existing technology.
By obtaining the information table of the data table and index in the database, perform left association, detect whether the index name is empty or the ratio of the space occupied by the index to the space occupied by the data table, determine whether there is an index missing or expansion abnormality, and achieve accurate detection of index anomalies. .
It achieves accurate detection of index missing and index expansion, timely discovery and repair, avoids system function timeout and production events, saves labor costs, and improves repair efficiency.
Smart Images

Figure CN118606318A
Abstract
Description
Technical Field
[0001] The present application belongs to the field of big data processing technology, and in particular, relates to an index anomaly detection method, device, equipment, medium and product. Background Art
[0002] Index missing means that after a new data table is created in the database, the index data corresponding to the new data table is not created, resulting in a full table scan during indexing. Index expansion means that after the data in the data table is deleted or updated, the index data corresponding to the data table is not deleted, resulting in a continuous expansion of the space occupied by the index.
[0003] Index missing and index expansion will lead to reduced index efficiency. In order to avoid reduced index efficiency, a solution for detecting index missing and index expansion is needed. Summary of the invention
[0004] The embodiments of the present application provide an index anomaly detection method, apparatus, device, medium and product, which can accurately detect index missing and index expansion.
[0005] In a first aspect, an embodiment of the present application provides an index anomaly detection method, the method comprising:
[0006] Obtain a first information table and a second information table, the first information table including the table name and the data table occupied space of the data table in the database, and the second information table including the table name, index name and index occupied space corresponding to the index data in the database;
[0007] Taking the first information table as the left table and the second information table as the right table, and taking the table name in the right table matching the table name in the left table as a condition, left-associate the left table and the right table to obtain an information association table, which includes the table name, the space occupied by the data table, the index name, and the space occupied by the index;
[0008] When the index name corresponding to the first table name in the information association table is empty, it is determined that the data table corresponding to the first table name has an index missing exception;
[0009] When the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet a preset condition, it is determined that the data table corresponding to the second table name has an index expansion anomaly.
[0010] In a second aspect, an embodiment of the present application provides an index anomaly detection device, the device comprising:
[0011] An acquisition module, used to acquire a first information table and a second information table, wherein the first information table includes a table name and a data table occupied space in a database, and the second information table includes a table name, an index name and an index occupied space corresponding to the index data in the database;
[0012] A first association module is used to perform left association on the left table and the right table, taking the first information table as the left table and the second information table as the right table, and taking the table name in the right table matching the table name in the left table as a condition, to obtain an information association table, wherein the information association table includes the table name, the space occupied by the data table, the index name, and the space occupied by the index;
[0013] A first determination module is used to determine that there is an index missing exception in the data table corresponding to the first table name when the index name corresponding to the first table name in the information association table is empty;
[0014] The second determination module is used to determine that the data table corresponding to the second table name has an index expansion anomaly when the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet a preset condition.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, the device comprising: a processor and a memory storing computer program instructions;
[0016] When the processor executes the computer program instructions, the index anomaly detection method as shown in any one of the embodiments of the first aspect is implemented.
[0017] In a fourth aspect, an embodiment of the present application provides a computer storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, the index anomaly detection method shown in any one of the embodiments of the first aspect is implemented.
[0018] In a fifth aspect, an embodiment of the present application provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the index anomaly detection method shown in any one of the embodiments of the first aspect.
[0019] In the index anomaly detection method, device, equipment, medium and product of the embodiment of the present application, a first information table and a second information table can be obtained, wherein the first information table includes the table name and the data table occupied space of the data table in the database, and the second information table includes the table name, index name and index occupied space corresponding to the index data in the database, and then the first information table is used as the left table, the second information table is used as the right table, and the table name in the right table matches the table name in the left table. The left table and the right table are left-associated to obtain an information association table, which includes the table name, the data table occupied space, the index name and the index occupied space. In the case that the index name corresponding to the first table name in the information association table is empty, it is determined that the data table corresponding to the first table name has an index missing anomaly; in the case that the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet the preset conditions, it is determined that the data table corresponding to the second table name has an index expansion anomaly. In this way, accurate detection of index missing and index expansion can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0021] Figure 1 This is one of the flowcharts of an index anomaly detection method provided by an embodiment of the present application;
[0022] Figure 2 This is the second flowchart of an index anomaly detection method provided by an embodiment of the present application;
[0023] Figure 3 This is a flowchart of a method for detecting anomalies in an index provided by an embodiment of the present application;
[0024] Figure 4 It is a structural schematic diagram of an index anomaly detection device provided by an embodiment of the present application;
[0025] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0026] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0027] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0028] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations.
[0029] In addition, it should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0030] As mentioned in the background technology, index missing means that after a new data table is created in the database, the index data corresponding to the new data table is not created, which will cause a full table scan in the Structured Query Language (SQL) execution plan, and the SQL execution efficiency is slow; index expansion means that after deleting or updating the index field data of the data table, the database does not actually delete the relevant data, but marks it for deletion, does not release space, and generates index fragments, causing the space occupied by the index to continue to expand, thereby causing the SQL execution efficiency to be slow, especially for large database tables, where the execution efficiency is more significantly reduced and the impact is more serious, and it is the focus of attention. Large database tables can refer to data tables with more than 10 million records or a table space of more than 10G.
[0031] Index missing may be caused by developers forgetting to create index data when creating tables, and large table index expansion may be caused by long-term deletion and modification of data. If there is no effective detection method, it may cause system function timeout at best, or cause serious production incidents at worst.
[0032] The index anomaly detection method, device, equipment, medium and product provided in the embodiments of the present application can obtain a first information table and a second information table, wherein the first information table includes the table name and the data table occupied space of the data table in the database, and the second information table includes the table name, index name and index occupied space corresponding to the index data in the database, and then the first information table is used as the left table, the second information table is used as the right table, and the table name in the right table matches the table name in the left table. The left table and the right table are left-associated to obtain an information association table, which includes the table name, the data table occupied space, the index name and the index occupied space. In the case that the index name corresponding to the first table name in the information association table is empty, it is determined that the data table corresponding to the first table name has an index missing anomaly; in the case that the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet the preset conditions, it is determined that the data table corresponding to the second table name has an index expansion anomaly. In this way, accurate detection of index missing and index expansion can be achieved.
[0033] Combine the following Figure 1 The index anomaly detection method provided in the embodiment of the present application is described in detail.
[0034] Figure 1 A schematic diagram of a flow chart of an index anomaly detection method provided by an embodiment of the present application is shown. It should be noted that the index anomaly detection method can be applied to an index anomaly detection device, such as Figure 1 As shown, the index anomaly detection method may include the following steps:
[0035] S110, obtaining a first information table and a second information table;
[0036] S120, taking the first information table as the left table, taking the second information table as the right table, and taking the table name in the right table matching the table name in the left table as a condition, performing a left association on the left table and the right table to obtain an information association table;
[0037] S130, when the index name corresponding to the first table name in the information association table is empty, determining that the data table corresponding to the first table name has an index missing exception;
[0038] S140: When the index space corresponding to the second table name in the information association table and the data table space corresponding to the second table name meet a preset condition, determine that the data table corresponding to the second table name has an index expansion anomaly.
[0039] Thus, the first information table and the second information table can be obtained, wherein the first information table includes the table name and the occupied space of the data table in the database, and the second information table includes the table name, index name and index occupied space corresponding to the index data in the database, and then the first information table is used as the left table, the second information table is used as the right table, and the table name in the right table matches the table name in the left table. The left table and the right table are left-associated to obtain an information association table, which includes the table name, the occupied space of the data table, the index name and the occupied space of the index. In the case that the index name corresponding to the first table name in the information association table is empty, it is determined that the data table corresponding to the first table name has an index missing anomaly; in the case that the occupied space of the index corresponding to the second table name in the information association table and the occupied space of the data table corresponding to the second table name meet the preset conditions, it is determined that the data table corresponding to the second table name has an index expansion anomaly. In this way, accurate detection of index missing and index expansion can be achieved.
[0040] Regarding S110 , the first information table and the second information table may be constructed in advance.
[0041] The first information table may be an information table of a data table, and the second information table may be an information table of index data.
[0042] The first information table may include the table name and the space occupied by the data table in the database. The second information table may include the table name, index name and the space occupied by the index corresponding to the index data in the database.
[0043] Here, "data tables in a database" may refer to all data tables in the database.
[0044] Regarding S120, a left join may refer to querying the right table based on a column of data in the left table, and displaying the data existing on both sides. If no data is found on the right side, the left table data + NULL is displayed.
[0045] Here, left join may be used to associate the first information table with the second information table to obtain an information association table.
[0046] The information association table may include a table name, a data table occupied space, an index name, and an index occupied space.
[0047] Table names can be matched by the same table name.
[0048] For example, the first information table can be used as the left table, the second information table can be used as the right table, and table_name=index_table can be used as the condition to perform a left association on the left table and the right table to obtain an information association table, wherein table_name is the table name in the first information table, and index_table is the table name in the second information table.
[0049] In S130, the first table name is a table name corresponding to the empty index name.
[0050] If the index name corresponding to a table name is empty, it means that the data table corresponding to the table name is missing an index.
[0051] In S140, the second table name is the table name of a data table whose index occupied space and data table occupied space meet a preset condition.
[0052] If the space occupied by the index corresponding to a table name and the space occupied by the data table corresponding to the table name meet the preset conditions, it can be indicated that the data table corresponding to the table name has index expansion.
[0053] In some implementations, in order to accurately detect index expansion, the preset condition may be that the ratio of the space occupied by the index corresponding to the second table name to the space occupied by the data table corresponding to the second table name is greater than N times.
[0054] Here, N may be greater than 1. For example, N may be 2.
[0055] In this way, when the space occupied by the index of a data table exceeds N times the space occupied by the data table, it is determined that the data table has index expansion, thereby achieving accurate detection of index expansion.
[0056] After detecting index expansion and / or index missing, if users cannot discover it in time, they cannot make timely repairs, which may still cause system function timeouts or serious production incidents.
[0057] Based on this, in some implementations, in order to enable the user to promptly discover the existence of index expansion and / or index missing in the data table, the first information table may further include the number of rows of the data table in the database, and the information association table may further include the number of rows of the data table. After S120, the method may further include:
[0058] If the index name corresponding to the first table name in the information association table is empty, the first table name is marked with a first identifier; and if the index space corresponding to the second table name in the information association table and the data table space corresponding to the second table name meet a preset condition, the second table name is marked with a second identifier;
[0059] Determine the name of a third table marked with the first identifier or the second identifier;
[0060] Determine the number of rows and the space occupied by the data table corresponding to the third table name based on the information association table;
[0061] When the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space, a prompt message is output.
[0062] Here, if the index name corresponding to the first table name in the information association table is empty, it can indicate that the data table corresponding to the first table name has an index missing exception, and the first table name can be marked with a first identifier. The first identifier can indicate that the data table corresponding to the first table name has an index missing exception.
[0063] If the index space corresponding to the second table name in the information association table and the data table space corresponding to the second table name meet the preset conditions, it can be indicated that the data table corresponding to the second table name has an index expansion anomaly, and the second table name can be marked with a second identifier. The second identifier can indicate that the data table corresponding to the second table name has an index expansion anomaly.
[0064] Exemplarily, the first identifier may be “no index is created in the table”, and the second identifier may be “yes”.
[0065] Since index anomalies in a data table with a small amount of data usually do not cause serious consequences, in order to avoid frequent output of prompt information, when the third table name includes a target table name with a number of rows greater than a preset number of rows or a data table space greater than a preset space, a prompt information can be output, and the prompt information can be used to prompt the user that the data table corresponding to the target table name has an index anomaly. Among them, the number of rows in the data table greater than the preset number of rows or the space occupied by the data table greater than the preset space can indicate that the data table is a data table with a large amount of data, that is, a large database table.
[0066] The preset number of rows and the preset space can be set according to actual needs. For example, the preset number of rows can be 10 million rows, and the preset space can be 10G.
[0067] The third table name may be a table name marked with the first identifier or the second identifier.
[0068] The output form of the prompt information can be set according to actual needs. For example, it can be sending a text message to the user. The user can be a staff member.
[0069] Exemplarily, the first table name with an empty index name index_name can be marked with "No index created in the table" (that is, the first identifier). According to the rule of whether the space occupied by the index exceeds twice the space occupied by the data table, the judgment result field check_result is set, and the case when syntax is used. If the space occupied by the index exceeds twice the space occupied by the data table, it is set to YES (that is, the second identifier), and if it does not exceed, it is set to NO. In addition, the screening rule for large database tables can also be set as "the number of rows is greater than 10 million or the space occupied by the data table is greater than 10G". Then the relevant data can be entered into the log, and the first identifier and the second identifier are configured as keywords, and monitored based on the above screening rules. When the monitoring is marked with the first identifier or the second identifier and it is a large database table, a text message can be sent to notify the relevant personnel to handle it. The judgment result can be shown in Table 1.
[0070] Table 1-Judgment results table
[0071] table_name num_rows index_name index_GB table_GB check_result 1 AAAA 34385852 IDX_1 2.2050781 1.429687 NO 2 BBBB 34385852 IDX_3 0.1465454 1.429687 NO 3 CCCC 34385852 IDX_2 2.3829345 1.429687 NO 4 DDDD 13908420 UNION 0.53125 2.5 NO 5 EEEE 13908420 IDX_03 0.005859 2.5 NO
[0072] In this way, users can promptly discover the existence of index expansion and / or index missing in the data table, so as to take timely measures to avoid system function timeouts or serious production incidents.
[0073] After discovering index missing and / or index expansion, it needs to be repaired, but manual repair will result in high labor costs and low repair efficiency.
[0074] Based on this, in some implementations, in order to save labor costs and improve repair efficiency, when the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space, after outputting the prompt information, the method may further include:
[0075] In response to the user's input of the index anomaly repair time, generate an index anomaly repair script;
[0076] During the index exception repair time, run the index exception repair script.
[0077] Here, the index anomaly repair time may be a time period, and the index anomaly repair script may be started to run at the start time of the time period and completed before or at the end time of the time period.
[0078] The index anomaly repair script may be generated based on the index missing and / or index expansion detected above.
[0079] Running the index anomaly repair script can repair index missing and / or index expansion. Specifically, index missing can be repaired by adding index data, and index expansion can be repaired by rebuilding the index.
[0080] Exemplarily, after receiving the prompt information, the system manager can set the date and time for automatic index reconstruction (that is, the index anomaly repair time), the end-of-day batch processing time and the working hours in the configuration to realize the automatic processing of index reconstruction by the application. The index anomaly repair time cannot overlap or intersect with the end-of-day batch processing time and the working hours. The index reconstruction script can be automatically generated based on the inflated index or the uncreated index detected above, and the online mode is automatically set in SQL, which does not affect the reading and writing of the current data table. When the set index anomaly repair time is reached, the index reconstruction or the index anomaly repair script for the newly created index is automatically scheduled to execute.
[0081] In this way, an index anomaly repair script can be automatically generated based on user input, and the index anomaly repair script can be automatically run when the index anomaly repair time set by the user is reached, thereby realizing automatic and scheduled repair of index expansion and index missing without the need for manual processing, saving labor costs and improving repair efficiency.
[0082] Based on the above content, it can be known that the first information table may include the table name, number of rows and space occupied by the data table in the database. To accurately detect index anomalies, it is necessary to first construct an accurate first information table.
[0083] Based on this, in some implementations, in order to obtain an accurate first information table, such as Figure 2 As shown, before S110, the method may further include:
[0084] S210, querying the table name and the number of rows of a data table in the database through the first data dictionary, and querying the table name and the table occupied space of the data table in the database through the second data dictionary;
[0085] S220, taking the first data dictionary as the left table, taking the second data dictionary as the right table, and taking the table name in the right table matching the table name in the left table as a condition, left-join the left table and the right table to obtain a first information table.
[0086] Here, the first data dictionary may be a table data dictionary. For example, if the database is an Oracle database, the first data dictionary may be dba_tables, and if the database is a MySQL series database, the first data dictionary may be information_schema.tables.
[0087] The fields queried by the first data dictionary may include table name (table_name) and number of rows (num_rows), and may also include owner (owner). In this way, after the query, the first data dictionary may record the description of all data tables in the database. Specifically, the first data dictionary may record the table name and number of rows of the data tables in the database, and may also include the owner of the data tables in the database.
[0088] The second data dictionary may be a storage space data dictionary. For example, if the database is an Oracle database, the second data dictionary may be dba_segments, and if the database is a MySQL series database, the second data dictionary may be information_schema.tables.
[0089] The fields queried by the second data dictionary may include the segment name (segment_name) and the size of the segment (bytes), that is, the space occupied by the data table, and may also include the owner (owner). The segment name may include the table name (table_name) and the index name (index_name). In this way, after the query, the second data dictionary may record the storage space allocated to all database segments. Specifically, the second data dictionary may record the table name, index name and space occupied by the data table in the database, and may also include the owner of the data table.
[0090] Specifically, the table names and number of rows corresponding to all data tables in the database can be queried through the table data dictionary, and the data table occupied space corresponding to all data tables in the database can be queried through the storage space data dictionary. Then, the table data dictionary is used as the left table, the storage space data dictionary is used as the right table, table_name=segment_name is specified as the condition for matching, and the table names and number of rows in the left table that meet the condition, as well as the data table occupied space in the right table, are queried to obtain the first information table.
[0091] Exemplarily, the first information table may be as shown in Table 2.
[0092] Table 2-First Information Table
[0093] table_name num_rows table_GB 1 GGGG 2 0.00006103515625 2 HHHH 0 0.00006103515625 3 FFFF 0 0.00006103515625 4 LLLL 6 0.00006103515625 5 JJJJ 4329 0.00018310546875
[0094] In this way, the data required to construct the first information table is queried through the data dictionary, and the required data is associated with the left join method, so that an accurate first information table can be obtained.
[0095] Based on the above content, it can be known that the second information table may include the table name, index name and index occupied space corresponding to the index data in the database. To accurately detect index anomalies, it is necessary to first construct an accurate second information table.
[0096] Based on this, in some implementations, in order to obtain an accurate second information table, such as Figure 3 As shown, before S110, the method may further include:
[0097] S310, querying the table name and index name corresponding to the index data in the database through the third data dictionary, and querying the index name and index occupied space of the index data in the database through the fourth data dictionary;
[0098] S320, using the third data dictionary as the left table, the fourth data dictionary as the right table, and the index name in the right table matching the index name in the left table, perform a left join on the left table and the right table to obtain a second information table.
[0099] Here, the third data dictionary may be an index data dictionary. For example, if the database is an Oracle database, the third data dictionary may be dba_indexes, and if the database is a MySQL series database, the third data dictionary may be mysql.innodb_index_stats.
[0100] The fields queried by the third data dictionary may include the index name (index_name) and the table name (table_name) corresponding to the index data, and may also include the owner (owner). In this way, after the query, the third data dictionary may record the description of all index data in the database. Specifically, the third data dictionary may record the table name and index name corresponding to the index data in the database, and may also include the owner of the index data in the database.
[0101] The fourth data dictionary may be a storage space data dictionary. For example, if the database is an Oracle database, the fourth data dictionary may be dba_segments, and if the database is a MySQL series database, the fourth data dictionary may be information_schema.tables.
[0102] The fields queried by the fourth data dictionary may include the segment name (segment_name) and the size of the segment (bytes), that is, the index occupied space, and may also include the owner (owner). The segment name may include the table name (table_name) and the index name (index_name). In this way, after the query, the fourth data dictionary may record the storage space allocated to all database segments. Specifically, the fourth data dictionary may record the index name and index occupied space of the index data in the database, and may also include the owner of the index data.
[0103] Specifically, the table names and index names corresponding to all the index data in the database can be queried through the index data dictionary, and the index occupied spaces corresponding to all the index data in the database can be queried through the storage space data dictionary. Then, the index data dictionary is used as the left table, the storage space data dictionary is used as the right table, and index_name=segment_name is specified as the condition for matching, and the table names and index names corresponding to the index data in the left table that meet the condition, as well as the index occupied spaces in the right table, are queried to obtain the second information table.
[0104] Exemplarily, the second information table may be as shown in Table 3.
[0105] Table 3 - Second information table
[0106] index_table index_name index_GB 1 GGGG XXXX 0.00006103515625 2 HHHH YYYY 0.00006103515625 3 FFFF ZZZZ 0.000244140625 4 LLLL MMMM 0.00018310546875 5 JJJJ NNNN 5.0009765625
[0107] In this way, the data required to construct the second information table is queried through the data dictionary, and the required data is associated with the left join method, so that an accurate second information table can be obtained.
[0108] In order to prevent system operation risks, avoid production incidents, and highlight key focus objects, the embodiment of the present application provides an index anomaly detection method, which can realize the detection of index missing and index expansion, and when the index missing or index expansion of a large database table is detected, it is marked, and the first identifier or the second identifier is scanned in real time through the monitoring platform. When the first identifier or the second identifier is scanned, a prompt message is output to notify relevant personnel to handle it in time.
[0109] Based on the same inventive concept, the present application embodiment also provides an index anomaly detection device. Figure 4 The index anomaly detection device provided in the embodiment of the present application is described in detail.
[0110] Figure 4 A schematic diagram of the structure of an index anomaly detection device provided by an embodiment of the present application is shown.
[0111] like Figure 4 As shown, the index anomaly detection device may include:
[0112] The acquisition module 401 is used to acquire a first information table and a second information table, wherein the first information table includes a table name and a data table occupied space in a database, and the second information table includes a table name, an index name and an index occupied space corresponding to the index data in the database;
[0113] The first association module 402 is used to perform left association on the left table and the right table with the first information table as the left table and the second information table as the right table, and to obtain an information association table with the table name, the data table occupied space, the index name and the index occupied space as a condition;
[0114] The first determination module 403 is used to determine that there is an index missing exception in the data table corresponding to the first table name when the index name corresponding to the first table name in the information association table is empty;
[0115] The second determining module 404 is used to determine that the data table corresponding to the second table name has an index expansion anomaly when the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet a preset condition.
[0116] Thus, the first information table and the second information table can be obtained, wherein the first information table includes the table name and the occupied space of the data table in the database, and the second information table includes the table name, index name and index occupied space corresponding to the index data in the database, and then the first information table is used as the left table, the second information table is used as the right table, and the table name in the right table matches the table name in the left table. The left table and the right table are left-associated to obtain an information association table, which includes the table name, the occupied space of the data table, the index name and the occupied space of the index. In the case that the index name corresponding to the first table name in the information association table is empty, it is determined that the data table corresponding to the first table name has an index missing anomaly; in the case that the occupied space of the index corresponding to the second table name in the information association table and the occupied space of the data table corresponding to the second table name meet the preset conditions, it is determined that the data table corresponding to the second table name has an index expansion anomaly. In this way, accurate detection of index missing and index expansion can be achieved.
[0117] In some implementations, in order to enable a user to promptly discover that a data table has index expansion and / or index missing, the first information table further includes the number of rows of the data table in the database, and the information association table further includes the number of rows of the data table. The device may further include:
[0118] a marking module, configured to mark a first identifier for a first table name when an index name corresponding to a first table name in the information association table is empty, and to mark a second identifier for a second table name when an index space corresponding to a second table name in the information association table and a data table space corresponding to the second table name meet a preset condition;
[0119] A third determination module, used to determine a third table name marked with the first identifier or the second identifier;
[0120] A fourth determination module, used to determine the number of rows corresponding to the third table name and the space occupied by the data table based on the information association table;
[0121] The output module is used to output prompt information when the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space. The prompt information is used to prompt the user that the data table corresponding to the target table name has an index anomaly.
[0122] In some implementations, in order to obtain an accurate first information table, the apparatus may further include:
[0123] A first query module is used to query the table name and the number of rows of the data table in the database through the first data dictionary, and query the table name and the table occupied space of the data table in the database through the second data dictionary before obtaining the first information table and the second information table;
[0124] The second association module is used to left-associate the left table with the right table using the first data dictionary as the left table and the second data dictionary as the right table, and to obtain the first information table on the condition that the table name in the right table matches the table name in the left table.
[0125] In some implementations, in order to obtain an accurate second information table, the apparatus may further include:
[0126] A second query module is used to query the table name and index name corresponding to the index data in the database through the third data dictionary before obtaining the first information table and the second information table, and query the index name and index occupied space of the index data in the database through the fourth data dictionary;
[0127] The third association module is used to left-associate the left table and the right table with the third data dictionary as the left table and the fourth data dictionary as the right table, and to obtain the second information table on the condition that the index name in the right table matches the index name in the left table.
[0128] In some embodiments, in order to save labor costs and improve repair efficiency, the device may further include:
[0129] A generating module, configured to generate an index anomaly repair script in response to a user input of an index anomaly repair time after outputting a prompt message when the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space;
[0130] The run module is used to run the index exception repair script during the index exception repair time.
[0131] In some implementations, in order to accurately detect index expansion, a preset condition is that the ratio of the index space corresponding to the second table name to the data table space corresponding to the second table name is greater than N times, and N is greater than 1.
[0132] Figure 5A schematic structural diagram of an electronic device provided by an embodiment of the present application is shown.
[0133] like Figure 5 As shown, the electronic device 5 is a structural diagram of an exemplary hardware architecture of an electronic device that can implement the index anomaly detection method and index anomaly detection device in the embodiment of the present application. The electronic device can refer to the electronic device in the embodiment of the present application.
[0134] The electronic device 5 may include a processor 501 and a memory 502 storing computer program instructions.
[0135] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0136] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 502 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory. In a specific embodiment, the memory 502 may include a read-only memory (ROM), a random access memory (RAM), a disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical, or other physical / tangible memory storage device. Therefore, typically, the memory 502 includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to one aspect of the present application.
[0137] The processor 501 implements any one of the index anomaly detection methods in the above embodiments by reading and executing computer program instructions stored in the memory 502 .
[0138] In one example, the electronic device may further include a communication interface 503 and a bus 504. Figure 5 As shown, the processor 501, the memory 502, and the communication interface 503 are connected via a bus 504 and communicate with each other.
[0139] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0140] Bus 504 includes hardware, software or both, and the parts of electronic equipment are coupled to each other.For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 504 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0141] The electronic device can execute the index anomaly detection method in the embodiment of the present application, thereby realizing the combination Figures 1 to 4 Described is an index anomaly detection method and apparatus.
[0142] In addition, in combination with the index anomaly detection method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the index anomaly detection methods in the above embodiment is implemented.
[0143] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0144] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0145] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0146] The above reference is to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present application, and describes various aspects of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable index abnormal detection device to produce a machine, so that these instructions executed by the processor of the computer or other programmable index abnormal detection device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0147] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for detecting anomalies in an index, characterized in that: include: Obtain a first information table and a second information table, wherein the first information table includes a table name and a data table occupied space in a database, and the second information table includes a table name, an index name, and an index occupied space corresponding to index data in the database; Taking the first information table as the left table and the second information table as the right table, and taking the table name in the right table matching the table name in the left table as a condition, left-associate the left table and the right table to obtain an information association table, wherein the information association table includes the table name, the data table occupied space, the index name, and the index occupied space; When there is an index name corresponding to the first table name in the information association table that is empty, determining that there is an index missing exception in the data table corresponding to the first table name; When the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet a preset condition, it is determined that the data table corresponding to the second table name has an index expansion anomaly.
2. The method according to claim 1, characterized in that The first information table also includes the number of rows in the data table in the database, the information association table also includes the number of rows in the data table, and the method further includes: If the index name corresponding to the first table name in the information association table is empty, the first table name is marked with a first identifier; and if the index space corresponding to the second table name in the information association table and the data table space corresponding to the second table name meet a preset condition, the second table name is marked with a second identifier; Determine a third table name marked with the first identifier or the second identifier; Determine the number of rows and data table occupied space corresponding to the third table name based on the information association table; When the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space, a prompt message is output, wherein the prompt message is used to prompt the user that an index anomaly exists in the data table corresponding to the target table name.
3. The method according to claim 2, characterized in that Before obtaining the first information table and the second information table, the method further includes: Query the table name and the number of rows of the data table in the database through the first data dictionary, and query the table name and the table occupied space of the data table in the database through the second data dictionary; With the first data dictionary as the left table and the second data dictionary as the right table, and with the table name in the right table matching the table name in the left table as a condition, the left table and the right table are left-joined to obtain a first information table.
4. The method according to claim 2, characterized in that: Before obtaining the first information table and the second information table, the method further includes: Query the table name and index name corresponding to the index data in the database through the third data dictionary, and query the index name and index occupied space of the index data in the database through the fourth data dictionary; With the third data dictionary as the left table and the fourth data dictionary as the right table, and with the index name in the right table matching the index name in the left table as a condition, the left table and the right table are left-joined to obtain a second information table.
5. The method according to claim 2, characterized in that: When the third table name includes a target table name whose number of rows is greater than a preset number of rows or whose data table occupies a space greater than a preset space, after outputting the prompt information, the method further includes: In response to the user's input of the index anomaly repair time, generate an index anomaly repair script; During the index anomaly repair time, the index anomaly repair script is run.
6. The method according to claim 1, characterized in that The preset condition is that the ratio of the space occupied by the index corresponding to the second table name to the space occupied by the data table corresponding to the second table name is greater than N times, and N is greater than 1.
7. An index anomaly detection device, characterized in that: include: An acquisition module, used to acquire a first information table and a second information table, wherein the first information table includes a table name and a data table occupied space in a database, and the second information table includes a table name, an index name and an index occupied space corresponding to the index data in the database; A first association module is used to take the first information table as a left table, take the second information table as a right table, and take the table name in the right table as a condition to match the table name in the left table, perform left association on the left table and the right table to obtain an information association table, wherein the information association table includes a table name, a data table occupied space, an index name, and an index occupied space; A first determining module, configured to determine that an index missing exception exists in a data table corresponding to a first table name when an index name corresponding to the first table name in the information association table is empty; The second determination module is used to determine that there is an index expansion anomaly in the data table corresponding to the second table name when the index occupied space corresponding to the second table name in the information association table and the data table occupied space corresponding to the second table name meet a preset condition.
8. An electronic device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the index anomaly detection method according to any one of claims 1 to 6 is implemented.
9. A computer storage medium, characterized in that The computer storage medium stores computer program instructions, and when the computer program instructions are executed by the processor, the index anomaly detection method according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the index anomaly detection method as described in any one of claims 1 to 6.
