A method, apparatus, device and storage medium for secondary index transfer

By transferring the secondary index to a secondary index table in the distributed database, the problem of not being able to specify the shard key for secondary index queries is solved, thus achieving high efficiency and performance improvement for secondary index queries.

CN114090622BActive Publication Date: 2025-12-02CHINA CONSTRUCTION BANK
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111388240.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-22
Publication Date
2025-12-02
Estimated Expiration
2041-11-22

AI Technical Summary

Technical Problem

In a distributed database, if a secondary index query cannot specify a shard key, the query statement will be distributed across all shards, resulting in significant time and performance overhead.

Method used

If the secondary index meets the preset transfer conditions, including the number of secondary index queries being greater than the number of insert, delete, and update operations and not containing a sharding key of the primary key index, the secondary index is transferred to a secondary index table. The primary key field and non-primary key fields of the secondary index table are then constructed, and the field that meets the sharding conditions is selected as the sharding key.

Benefits of technology

This avoids cross-shard queries for secondary indexes, improving the efficiency and performance of secondary index queries and reducing the cost of accessing database tables.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090622B_ABST
    Figure CN114090622B_ABST
Patent Text Reader

Abstract

This invention relates to the field of distributed database technology, specifically a method, apparatus, device, and storage medium for transferring secondary indexes. The method includes: obtaining a secondary index of a target data table, wherein the target data table includes multiple data shards; determining whether the secondary index meets preset transfer conditions; and when the secondary index meets the preset transfer conditions, constructing a secondary index table for secondary index queries based on the secondary index. The secondary index transfer method of this invention, based on the characteristic that distributed database data is distributed across multiple shards, transfers the secondary index into a secondary index table for secondary index queries when the secondary index of the data table meets the transfer conditions. When using the secondary index for queries, it becomes a primary key query using the secondary index table, which avoids cross-shard queries and greatly improves the efficiency of secondary index queries.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed database technology, and in particular to a method, apparatus, device, and storage medium for transferring secondary indexes. Background Technology

[0002] With the development of the financial industry, the transaction system of banks' core systems has gradually become larger, and the size and growth rate of system data are also increasing rapidly. The drawbacks of traditional centralized architecture, such as insufficient scalability and high cost, have gradually become apparent, and the distributed transformation of banks has been put on the agenda.

[0003] The distributed transformation of the bank's core system requires the use of a distributed database. Distributed databases are limited by the performance and storage capacity of a single physical node, so data tables need to be split according to certain rules and stored on different physical nodes.

[0004] The most significant difference between distributed and centralized databases is sharding. Current technologies typically employ sharding methods such as hash sharding, range sharding, and list sharding, generally selecting a sharding key, which is usually a field of the primary key. This allows most queries to directly specify the sharding key, accurately determining which shard the retrieved data belongs to, thereby reducing the cost of data access and speeding up response time.

[0005] However, in actual querying, some query statements cannot specify the shard key. In this case, a secondary index is usually created to ensure query efficiency on a single shard. Since it is impossible to accurately determine which shard the data to be queried is located on, the query statement will be distributed to all shards, resulting in a lot of unnecessary time and performance loss. Summary of the Invention

[0006] In view of the above-mentioned problems in the prior art, the purpose of the present invention is to provide a secondary index transfer method, apparatus, device and storage medium that can avoid cross-slice secondary index queries, thereby improving the efficiency of secondary index queries.

[0007] To address the above problems, this invention provides a secondary index transfer method, comprising:

[0008] Obtain the secondary index of the target data table, wherein the target data table includes multiple data shards;

[0009] Determine whether the sub-index meets the preset transfer conditions;

[0010] When the secondary index meets the preset transfer conditions, a secondary index table is constructed based on the secondary index for performing secondary index queries.

[0011] Optionally, determining whether the secondary index meets the preset transfer conditions includes:

[0012] Obtain the number of index queries and the number of insert, delete, and update operations corresponding to the target data table;

[0013] Determine whether the number of index queries is greater than the number of insert, delete, and update operations;

[0014] Determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0015] When the number of queries to the secondary index is greater than the number of insert, delete, and update operations, and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions.

[0016] Otherwise, it is determined that the sub-index does not meet the preset transfer conditions.

[0017] Optionally, determining whether the secondary index meets the preset transfer conditions includes:

[0018] Obtain the data table type corresponding to the target data table;

[0019] Determine whether the data table type is a query type;

[0020] Determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0021] When the data table type is query type and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions;

[0022] Otherwise, it is determined that the sub-index does not meet the preset transfer conditions.

[0023] Furthermore, when the secondary index meets the preset transfer conditions, constructing a secondary index table based on the secondary index for performing secondary index queries includes:

[0024] Retrieve field information from the sub-index;

[0025] The field information is used as the primary key field of the secondary index table, and the secondary index table is constructed based on the primary key field of the secondary index table.

[0026] Furthermore, the step of constructing a secondary index table for secondary index queries based on the secondary index when the secondary index meets the preset transfer conditions further includes:

[0027] The fields in the primary key index of the target data table, excluding the shard key and the field information in the secondary index, are used as non-primary key fields of the secondary index table;

[0028] The non-primary key fields of the secondary index table are deleted to obtain the target secondary index table.

[0029] Furthermore, the step of constructing a secondary index table for secondary index queries based on the secondary index when the secondary index meets the preset transfer conditions further includes:

[0030] Determine whether each field in the sub-index meets the preset sharding conditions;

[0031] One or more fields are selected from the fields that meet the preset sharding conditions and used as the sharding keys of the secondary index table.

[0032] Furthermore, determining whether each field information in the sub-index satisfies the preset sharding conditions includes:

[0033] For each field in the sub-index, determine whether the field information can be evenly distributed to the various data shards of the target data table based on a certain preset sharding method;

[0034] If so, the field information is determined to meet the preset sharding conditions;

[0035] If not, the field information is determined not to meet the preset sharding conditions.

[0036] Another aspect of the present invention provides a secondary index transfer device, comprising:

[0037] The acquisition module is used to acquire the secondary index of the target data table, wherein the target data table includes multiple data shards;

[0038] The judgment module is used to determine whether the sub-index meets the preset transfer conditions;

[0039] A construction module is used to construct a secondary index table for performing secondary index queries based on the secondary index when the secondary index meets the preset transfer conditions.

[0040] In another aspect, the present invention provides an electronic device including a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the sub-index transfer method as described above.

[0041] In another aspect, the present invention provides a computer-readable storage medium storing at least one instruction or at least one program, wherein the at least one instruction or the at least one program is loaded and executed by a processor to implement the sub-index transfer method as described above.

[0042] In another aspect, the present invention provides a computer program product, including a computer program / instruction that, when executed by a processor, implements the steps of the sub-index transfer method described above.

[0043] Due to the above technical solution, the present invention has the following beneficial effects:

[0044] According to the secondary index transfer method of the present invention, based on the characteristic that the data of the distributed database is distributed across multiple shards, when the secondary index of the data table meets the transfer conditions, the secondary index is transferred into a secondary index table for secondary index query. When using the secondary index query, it becomes a primary key query using the secondary index table, which can avoid cross-shard secondary index query and greatly improve the efficiency of secondary index query. Attached Figure Description

[0045] To more clearly illustrate the technical solutions of the present invention, the accompanying drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without any creative effort.

[0046] Figure 1 This is a flowchart of a secondary index transfer method provided in one embodiment of the present invention;

[0047] Figure 2 This is a flowchart of a secondary index transfer method provided in another embodiment of the present invention;

[0048] Figure 3 This is a flowchart of a secondary index transfer method provided in another embodiment of the present invention;

[0049] Figure 4 This is a schematic diagram of a secondary index transfer example provided in one embodiment of the present invention;

[0050] Figure 5 This is a schematic diagram of the structure of a secondary index transfer device provided in one embodiment of the present invention;

[0051] Figure 6 This is a schematic diagram of the structure of an electronic device provided in one embodiment of the present invention. Detailed Implementation

[0052] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0053] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0054] To make the objectives, technical solutions, and advantages disclosed in the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the embodiments of the present invention and are not intended to limit the embodiments of the present invention. The acquisition, storage, use, and processing of data in the technical solutions of the embodiments of the present invention all comply with the relevant provisions of national laws and regulations. First, the following concepts are explained in the embodiments of the present invention:

[0055] Secondary indexes refer to indexes other than primary key indexes, also known as auxiliary indexes.

[0056] Secondary index table: A table where the secondary index of the original table is used as the primary key after the secondary index is transferred.

[0057] Core system: refers to the core system of a bank in the financial industry. Current bank core systems are customer-centric, handling accounting, supporting integrated teller systems, and providing 24-hour service.

[0058] Sharding refers to the process of splitting data into subsets according to certain rules and deploying them to different nodes.

[0059] Sharding key: The basis for identifying data shards.

[0060] Reference manual attached Figure 1 This illustrates the flow of a secondary index transfer method provided in one embodiment of the present invention, such as... Figure 1As shown, the method may include the following steps:

[0061] S110: Obtain the secondary index of the target data table, wherein the target data table includes multiple data shards.

[0062] In this embodiment of the invention, the target data table can be a distributed multi-sharded table, and the target data table has a secondary index used as a query condition, and each data shard can be deployed on different nodes.

[0063] S120: Determine whether the sub-index meets the preset transfer conditions.

[0064] In this embodiment of the invention, if the secondary index is frequently used as a query condition and the secondary index does not contain a shard key in the primary key, then when the secondary index query scenario in the target data table is more frequent than the insertion, modification, and deletion scenarios, the secondary index can be used as the primary key to create another index table, and the secondary index query scenario can be changed to query using the primary key of the new index table.

[0065] Optionally, refer to the accompanying reference manual. Figure 2 The determination of whether the secondary index meets the preset transfer conditions may include:

[0066] S1211: Obtain the number of index queries and the number of insert, delete, and update operations corresponding to the target data table;

[0067] S1212: Determine whether the number of index queries is greater than the number of insert, delete, and update operations;

[0068] S1213: Determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0069] S1214: When the number of queries to the secondary index is greater than the number of insert, delete, and update operations and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions.

[0070] Otherwise, it is determined that the sub-index does not meet the preset transfer conditions.

[0071] Specifically, when the secondary index includes the shard key in the primary key index, when performing a secondary index query, the shard key can be used to directly determine which shard the data to be queried is located in, resulting in less time and performance consumption. In this case, there is no need to perform secondary index transfer.

[0072] Specifically, when the secondary index does not include the shard key in the primary key index, since there is no global index, the query statement will be distributed to all shards, causing a lot of unnecessary time and performance loss. In order to improve data query efficiency and reduce the cost of query access, the secondary indexes whose query count is greater than the number of insert, delete and update operations can be transferred.

[0073] The following is a quantitative analysis. First, we introduce a quantifiable metric called the "sum of database table access costs" Ω. t Let $S$ be the access cost of data table $t$.

[0074] Assume d is the number of partitions in data table t, S i Let be the total number of SQL statements for table t in the i-th partition.

[0075]

[0076] In reality, a data table's Data Manipulation Language (DML) operations only have four types: CRUD (Create, Read, Update, Delete), denoted by S... insert S delete S update S select Let n represent the number of statements in a given category, and e represent the number of shards accessed by a single SQL statement. Since INSERT, DELETE, and UPDATE statements do not cross shards in the SQL specification of the core banking system, then...

[0077]

[0078] After the secondary index is transferred, the number of INSERT, DELETE, and UPDATE statements doubles, and SELECT statements using the secondary index no longer cross shards. The "sum of database table access costs" after the secondary index transfer can be derived as follows:

[0079]

[0080] Therefore, the changes in the "sum of database table access costs" after this index transfer can be calculated as follows:

[0081] Ωt_change=Ωt new -Ωt=n insert +n delete +n update -(d-1)n 次索引select

[0082] Therefore, to ensure a reduction in the "sum of database table access costs" after the index transfer, it is necessary to ensure that Ωt_change < 0, i.e.

[0083] n insert +n delete +n update -(d-1)n 次索引select <0

[0084] n insert +ndelete +n update <(d-1)n 次索引select

[0085] In a distributed environment, where the number of shards d ≥ 2, as long as the number of secondary index query SQL queries for the data table exceeds the number of insert, update, and delete SQL queries, the secondary index transfer will ensure an overall performance improvement.

[0086] Optionally, refer to the accompanying reference manual. Figure 3 The determination of whether the secondary index meets the preset transfer conditions may include:

[0087] S1221: Obtain the data table type corresponding to the target data table;

[0088] S1222: Determine whether the data table type is a query type;

[0089] S1223: Determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0090] S1224: When the data table type is a query type and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions;

[0091] Otherwise, it is determined that the sub-index does not meet the preset transfer conditions.

[0092] Specifically, when it is impossible to accurately count the number of SQL statements in a data table, the operation weight of the data table can be calculated based on transaction statistics. That is, the proportion of operations corresponding to each data table is calculated, and the data tables are divided into the following three categories:

[0093] 1. Query-type tables: These tables have a high query weight, while other insert, delete, and update operations have a low weight; for example, parameter-type tables have virtually no insert, delete, or update operations.

[0094] 2. Insertion-type tables: The insertion weight of these tables is very high, while the weight of other query, delete, and update operations is very low; for example, transaction tables only record data and are rarely queried or modified.

[0095] 3. Update class table: The weights of all operations on the table are relatively similar.

[0096] As the analysis above shows, in a distributed environment, as long as the number of secondary index query SQL statements for the data table exceeds the number of insert, update, and delete SQL statements, the secondary index transfer will ensure an overall performance improvement. Therefore, it's easy to deduce that the data table requiring secondary index transfer is a query-type table, because query-type tables typically have more secondary index queries than insert, update, and delete operations. Thus, when the target data table is a query-type table and the secondary index does not include the shard key in the primary key index, secondary index transfer should be performed.

[0097] The embodiments of the present invention impose strict limitations on the conditions for using secondary index transfer, and scientifically demonstrate that secondary index transfer improves the overall performance of the data table, ensuring that the efficiency and performance of secondary index queries can be improved through a certain amount of storage redundancy.

[0098] S130: When the secondary index meets the preset transfer conditions, a secondary index table for performing secondary index queries is constructed based on the secondary index.

[0099] Specifically, when the secondary index meets the preset transfer conditions, constructing a secondary index table for performing secondary index queries based on the secondary index may include:

[0100] Retrieve field information from the sub-index;

[0101] The field information is used as the primary key field of the secondary index table, and the secondary index table is constructed based on the primary key field of the secondary index table.

[0102] Specifically, when the secondary index meets the preset transfer conditions, constructing a secondary index table based on the secondary index for performing secondary index queries may further include:

[0103] The fields in the primary key index of the target data table, excluding the shard key and the field information in the secondary index, are used as non-primary key fields of the secondary index table;

[0104] The non-primary key fields of the secondary index table are deleted to obtain the target secondary index table.

[0105] In this embodiment of the invention, the field information in the secondary index can be used as the primary key field of the secondary index table, and the field information in the primary key index other than the shard key and the field information in the secondary index can be used as the non-primary key field of the secondary index table. Since most queries are executed through the original table, the secondary index table is usually only accessed by a few specific SQL queries. Therefore, some fields in the secondary index table can be appropriately reduced to save storage space and improve query efficiency.

[0106] The original table's sharding key is a sharding key introduced to unify sharding strategies for various businesses and is unrelated to specific businesses. It can also be called the "application shard number." The "application shard number" meets the following conditions:

[0107] (1) is one (or more) fields of the primary key;

[0108] (2) Purely technical fields, unrelated to specific business operations;

[0109] (3) No large-scale table structure changes are required, resulting in minimal intrusion into the application;

[0110] (4) It can ensure that the data is roughly uniform among the different partitions;

[0111] (5) It has the ability to provide future business expansion.

[0112] For example, such as Figure 4 As shown, suppose a query-type data table has twelve fields: ABCDEFGHIJKL. Fields AB, CDE are the primary keys, field C is the application shard number, and fields AB, FG are secondary indexes. If the secondary indexes meet preset transfer conditions, then fields ABFG can be used as the primary key fields of the secondary index table, and the four fields DEKL, which are not needed when accessing the secondary indexes, can be discarded, resulting in the secondary index table.

[0113] Specifically, when the secondary index meets the preset transfer conditions, constructing a secondary index table based on the secondary index for performing secondary index queries may further include:

[0114] Determine whether each field in the sub-index meets the preset sharding conditions;

[0115] One or more fields are selected from the fields that meet the preset sharding conditions and used as the sharding keys of the secondary index table.

[0116] Specifically, determining whether each field in the sub-index satisfies the preset sharding conditions may include:

[0117] For each field in the sub-index, determine whether the field information can be evenly distributed to the various data shards of the target data table based on a certain preset sharding method;

[0118] If so, the field information is determined to meet the preset sharding conditions;

[0119] If not, the field information is determined not to meet the preset sharding conditions.

[0120] In this embodiment of the invention, after generating the secondary index table, one or more fields that can be sharded to all shards can be selected from the various fields in the secondary index as the sharding key of the secondary index table. Specifically, the primary key of the secondary index table is the secondary index of the original table (this secondary index does not need to be created in the original table after the transfer), and the sharding key of the secondary index table satisfies the following conditions:

[0121] (1) is one (or more) fields in this index;

[0122] (2) There is a sharding method for this field that can be evenly distributed across all shards.

[0123] As can be seen, since the sharding key of the secondary index table only applies to that table, the restrictions are not as strict as those for "applying the shard number." Basically, as long as the data can be evenly distributed, it is acceptable. The sharding methods mentioned can include hash sharding, range sharding, etc.

[0124] This invention converts the secondary index field into a primary key and separates it into a secondary index table. This allows the sharding key to be specified in the secondary index field. When querying using the secondary index table, the sharding key of the secondary index table can be used to determine which shard the data to be queried by the SQL statement is located in, thereby reducing the time required for secondary index queries and improving the efficiency of secondary index queries.

[0125] For example, such as Figure 4 As shown, assuming that the AFG fields all meet the preset sharding conditions, then the F field can be selected as the sharding key. It should be noted that the sharding method of the sharding key C field of the original table and the sharding method of the sharding key F field of the secondary index table are usually different.

[0126] In summary, the secondary index transfer method according to the embodiments of the present invention, based on the characteristic that distributed database data is distributed across multiple shards, transfers the secondary index into a secondary index table for secondary index query when the secondary index of the data table meets the transfer conditions. When using the secondary index query, it becomes a primary key query using the secondary index table. Through a certain storage redundancy, cross-shard secondary index queries can be avoided, greatly improving the efficiency and performance of secondary index queries.

[0127] Reference manual attached Figure 5 This illustrates the structure of a secondary index transfer device 500 provided in one embodiment of the present invention. For example... Figure 5 As shown, the device 500 may include:

[0128] The acquisition module 510 is used to acquire the secondary index of the target data table, wherein the target data table includes multiple data shards;

[0129] The judgment module 520 is used to determine whether the sub-index meets the preset transfer conditions;

[0130] The construction module 530 is used to construct a secondary index table for performing secondary index queries based on the secondary index when the secondary index meets the preset transfer conditions.

[0131] In one possible embodiment, the determining module 520 may include:

[0132] The first acquisition unit is used to acquire the number of index queries and the number of insert, delete, and update operations corresponding to the target data table;

[0133] The first judgment unit is used to determine whether the number of index queries is greater than the number of insert, delete, and update operations.

[0134] The second judgment unit is used to determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0135] The first determination unit is used to determine that the secondary index meets the preset transfer conditions when the number of queries of the secondary index is greater than the number of insert, delete and modify operations and the secondary index does not include the shard key in the primary key index; otherwise, it determines that the secondary index does not meet the preset transfer conditions.

[0136] In another possible embodiment, the determination module 520 may include:

[0137] The second acquisition unit is used to acquire the data table type corresponding to the target data table;

[0138] The third judgment unit is used to determine whether the data table type is a query type;

[0139] The fourth determination unit is used to determine whether the secondary index includes the shard key in the primary key index of the target data table;

[0140] The second determination unit is used to determine that the secondary index meets the preset transfer conditions when the data table type is a query type and the secondary index does not include the shard key in the primary key index; otherwise, it determines that the secondary index does not meet the preset transfer conditions.

[0141] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus provided in the above embodiments and the corresponding method embodiments belong to the same concept, and the specific implementation process can be found in the corresponding method embodiments, which will not be repeated here.

[0142] One embodiment of the present invention also provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the sub-index transfer method provided in the above method embodiments.

[0143] Memory can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, application programs required for the functions, etc.; the data storage area can store data created based on the use of the device, etc. Furthermore, memory can include high-speed random access memory, and can also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, memory can also include a memory controller to provide the processor with access to the memory.

[0144] In one specific embodiment Figure 6 A schematic diagram of the hardware structure of an electronic device for implementing the secondary index transfer method provided in the embodiments of the present invention is shown. The electronic device can be a computer terminal, a mobile terminal, or other devices. The electronic device can also participate in or include the secondary index transfer device provided in the embodiments of the present invention. Figure 6 As shown, the electronic device 600 may include a memory 610 with one or more computer-readable storage media, a processor 620 with one or more processing cores, an input unit 630, a display unit 640, a radio frequency (RF) circuit 650, a wireless fidelity (WiFi) module 660, and a power supply 670, among other components. Those skilled in the art will understand that... Figure 6 The electronic device structure shown does not constitute a limitation on electronic device 600, and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0145] The memory 610 can be used to store software programs and modules. The processor 620 performs various functional applications and data processing by running or executing the software programs and modules stored in the memory 610 and by calling data stored in the memory 610. The memory 610 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function, etc.; the data storage area may store data created based on the use of the electronic device, etc. In addition, the memory 610 may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 610 may also include a memory controller to provide the processor 620 with access to the memory 610.

[0146] The processor 620 is the control center of the electronic device 600. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 610, and by calling data stored in the memory 610, it performs various functions and processes data of the electronic device 600, thereby providing overall monitoring of the electronic device 600. The processor 620 can be a central processing unit, or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0147] The input unit 630 can be used to receive input numerical or character information, and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control. Specifically, the input unit 630 may include a touch-sensitive surface 631 and other input devices 632. Specifically, the touch-sensitive surface 631 may include, but is not limited to, a touchpad or a touch screen, and other input devices 632 may include, but are not limited to, one or more of the following: a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick.

[0148] The display unit 640 can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of electronic devices. These graphical user interfaces can be composed of graphics, text, icons, videos, and any combination thereof. The display unit 640 may include a display panel 641, which may optionally be configured as a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.

[0149] The RF circuit 650 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and hands it over to one or more processors 620 for processing; additionally, it transmits uplink data to the base station. Typically, the RF circuit 650 includes, but is not limited to, an antenna, at least one amplifier, a tuner, one or more oscillators, a Subscriber Identity Module (SIM) card, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the RF circuit 650 can also communicate wirelessly with networks and other devices. The wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0150] WiFi is a short-range wireless transmission technology. Electronic device 600, through WiFi module 660, can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 6 WiFi module 660 is shown, but it is understood that it is not a necessary component of electronic device 600 and can be omitted as needed without changing the nature of the invention.

[0151] The electronic device 600 also includes a power supply 670 (such as a battery) to power various components. Preferably, the power supply can be logically connected to the processor 620 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 670 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0152] It should be noted that, although not shown, the electronic device 600 may also include a Bluetooth module, etc., which will not be described in detail here.

[0153] One embodiment of the present invention also provides a computer-readable storage medium, which can be disposed in an electronic device to store at least one instruction or at least one program related to implementing a sub-index transfer method, wherein the at least one instruction or the at least one program is loaded and executed by the processor to implement the sub-index transfer method provided in the above method embodiment.

[0154] Optionally, in embodiments of the present invention, the storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

[0155] One embodiment of the present invention also provides a computer program product comprising a computer program / instructions that, when the computer program product is run on an electronic device, are loaded and executed by a processor to implement the steps of the sub-index transfer method provided in the various alternative embodiments described above.

[0156] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, specific embodiments have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in a different order than that shown in the embodiments and still achieve the desired result. Additionally, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0157] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0158] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0159] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A secondary index transfer method, characterized in that, include: Obtain the secondary index of the target data table, wherein the secondary index is an auxiliary index other than the primary key index of the target data table, and the target data table includes multiple data shards; Determine whether the sub-index meets the preset transfer conditions; When the secondary index meets the preset transfer conditions, a secondary index table for performing secondary index queries is constructed based on the secondary index. The step of determining whether the secondary index meets the preset transfer conditions includes: Obtain the number of index queries and the number of insert, delete, and update operations corresponding to the target data table; Determine whether the number of index queries is greater than the number of insert, delete, and update operations; Determine whether the secondary index includes the shard key in the primary key index of the target data table; When the number of queries to the secondary index is greater than the number of insert, delete, and update operations, and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions. Otherwise, it is determined that the sub-index does not meet the preset transfer conditions. Alternatively, determining whether the secondary index meets the preset transfer conditions includes: Obtain the data table type corresponding to the target data table; Determine whether the data table type is a query type; Determine whether the secondary index includes the shard key in the primary key index of the target data table; When the data table type is query type and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions; Otherwise, it is determined that the sub-index does not meet the preset transfer conditions. The sharding key of the secondary index table satisfies the following condition: (1) is one or more fields in the sub-index; (2) The sharding method for the one or more fields can be evenly distributed among all shards.

2. The method according to claim 1, characterized in that, When the secondary index meets the preset transfer conditions, constructing a secondary index table based on the secondary index for secondary index queries includes: Retrieve field information from the sub-index; The field information is used as the primary key field of the secondary index table, and the secondary index table is constructed based on the primary key field of the secondary index table.

3. The method according to claim 2, characterized in that, When the secondary index meets the preset transfer conditions, constructing a secondary index table for secondary index queries based on the secondary index further includes: The fields in the primary key index of the target data table, excluding the shard key and the field information in the secondary index, are used as non-primary key fields of the secondary index table; The non-primary key fields of the secondary index table are deleted to obtain the target secondary index table.

4. The method according to claim 2 or 3, characterized in that, When the secondary index meets the preset transfer conditions, constructing a secondary index table for secondary index queries based on the secondary index further includes: Determine whether each field in the sub-index meets the preset sharding conditions; One or more fields are selected from the fields that meet the preset sharding conditions and used as the sharding keys of the secondary index table.

5. The method according to claim 4, characterized in that, The step of determining whether each field information in the sub-index meets the preset sharding conditions includes: For each field in the sub-index, determine whether the field information can be evenly distributed to the various data shards of the target data table based on a certain preset sharding method; If so, the field information is determined to meet the preset sharding conditions; If not, the field information is determined not to meet the preset sharding conditions.

6. A secondary index transfer device, characterized in that, include: The acquisition module is used to acquire the secondary index of the target data table, wherein the secondary index is an auxiliary index other than the primary key index, and the target data table includes multiple data shards; The judgment module is used to determine whether the sub-index meets the preset transfer conditions; The construction module is used to construct a secondary index table for performing secondary index queries based on the secondary index when the secondary index meets the preset transfer conditions. The step of determining whether the secondary index meets the preset transfer conditions includes: Obtain the number of index queries and the number of insert, delete, and update operations corresponding to the target data table; Determine whether the number of index queries is greater than the number of insert, delete, and update operations; Determine whether the secondary index includes the shard key in the primary key index of the target data table; When the number of queries to the secondary index is greater than the number of insert, delete, and update operations, and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions. Otherwise, it is determined that the sub-index does not meet the preset transfer conditions. Alternatively, determining whether the secondary index meets the preset transfer conditions includes: Obtain the data table type corresponding to the target data table; Determine whether the data table type is a query type; Determine whether the secondary index includes the shard key in the primary key index of the target data table; When the data table type is query type and the secondary index does not include the shard key in the primary key index, it is determined that the secondary index meets the preset transfer conditions; Otherwise, it is determined that the sub-index does not meet the preset transfer conditions. The sharding key of the secondary index table satisfies the following condition: (1) is one or more fields in the sub-index; (2) The sharding method for the one or more fields can be evenly distributed among all shards.

7. An electronic device, characterized in that, The electronic device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, the at least one instruction or the at least one program being loaded and executed by the processor to implement the sub-index transfer method as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction or at least one program, which is loaded and executed by a processor to implement the sub-index transfer method as described in any one of claims 1-5.

9. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the steps of the sub-index transfer method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Data management method and device

    CN113312355A