Database index changing method and device, electronic equipment and storage medium

By copying and changing the database index information, and comparing the query time to determine the replacement conditions, the abnormality problem caused by the database index change in the existing technology is solved, and the query efficiency and system reliability are improved without affecting the historical data query.

CN118568111APending Publication Date: 2024-08-30PINGAN YIQIANBAO E COMMERCE CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410725591.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing database index changing methods are prone to abnormal situations during data query, insertion, update, and deletion operations, leading to production line failures, and it is difficult to improve query efficiency without affecting historical data query.

Method used

By copying the target table and target index information, changing the temporary index information, and using the target index information and changed index information to execute multiple query statements, compare the query time to determine whether the replacement conditions are met, and if so, replace the target table with the temporary table to ensure query efficiency and data integrity.

Benefits of technology

It effectively avoids abnormal situations in database operations, improves query efficiency and system reliability, and ensures the normal operation of the production line.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568111A
    Figure CN118568111A
Patent Text Reader

Abstract

The invention relates to the technical field of databases, and discloses a database index changing method and device, electronic equipment and a storage medium. The method comprises the following steps: copying an obtained target table and target index information to obtain a temporary table and temporary index information; changing the temporary index information to obtain changed index information; obtaining a plurality of query statements of the target table, and executing the plurality of query statements in the target table by utilizing the target index information to obtain first query time; executing the plurality of query statements in the temporary table by utilizing the change index information to obtain second query time; based on the first query time, the second query time and preset query time, judging whether the change index information enables the temporary table to meet a replacement condition or not; and if yes, replacing the target table with the temporary table to obtain a replaced target table. According to the method, the target table is replaced with the temporary table under the condition that the change index information of the temporary table does not affect historical data query and the query efficiency can be improved, and normal operation of a production line is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of database technology, and in particular to a method, device, electronic device and storage medium for changing a database index. Background Art

[0002] A database is a warehouse that organizes, stores, and manages data according to data structures. As the number of records in a database increases, the efficiency of database query operations becomes lower and lower. In order to improve query efficiency, you can create indexes on one or more columns in a table so that you can locate the data you want to query more quickly, thereby reducing query time and resource consumption.

[0003] In the process of using the database, it is often necessary to change the index of the table. In the related technology, a new index is usually added based on the original index, or a temporary table is added and renamed to the name of the target table. However, when using the changed index obtained by this method to query, insert, update, and delete data, there will be abnormal situations, such as incorrect query results, deletion of data that needs to be retained, etc., which directly leads to production line failure. Summary of the invention

[0004] In view of the above situation, the embodiments of the present application provide a method, device, electronic device and storage medium for changing a database index, aiming to solve the above problem or at least partially solve the above problem.

[0005] In a first aspect, an embodiment of the present application provides a method for changing a database index, the method comprising:

[0006] The obtained target table and target index information are copied to obtain a temporary table and temporary index information;

[0007] Changing the temporary index information to obtain changed index information;

[0008] Acquire multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the change index information to obtain a second query time;

[0009] Based on the first query time, the second query time, and the preset query time, determining whether the changed index information causes the temporary table to meet a replacement condition;

[0010] If the change index information makes the temporary table meet the replacement condition, the target table is replaced with the temporary table to obtain a replaced target table.

[0011] In a second aspect, an embodiment of the present application further provides a device for changing a database index, the device comprising:

[0012] A copy module is used to copy the acquired target table and target index information to obtain a temporary table and temporary index information;

[0013] A changing module, used for changing the temporary index information to obtain changed index information;

[0014] A query module, configured to obtain multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the change index information to obtain a second query time;

[0015] A judgment module, configured to judge whether the change index information makes the temporary table meet a replacement condition based on the first query time, the second query time and a preset query time;

[0016] A replacement module is used to replace the target table with the temporary table to obtain a replaced target table if the change index information makes the temporary table meet the replacement condition.

[0017] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor; and a memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor executes the steps of the above-mentioned method for changing the database index.

[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which stores one or more programs. When the one or more programs are executed by an electronic device including multiple applications, the electronic device executes the steps of the above-mentioned method for changing the database index.

[0019] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:

[0020] The method for changing a database index provided in an embodiment of the present application first copies the acquired target table and target index information to obtain a temporary table and temporary index information; changes the temporary index information to obtain the changed index information; obtains multiple query statements of the target table, and executes the multiple query statements in the target table using the target index information to obtain a first query time; and executes the multiple query statements in the temporary table using the changed index information to obtain a second query time; based on the first query time, the second query time and the preset query time, determines whether the changed index information makes the temporary table meet the replacement condition; if the changed index information makes the temporary table meet the replacement condition, replaces the target table with the temporary table to obtain the replaced target table. It can be seen that, unlike the prior art, the embodiment of the present application first determines whether the change index information of the temporary table can improve the query efficiency without affecting the historical data query through the first query time, the second query time and the preset query time before replacing the target table with the temporary table. If so, the target table is replaced with the temporary table to obtain the replaced target table, which improves the reliability of the temporary table and avoids the following situations: abnormal situations when using the change index information to query, insert, update, and delete data operations; high database active sessions; database downtime; high CPU usage, etc., thereby ensuring the normal operation of the production line. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0022] Figure 1 A schematic diagram showing a flow chart of a method for changing a database index provided in an embodiment of the present application is shown;

[0023] Figure 2 A flowchart showing a method for changing a database index provided by another embodiment of the present application is shown;

[0024] Figure 3 A structural diagram of a device for changing a database index provided in an embodiment of the present application is shown;

[0025] Figure 4 A schematic structural diagram of an electronic device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that such use is interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the term "including" and its variants are to be interpreted as open-ended terms meaning "including but not limited to".

[0028] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.

[0029] As mentioned above, the existing technology usually adds a new index based on the original index, or renames the temporary table to the name of the target table after adding a temporary table. However, when using the changed index obtained by this method to query, insert, update, and delete data operations, there will be abnormal situations.

[0030] Based on this, the embodiment of the present application proposes a method for changing a database index. Different from the prior art, before replacing the target table with a temporary table, the embodiment of the present application first determines whether the change index information of the temporary table can improve the query efficiency without affecting the historical data query through the first query time, the second query time and the preset query time. If so, the target table is replaced with the temporary table to obtain the replaced target table, which improves the reliability of the temporary table and avoids the following situations: abnormal situations when querying, inserting, updating and deleting data using the change index information; high database active sessions; database downtime; high CPU usage, etc., thereby ensuring the normal operation of the production line. The present application is described in detail below through specific embodiments.

[0031] Figure 1 A schematic diagram showing a flow chart of a method for changing a database index provided in an embodiment of the present application is shown. Figure 1 It can be seen that the present application at least includes steps S101 to S105:

[0032] Step S101: copy the acquired target table and target index information to obtain a temporary table and temporary index information.

[0033] The execution subject of the method for changing the database index provided in the embodiment of the present application is generally a computer device with certain computing power, and the computer device includes, for example, a terminal device or a server. In some possible implementations, the method for changing the database index can be implemented by a processor calling a computer-readable instruction stored in a memory. The database in the embodiment of the present application can be: MySQL, Oracle, Microsoft SQL Server, Microsoft Access, Sybase, etc. For the convenience of description, MySQL is used as an example for explanation below.

[0034] During implementation, in this step, the target table can be completely copied, and the copy objects include tables, data, indexes, triggers, primary key constraints, foreign key constraints, etc. Therefore, the target index information is also copied at the same time. For example, data can be selected from the target table and inserted into a temporary table. Specifically, the following statement can be executed to implement the copy process: INSERT temporary table table name SELECT * FROM target table table name. For another example, a temporary table can be directly created based on the target table. Specifically, the following statement can be executed to implement the copy process: CREATE TABLE IF NOT EXISTS temporary table table name LIKE target table table name.

[0035] Step S102: Change the temporary index information to obtain the changed index information.

[0036] After obtaining the temporary table and temporary index information, the index of the temporary table can be changed through SQL statements to obtain the changed index information.

[0037] In one possible implementation, changing the temporary index information to obtain the changed index information includes: creating a first target index in the temporary index information; and / or deleting the second target index in the temporary index information; and / or modifying the third target index in the temporary index information to obtain the changed index information.

[0038] During implementation, you can create an index in the temporary index information by executing the following command statements: create index index name on temporary table table name (column name); create unique index index name on temporary table table name (column name). You can delete an index in the temporary index information by executing the following command statements: drop index index name on temporary table table name; alter table temporary table name drop index index name; alter table temporary table name drop primary key (delete the primary key index). You can modify the index in the temporary index information by executing the following command statements: alter table temporary table name add index index name (column name) (create a normal index); alter table temporary table name add unique index name (column name) (create a unique index); alter table temporary table name add primary key (column name) (create a primary key index).

[0039] In this embodiment, the change of the temporary index information includes at least one of the following methods: creating an index in the temporary index information, deleting an index in the temporary index information, and modifying an index in the temporary index information. For example, in some embodiments, the command statement: create index index name 1 on temporary table table name (column name 1) can be executed to create a first target index 1 based on the temporary index information to obtain the changed index information.

[0040] In other embodiments, the command statement: drop index index name 2 on temporary table table name can be executed to delete the second target index 1 in the temporary index information to obtain the intermediate index information 1, and then the command statement: alter table temporary table table name add index index name 3 (column name 2) can be executed to modify the third target index 1 in the intermediate index information 1 to obtain the changed index information.

[0041] In some other embodiments, the command statement: create unique index index name 4 on temporary table table name (column name 3) can be executed to create a first target index 2 based on the temporary index information to obtain intermediate index information 2; then, the command statement: alter table temporary table table name drop index index name 5 can be executed to delete the second target index 2 in the intermediate index information 2 to obtain intermediate index information 3; finally, the command statement: alter table temporary table name add unique index name 6 (column name 4) can be executed to modify the third target index 2 in the intermediate index information 3 to obtain the changed index information.

[0042] Step S103: obtaining multiple query statements of the target table, and executing the multiple query statements in the target table using the target index information to obtain a first query time; and executing the multiple query statements in the temporary table using the changed index information to obtain a second query time.

[0043] MySQL has built-in multiple log functions, such as slow query log, general query log, etc. The MySQL log file records the executed SQL statements. Therefore, in this step, the query log can be screened first to obtain all query statements for the target table, such as query statement 1, query statement 2, and query statement 3. Then, query statement 1, query statement 2, and query statement 3 are executed in the target table in sequence using the target index information to obtain the total time for executing the above three statements, i.e., the first query time. Similarly, query statement 1, query statement 2, and query statement 3 are executed in sequence in the temporary table using the change index information to obtain the second query time.

[0044] Step S104: Based on the first query time, the second query time and the preset query time, it is determined whether the changed index information makes the temporary table meet the replacement condition.

[0045] Before the step of copying the acquired target table and target index information to obtain the temporary table and temporary index information, the target index information may be used to execute multiple query statements in the target table to obtain a preset query time.

[0046] After obtaining the first query time and the second query time, it can be determined whether the difference between the first query time and the preset query time is within a preset range. If so, it indicates that using the changed index information will not affect the speed of historical data query; at the same time, it is determined whether the difference between the second query time and the preset query time is within a preset range. If so, it indicates that using the changed index information can improve the speed of data query. If using the changed index information does not affect the speed of historical data query and can improve the speed of data query, it is determined whether the changed index information makes the temporary table meet the replacement condition.

[0047] In one possible implementation, based on the first query time, the second query time and the preset query time, it is determined whether the changed index information makes the temporary table meet the replacement condition, including: if the difference between the preset query time and the first query time is greater than or equal to the preset first threshold, and the difference between the preset query time and the second query time is greater than or equal to the preset second threshold, then the index information is changed so that the temporary table meets the replacement condition; if the difference between the preset query time and the first query time is less than the preset first threshold, and / or the difference between the preset query time and the second query time is less than the preset second threshold, then the index information is changed so that the temporary table does not meet the replacement condition.

[0048] For example, if the preset query time is 10ms, the first query time is 11ms, the second query time is 9ms, the preset first threshold is -1ms, and the preset second threshold is 0.5ms, then the difference between the preset query time and the first query time is -1ms, which is equal to the preset first threshold. At the same time, the difference between the preset query time and the second query time is 1ms, which is greater than the preset second threshold, which indicates that the change in index information makes the temporary table meet the replacement condition. For another example, if the preset query time is 10ms, the first query time is 12ms, and the second query time is 9ms, the preset first threshold is -1ms, and the preset second threshold is 0.5ms, then the difference between the preset query time and the first query time is -2ms, which is less than the preset first threshold. The difference between the preset query time and the second query time is 1ms, which is greater than the preset second threshold, which indicates that the change in index information makes the temporary table not meet the replacement condition. For another example, suppose the preset query time is 10ms, the first query time is 10ms, the second query time is 9.9ms, the preset first threshold is -1ms, and the preset second threshold is 0.5ms. The difference between the preset query time and the first query time is 0ms, which is greater than the preset first threshold. The difference between the preset query time and the second query time is 0.1ms, which is less than the preset second threshold. This indicates that the change in index information makes the temporary table not meet the replacement condition. For another example, suppose the preset query time is 10ms, the first query time is 12ms, and the second query time is 9.8ms. The preset first threshold is -1ms, and the preset second threshold is 0.5ms. The difference between the preset query time and the first query time is -2ms, which is less than the preset first threshold. The difference between the preset query time and the second query time is 0.2ms, which is less than the preset second threshold. This indicates that the change in index information makes the temporary table not meet the replacement condition. The aforementioned preset first threshold and preset second threshold can be set according to actual needs, and this application does not limit this.

[0049] Step S105: If the index information is changed so that the temporary table meets the replacement condition, the target table is replaced with the temporary table to obtain a replaced target table.

[0050] During implementation, if the index information is changed so that the temporary table meets the replacement condition, the target table can be replaced with the temporary table to obtain a replaced target table, and the index information corresponding to the replaced target table is the changed index information.

[0051] In a possible implementation, replacing the target table with the temporary table to obtain the replaced target table includes: exchanging the table name of the target table with the table name of the temporary table to obtain the replaced target table.

[0052] In the embodiment of the present application, the following atomic operations may be performed: alter B rename A, A to B, renaming the table name A of the target table to the table name B of the temporary table, and renaming the table name B of the temporary table to the table name A of the target table.

[0053] from Figure 1 It can be seen from the method shown that the embodiment of the present application first copies the acquired target table and target index information to obtain a temporary table and temporary index information; changes the temporary index information to obtain the changed index information; obtains multiple query statements for the target table, and uses the target index information to execute the multiple query statements in the target table to obtain a first query time; and uses the changed index information to execute the multiple query statements in the temporary table to obtain a second query time; based on the first query time, the second query time and the preset query time, determines whether the changed index information makes the temporary table meet the replacement condition; if the changed index information makes the temporary table meet the replacement condition, the target table is replaced with the temporary table to obtain the replaced target table.

[0054] It can be seen that, unlike the prior art, the embodiment of the present application first determines whether the change index information of the temporary table can improve the query efficiency without affecting the historical data query through the first query time, the second query time and the preset query time before replacing the target table with the temporary table. If so, the target table is replaced with the temporary table to obtain the replaced target table, which improves the reliability of the temporary table and avoids the following situations: abnormal situations when querying, inserting, updating and deleting data using the change index information; high database active sessions; database downtime; high CPU usage, etc., thereby ensuring the normal operation of the production line.

[0055] In a possible implementation, the acquired target table and target index information are copied to obtain a temporary table and temporary index information, including: creating a new initial temporary table; inserting the initial data in the acquired target table into the initial temporary table to obtain an intermediate temporary table; according to the table modification log of the target table, synchronously writing the newly added data in the target table into the intermediate temporary table to obtain a temporary table and temporary index information.

[0056] Considering that the data in the target table will be continuously updated, during implementation, you can first create a new initial temporary table according to the following statement, insert the initial data in the target table into the initial temporary table, and obtain an intermediate temporary table: INSERT temporary table name SELECT * FROM target table name.

[0057] Then, according to the table modification log of the target table, the newly added data in the target table can be synchronously written into the intermediate temporary table to obtain the temporary table and temporary index information. For example, the binary log (binlog) can be used for synchronous writing. The binlog can record the SQL statements that have or may have changed the target table data and save them in binary form on the disk. Therefore, by executing the statements in the binlog (such as INSERT, UPDATE, DELETE, etc.), the newly added data in the target table can be synchronously written into the intermediate temporary table to obtain the temporary table, where the temporary table includes temporary index information.

[0058] In a possible implementation, the method further includes: if the change index information causes the temporary table to not satisfy the replacement condition, modifying the change index information to obtain the modified change index information, and using the modified change index information as the new change index information; returning to obtain multiple query statements for the target table, and using the target index information to execute the multiple query statements in the target table to obtain a first query time; and using the change index information to execute the multiple query statements in the temporary table to obtain a second query time.

[0059] In this embodiment, if the change index information makes the temporary table fail to meet the replacement condition, for example, the difference between the preset query time and the first query time is greater than the preset first threshold, and the difference between the preset query time and the second query time is less than the preset second threshold, it indicates that although the use of the change index information will not affect the speed of historical data query, it will not improve the query efficiency. Therefore, the developer can analyze each query process according to the execution plan, and the server modifies the change index information according to the input of the developer to obtain the modified change index information, and uses the modified change index information as the new change index information, and then uses the target index information to execute multiple query statements in the target table to obtain the third query time, and uses the target index information to execute multiple query statements in the target table to obtain the fourth query time; it is determined whether the difference between the preset query time and the third query time is greater than or equal to the preset first threshold, and whether the difference between the preset query time and the fourth query time is greater than or equal to the preset second threshold. If so, the target table is replaced with the temporary table to obtain the replaced target table; if not, the change index information is continuously modified and judged until the change index information makes the temporary table meet the replacement condition.

[0060] Figure 2 A schematic diagram showing a flow chart of a method for changing a database index provided by another embodiment of the present application is shown. Figure 2 It can be seen that this embodiment includes the following steps S201-S208:

[0061] Step S201: Create an initial temporary table.

[0062] Step S202: inserting the acquired initial data in the target table into the initial temporary table to obtain an intermediate temporary table.

[0063] Step S203: according to the table modification log of the target table, the newly added data in the target table is synchronously written into the intermediate temporary table to obtain the temporary table and temporary index information.

[0064] Step S204: create a first target index in the temporary index information; and / or delete a second target index in the temporary index information; and / or modify a third target index in the temporary index information to obtain changed index information.

[0065] Step S205: Obtain multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the changed index information to obtain a second query time.

[0066] Step S206: Determine whether the difference between the preset query time and the first query time is greater than or equal to the preset first threshold, and whether the difference between the preset query time and the second query time is greater than or equal to the preset second threshold. If so, go to step S207; if not, go to step S208.

[0067] Step S207: swap the table name of the target table with the table name of the temporary table to obtain a replaced target table.

[0068] Step S208: modify the change index information to obtain the modified change index information, and use the modified change index information as the new change index information, and then go to step S205.

[0069] Figure 3 A schematic diagram of the structure of a device for changing a database index provided in an embodiment of the present application is shown, wherein the device 300 for changing a database index includes:

[0070] The copy module 301 is used to copy the acquired target table and target index information to obtain a temporary table and temporary index information.

[0071] The changing module 302 is used to change the temporary index information and obtain the changed index information.

[0072] The query module 303 is used to obtain multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the change index information to obtain a second query time.

[0073] The judgment module 304 is used to judge whether the changed index information makes the temporary table meet the replacement condition based on the first query time, the second query time and the preset query time.

[0074] The replacement module 305 is used to replace the target table with the temporary table to obtain a replaced target table if the index information is changed so that the temporary table meets the replacement condition.

[0075] In a possible implementation manner, in the above device, the copy module 301 is further used for:

[0076] Create a new initial temporary table;

[0077] Insert the initial data in the target table into the initial temporary table to obtain an intermediate temporary table;

[0078] According to the table modification log of the target table, the newly added data in the target table is synchronously written into the intermediate temporary table to obtain the temporary table and temporary index information.

[0079] In a possible implementation manner, in the above device, the changing module 302 is further configured to:

[0080] Creating a first target index in the temporary index information; and / or

[0081] Deleting the second target index in the temporary index information; and / or

[0082] The third target index in the temporary index information is modified to obtain the changed index information.

[0083] In a possible implementation manner, in the above device, the determination module 304 is further configured to:

[0084] If the difference between the preset query time and the first query time is greater than or equal to the preset first threshold, and the difference between the preset query time and the second query time is greater than or equal to the preset second threshold, the index information is changed so that the temporary table meets the replacement condition;

[0085] If the difference between the preset query time and the first query time is less than a preset first threshold, and / or the difference between the preset query time and the second query time is less than a preset second threshold, the index information is changed so that the temporary table does not meet the replacement condition.

[0086] In a possible implementation, in the above device, the replacement module 305 is further configured to: exchange the table name of the target table with the table name of the temporary table to obtain a replaced target table.

[0087] In a possible implementation manner, the apparatus further includes a modification module, which is used to: if the change index information causes the temporary table to not satisfy the replacement condition, modify the change index information to obtain modified change index information, and use the modified change index information as new change index information;

[0088] Return to the step of obtaining multiple query statements of the target table, and executing multiple query statements in the target table using the target index information to obtain the first query time; and executing multiple query statements in the temporary table using the changed index information to obtain the second query time. It should be noted that any of the above-mentioned database index change devices can implement the above-mentioned database index change method in a one-to-one correspondence manner, which will not be repeated here.

[0089] Figure 4 FIG. 1 is a schematic diagram showing the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown, at the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. Among them, the memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage, etc. Of course, the electronic device may also include hardware required for other services.

[0090] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0091] The memory is used to store programs. Specifically, the program may include program code, and the program code includes computer operation instructions. The memory may include internal memory and non-volatile memory, and provides instructions and data to the processor.

[0092] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a device for changing the database index at the logical level. The processor executes the program stored in the memory and is specifically used to execute the above method.

[0093] The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor to be executed. The software module may be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0094] The electronic device can execute the method for changing the database index provided in multiple embodiments of the present application, and realize the device for changing the database index in Figure 3 The functions of the illustrated embodiment will not be described in detail in the embodiments of the present application.

[0095] An embodiment of the present application also proposes a computer-readable storage medium, which stores one or more programs, and the one or more programs include instructions. When the instructions are executed by an electronic device including multiple application programs, the electronic device can execute the method of changing the database index provided by multiple embodiments of the present application.

[0096] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0097] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0098] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0099] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0101] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0102] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0103] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity or device including the element.

[0104] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0105] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A method for changing a database index, characterized in that: The method comprises: The obtained target table and target index information are copied to obtain a temporary table and temporary index information; Changing the temporary index information to obtain changed index information; Acquire multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the change index information to obtain a second query time; Based on the first query time, the second query time, and the preset query time, determining whether the changed index information causes the temporary table to meet a replacement condition; If the change index information makes the temporary table meet the replacement condition, the target table is replaced with the temporary table to obtain a replaced target table.

2. The method according to claim 1, characterized in that The step of copying the acquired target table and target index information to obtain a temporary table and temporary index information includes: Create a new initial temporary table; Inserting the initial data in the acquired target table into the initial temporary table to obtain an intermediate temporary table; According to the table modification log of the target table, the newly added data in the target table is synchronously written into the intermediate temporary table to obtain the temporary table and temporary index information.

3. The method according to claim 1, characterized in that The changing the temporary index information to obtain the changed index information includes: Creating a first target index in the temporary index information; and / or Deleting the second target index in the temporary index information; and / or The third target index in the temporary index information is modified to obtain the changed index information.

4. The method according to claim 1, characterized in that: The determining, based on the first query time, the second query time, and the preset query time, whether the changed index information causes the temporary table to meet a replacement condition includes: If the difference between the preset query time and the first query time is greater than or equal to a preset first threshold, and the difference between the preset query time and the second query time is greater than or equal to a preset second threshold, then the index information is changed so that the temporary table meets the replacement condition; If the difference between the preset query time and the first query time is less than the preset first threshold, and / or the difference between the preset query time and the second query time is less than the preset second threshold, the change index information makes the temporary table not meet the replacement condition.

5. The method according to claim 1, characterized in that The step of replacing the target table with the temporary table to obtain a replaced target table includes: The table name of the target table is exchanged with the table name of the temporary table to obtain the replaced target table.

6. The method according to claim 4, characterized in that The method further comprises: If the change index information causes the temporary table to not satisfy the replacement condition, modify the change index information to obtain modified change index information, and use the modified change index information as new change index information; Return to the step of obtaining multiple query statements of the target table, and using the target index information to execute the multiple query statements in the target table to obtain a first query time; and using the change index information to execute the multiple query statements in the temporary table to obtain a second query time.

7. A device for changing a database index, characterized in that: The device comprises: A copy module is used to copy the acquired target table and target index information to obtain a temporary table and temporary index information; A changing module, used for changing the temporary index information to obtain changed index information; A query module, configured to obtain multiple query statements of the target table, and execute the multiple query statements in the target table using the target index information to obtain a first query time; and execute the multiple query statements in the temporary table using the change index information to obtain a second query time; A judgment module, configured to judge whether the change index information makes the temporary table meet a replacement condition based on the first query time, the second query time and a preset query time; A replacement module is used to replace the target table with the temporary table to obtain a replaced target table if the change index information makes the temporary table meet the replacement condition.

8. The device according to claim 7, characterized in that The replication module is also used to: Create a new initial temporary table; Inserting the initial data in the acquired target table into the initial temporary table to obtain an intermediate temporary table; According to the table modification log of the target table, the newly added data in the target table is synchronously written into the intermediate temporary table to obtain the temporary table and temporary index information.

9. An electronic device, comprising: processor; as well as A memory arranged to store computer executable instructions, wherein when the executable instructions are executed, the processor executes the steps of the method for changing a database index as claimed in any one of claims 1 to 6.

10. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of application programs, enables the electronic device to perform the steps of the method for changing a database index as described in any one of claims 1 to 6.

Citation Information

Cited By

  • Database index updating method and device, equipment and medium

    CN120216525A