WO2015054998A1 - 一种在线重建索引的方法和装置 - Google Patents

一种在线重建索引的方法和装置 Download PDF

Info

Publication number
WO2015054998A1
WO2015054998A1 PCT/CN2014/076185 CN2014076185W WO2015054998A1 WO 2015054998 A1 WO2015054998 A1 WO 2015054998A1 CN 2014076185 W CN2014076185 W CN 2014076185W WO 2015054998 A1 WO2015054998 A1 WO 2015054998A1
Authority
WO
WIPO (PCT)
Prior art keywords
index
target
data
source
new
Prior art date
Application number
PCT/CN2014/076185
Other languages
English (en)
French (fr)
Inventor
李海丰
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP14854786.2A priority Critical patent/EP3002687A4/en
Publication of WO2015054998A1 publication Critical patent/WO2015054998A1/zh
Priority to US14/981,111 priority patent/US20160132542A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2272Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching

Definitions

  • an index is a structure that sorts the values of one or more columns in a database base table, so an index can be used to quickly retrieve data from a database base table.
  • the index uses a B-Tree structure.
  • the index data located in the index page is organized in the form of a tree, and the index data of each level is stored in order. That is, when the index data is inserted into the index page for storage, it must be inserted into the index page that meets the order requirements, and cannot be inserted into other index pages (even if other index pages have enough storage space). If the index page that meets the order requirements has insufficient free space, a new page is also requested for storing the index data.
  • the index has the above characteristics, when the operation of deleting and inserting index data frequently occurs, the index tree is likely to be unbalanced. For example, all index data is discretely distributed across multiple index pages, and there is only a very small amount of index data in each index page. Obviously, the index of this structure not only causes waste of storage space, but also reduces the scanning efficiency of the index, which further affects the retrieval speed of the database base table.
  • the method for rebuilding the index online is as follows: firstly, the target index of the source index (the target index has the same structure as the source index) and the index snapshot, wherein, during the creation process, the base table is blocked. Write transaction, release blocking after creation. Then, the source index data in the index snapshot is migrated to the target index, and if new index data is generated during the source index data migration, the new index data is simultaneously inserted into the source index and the target index. Finally, when all the source index data in the source index is migrated to the target index, the online rebuild process is completed, and the target index can be used later.
  • an embodiment of the present invention provides a method and apparatus for rebuilding an index online to reduce the operation of the system random 10 and system overhead.
  • a method for rebuilding an index online includes: creating an index snapshot, an index cache, and a target index for a source index, and blocking a write transaction to a database base table during the creation process, where The target index has the same structure as the source index; in the target index, the invalid source index data in the source index is filtered by the index snapshot during the migration process;
  • the new index data is migrated to the target index together with the source index data in the current index page; or After the source index data is completely migrated, the new index data in the index cache is migrated to the target index.
  • the present invention also has a first possibility, further comprising: when migrating new index data together with source index data in a current index page to the target index during migration, After the migration is completed, check whether there is still new index data in the index cache that is not stored in the target index; If so, the new index data not stored in the target index is continually migrated into the target index.
  • the invention also has a second possibility, further comprising:
  • the index cache is deleted.
  • the invention also has a third possibility, further comprising:
  • the source index is set to an unavailable state.
  • the present invention also has a fourth possibility that in the index reconstruction process, the index data is queried by:
  • the index data that meets the requirements is queried in the target index or in the target index and the index cache.
  • the present invention also has a fifth possibility that after the source index data migration is completed, the new index data is added as follows:
  • an apparatus for online index reconstruction including: a creating unit, configured to create an index snapshot, an index cache, and a target index for a source index, and block a database base table during the creation process.
  • Write transaction wherein the target index is used for the source index to have the same structure; the source index data in the migration is migrated to the target index, and the invalid source index in the source index is indexed by the index snapshot during the migration process Data is filtered;
  • a new index data cache unit for storing new index data generated during the migration process into the cable In the cache
  • a new index data reconstruction unit configured to migrate the new index data together with the source index data in the current index page if there is new index data required for the current index page being processed in the index cache during the migration process Or to the target index, or to migrate new index data in the index cache to the target index after the source index data is completely migrated.
  • the present invention also has a first possibility that the apparatus further includes: a checking unit, configured to: when the source index data migration process, the new index data and the source index data in the current index page When migrating to the target index together, after the migration is completed, it is checked whether there is still new index data not stored in the target index in the index cache;
  • a checking unit configured to: when the source index data migration process, the new index data and the source index data in the current index page When migrating to the target index together, after the migration is completed, it is checked whether there is still new index data not stored in the target index in the index cache;
  • a new index data repairing unit configured to check, by the checking unit, that new index data not stored in the target index exists in the index cache, and continue to migrate the new index data that is not stored in the target index to the target In the index.
  • the invention also has a second possibility that the apparatus further comprises:
  • a deleting unit configured to delete the index cache after all the new index data in the index cache is stored in the target index.
  • the invention also has a third possibility that the apparatus further comprises:
  • a setting unit configured to set the source index to an unavailable state after all the source index data in the source index is migrated into the target index.
  • the new index data generated during the source index data migration process between the index snapshot and the target index is saved to the index cache (instead of The new index and the target index) reduce the overhead caused by storing new index data in the source index.
  • the new index data in the index cache one way is: When the source index data of an index page in the index snapshot is migrated to the target index, if there is new index data related to the index page in the index cache at this time, The new index data is also migrated to the target index along with the source index data in the index page. Another way is to migrate the new index data in the index cache to the target index after all the source index data in the source index has been migrated. Thereby ensuring that new index data is inserted into the target index. The operation interrupts the migration of the source index data and reduces the random operation of the system.
  • FIG. 1 is a flowchart of an embodiment of a method for online index reconstruction according to the present invention
  • FIG. 2 is a schematic diagram of saving new index data in an index cache to a target index according to the present invention
  • FIG. 3 is another schematic diagram of saving new index data in an index cache to a target index in the present invention
  • FIG. 4 is a flowchart of another embodiment of a method for online index reconstruction according to the present invention.
  • FIG. 5 is a structural diagram of an embodiment of an apparatus for online index reconstruction according to the present invention.
  • Embodiments of the present invention provide a method and apparatus for rebuilding an index online.
  • the key point of the technical solution of the present invention is that if new index data is generated in the process of migrating the source index data in the index snapshot to the target index, the new index data is first stored in the index cache (instead of being stored in the source index). And the target index).
  • the new index data in the index cache one way is: When the source index data of an index page in the index snapshot is migrated to the target index, if there is new index data related to the index page in the index cache at this time, The new index data is also migrated to the target index along with the source index data in the index page. Another way is to migrate the new index data in the index cache to the target index after all the source index data in the source index has been migrated.
  • FIG. 1 is a flowchart of an embodiment of a method for online rebuilding an index according to the present invention.
  • the method includes the following steps:
  • Step 101 Create an index snapshot, an index cache, and a target index for the source index, and block a write transaction to the database base table during the creation process, where the target index has the same structure as the source index;
  • the online rebuild index request can be triggered by the command. After receiving the request, the database rebuilds the specified index online.
  • the read transaction of the database base table creates an index snapshot, an index cache, and a target index with the same structure as the source index for the source index, and releases the blocking of the write transaction after the creation.
  • the created target index is unavailable, that is, the target index cannot be queried, inserted, and deleted.
  • Step 102 The source index data in the index snapshot is migrated to the target index page by page according to the order of the index pages, and the invalid source index data in the source index is filtered by the index snapshot during the migration process;
  • the index page which is the basic unit of index data storage, can be logically divided into pages (numbered consecutively from 0 to n) in the unallocated file in the database, and the size of each page is fixed.
  • the source index data in the index snapshot is migrated to the target index one by one.
  • Step 103 The new index data generated in the migration process is stored in the index cache; while the source index data in the source index is migrated to the target index, a DML transaction to the database base table may also occur, such as writing Transactions, and these write transactions will cause operations on the index, such as insert or delete operations, and then generate new index data, once the new index data is generated, the new index data will be The sections are all stored in the index cache.
  • the index cache consists of two queues, namely the new tuple queue and the original tuple delete queue.
  • the new tuple queue is sorted and stored according to the key value
  • the original tuple delete queue is sorted according to the unique identifier of the deleted original tuple.
  • the unique identifier may be used to locate the database base. The ID of the tuple in the table.
  • the index cache when the index cache is running, you need to deal with the following situation.
  • the index cache space is insufficient, in order to provide storage space for the new tuple, you need to free some tuple space.
  • the new tuple (and/or the deletion ID of the original tuple) that has been migrated to the target index is manually inserted into the original tuple of the source index, and the new tuple is released.
  • the space occupied since the source index also needs to provide query operations, so you need to store this part of the tuple).
  • Step 104 During the migration process, if there is new index data required for the current index page being processed in the index cache, the new index data is migrated to the target index together with the source index data in the current index page. Or; after the source index data migration is completed, the new index data in the index cache is migrated to the target index.
  • the source index data in the first index page of the source index (the first index page is the current index page being processed) is currently being migrated to the first index page of the target index.
  • the implementation process is shown in Figure 2.
  • the new index data required for the first index page of the source index existing in the index cache is migrated to the first index of the target index.
  • the new index data required for the second index page of the source index existing in the index cache is migrated to the first index page of the target index, and so on.
  • the implementation process is shown in Figure 3.
  • the index cache is also checked for a tuple having a smaller key value than the tuple to be migrated. If not, the tuple to be migrated is directly Insert into the target index, if there is, first insert the tuple in the index cache into the target index until the key value of the tuple in the index cache is greater than the key value of the tuple to be migrated, and then take the index snapshot The to-be-migrated tuple is inserted into the target index Medium.
  • the tuple to be migrated in the index snapshot When the tuple to be migrated in the index snapshot is inserted into the target index, first check whether the tuple to be migrated is in the original tuple deletion queue of the index cache. If it exists, the tuple to be migrated is inserted at the same time as the insertion. A delete identifier. After all the new index data in the index cache is stored in the target index, the index cache can be deleted to free up the system's storage space. Moreover, at this time, the target index is changed from the unavailable state to the available state by setting, and in the process of setting the available state of the target index, the DML transaction needs to be blocked for a short time, and the blocking can be released after the setting is completed.
  • various index operations can only be on the source index, not on the new index. After all the source index data in the source index is migrated to the target index, the source index is unavailable, the source index can be deleted, and various index operations are only performed on the new index.
  • the new index data generated during the source index data migration process between the index snapshot and the target index is saved to the index cache (instead of The new index and the target index) reduce the overhead caused by storing new index data in the source index.
  • the new index data in the index cache one way is: When the source index data of an index page in the index snapshot is migrated to the target index, if there is new index data related to the index page in the index cache at this time, The new index data is also migrated to the target index along with the source index data in the index page. Another way is to migrate the new index data in the index cache to the target index after all the source index data in the source index has been migrated. Therefore, the operation of inserting new index data into the target index interrupts the migration operation of the source index data, thereby reducing the operation of the system random 10 .
  • Embodiment 2 In addition, during the entire rebuild process, only one DML transaction is blocked, and the blocking time is short. Embodiment 2
  • step 104 for the first mode, it is assumed that after the new index data required for the first index page of the source index existing in the index cache is migrated to the first index page of the target index, the active index is further The new index data required for the first index page is stored in the index cache, if these new indexes are not The data is then migrated to the target index, which will inevitably miss the index data during the online reconstruction process.
  • the present embodiment differs from the first embodiment in that it further checks whether there is missing new index data in the index cache (ie, new index data that is not stored in the target index), and determines the omission. Next, the missing new index data is added to the target index.
  • FIG. 4 is a flowchart of another embodiment of a method for online index reconstruction according to the present invention. The method includes the following steps:
  • Step 401 Create an index snapshot, an index cache, and a target index for the source index, and block a write transaction to the database base table during the creation process, where the target index has the same structure as the source index;
  • Step 402 The source index data in the index snapshot is migrated to the target index page by page according to the sequence of the index page, and the invalid source index data in the source index is filtered by the index snapshot during the migration process;
  • Step 403 The new index data generated in the migration process is stored in the cache;
  • Step 404 During the migration process, if there is new index data required for the current index page being processed in the index cache And migrating the new index data to the target index together with the source index data in the current index page;
  • steps 101-104 in the first embodiment For detailed execution of the above steps, refer to steps 101-104 in the first embodiment.
  • Step 405 Check whether there is still new index data not stored in the target index in the index cache, and if yes, proceed to step 406, otherwise, end the process;
  • Step 406 Continue to migrate the new index data not stored in the target index to the target index, and end the process.
  • the advantages of the present invention are compared with the prior art: the new index data generated during the source index data migration process between the index snapshot and the target index is saved to the index cache (instead of New index and target index), reduced due to new index data The overhead of storing the source index.
  • the new index data in the index cache one way is: When the source index data of an index page in the index snapshot is migrated to the target index, if there is new index data related to the index page in the index cache at this time, The new index data is also migrated to the target index along with the source index data in the index page. Another way is to migrate the new index data in the index cache to the target index after all the source index data in the source index has been migrated. Therefore, the operation of inserting new index data into the target index interrupts the migration operation of the source index data, thereby reducing the operation of the system random 10 .
  • the entire index rebuild process is done online, that is, while the index is being rebuilt, the service is not interrupted, so that the system can still query, insert, and delete the index.
  • the query, insert, and delete processes are as follows:
  • Insert processing If the index is a unique index, it will be uniquely verified based on the source index and the index cache. If the verification passes, the new index data to be inserted is stored in the index cache.
  • Delete processing There are two cases of deletion. In the first case, the index to be deleted is in the source index, then only the deletion flag of the index is recorded on the index cache; the second case is that the index to be deleted is reconstructed. The newly inserted index in the process, and the index is in the index cache, then just delete the delete identifier directly in the index cache.
  • Query processing The index data needs to be obtained from the source index and the index cache. If the index data is obtained from the source index, it is also necessary to check whether the index data is deleted from the index cache.
  • the query, insert, and delete processes are as follows:
  • Insert processing If the index is a unique index, it will be uniquely verified based on the target index, or the target index and the index cache. If the verification passes, the new index data to be inserted is stored in the target index.
  • Delete processing There are two cases in the deletion. In the first case, the index to be deleted is in the target index, then only the deletion flag of the index is recorded on the target index; the second case is that the index to be deleted is in the index. In the cache, you only need to directly delete the ID in the index cache.
  • Query processing The index data needs to be obtained from the source index and the index cache. If the index data is obtained from the source index, it is also necessary to check whether the index data is deleted from the index cache.
  • the embodiment of the present invention further provides an apparatus for rebuilding an index online.
  • FIG. 5 it is a structural diagram of an embodiment of an apparatus for online index rebuilding according to the present invention.
  • the apparatus includes: a creating unit 501, a source index data reconstruction unit 502, a new index data buffer unit 503, and a new index data reconstruction unit. 504.
  • the internal structure and connection relationship will be further described below in conjunction with the working principle of the device.
  • the creating unit 501 is configured to create an index snapshot, an index cache, and a target index for the source index, and block a write transaction to the database base table during the creation process, where the target index is used for the source index to have the same structure;
  • the source index data reconstruction unit 502 is configured to migrate the source index data in the index snapshot to the target index page by page according to the order of the index pages, and invalidate the source index by using the index snapshot during the migration process.
  • Source index data is filtered;
  • a new index data cache unit 503, configured to store new index data generated during the migration process into the index cache;
  • a new index data reconstruction unit 504 configured to: in the migration process, if there is new index data required for the current index page being processed in the index cache, the new index data is the same as the source index data in the current index page. Migrating to the target index, or for migrating new index data in the index cache to the target index after all the source index data has been migrated.
  • the apparatus further includes: an inspecting unit 505 and a new index data replenishing unit 506, wherein
  • the checking unit 505 is configured to: when the new index data is migrated to the target index together with the source index data in the current index page during the source index data migration process, when the new index data is migrated to the target index, the checkpoint Whether there is still new index data not stored in the target index in the index cache;
  • the device further includes: a deleting unit, configured to delete the index cache after all the new index data in the index cache is stored in the target index.
  • the apparatus further includes: a setting unit, configured to set the source index to an unavailable state after all the source index data in the source index is migrated into the target index.
  • the new index data generated during the source index data migration process between the index snapshot and the target index is saved to the index cache (instead of The new index and the target index) reduce the overhead caused by storing new index data in the source index.
  • the new index data in the index cache one way is: When the source index data of an index page in the index snapshot is migrated to the target index, if there is new index data related to the index page in the index cache at this time, The new index data is also migrated to the target index along with the source index data in the index page. Another way is to migrate the new index data in the index cache to the target index after all the source index data in the source index has been migrated. Therefore, the operation of inserting new index data into the target index interrupts the migration operation of the source index data, thereby reducing the operation of the system random 10 .
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are only schematic.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined. Or can be integrated into another system, or some features can be ignored, or not executed.
  • the mutual coupling or direct connection or communication connection shown or discussed may be an indirect connection or communication connection through some interface, device or unit, and may be in electrical, mechanical or other form.
  • the component displayed by the meta may or may not be a physical unit, that is, it may be located in one place, or Can be distributed to multiple network elements. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware, and can be implemented in the form of a software functional unit.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

一种在线重建索引的方法和装置。其中,该方法包括:为源索引创建索引快照、索引缓存和目标索引,并在创建过程中阻塞对数据库基表的写事务;按照索引页的先后顺序逐页地将源索引中的源索引数据迁移到目标索引中,并在迁移过程中通过索引快照对源索引中的无效源索引数据进行过滤;将迁移过程中所产生的新索引数据存入索引缓存中;在迁移过程中,如果索引缓存中存在正在处理的当前索引页所需的新索引数据,将所述新索引数据与当前索引页中的源索引数据一同迁移到目标索引中;或者,在源索引数据全部迁移完毕后,将索引缓存中的新索引数据迁移到目标索引中。根据本发明实施例,可以减少系统随机IO的操作以及系统开销。

Description

一种在线重建索引的方法和装置 本申请要求于 2013 年 10 月 14 日提交中国专利局、 申请号为 201310478786.3 , 发明名称为"一种在线重建索引的方法和装置"的中国专利申 请的优先权, 其全部内容通过引用结合在本申请中。 技术领域 本发明涉及数据库技术领域, 特别是涉及一种在先重建索引的方法和装 置。
背景技术
在数据库中,索引是对数据库基表中的一列或多列的值进行排序的一种结 构, 因此, 使用索引可以快速检索数据库基表中的数据。 通常, 索引多釆用 B-Tree结构, 在 B-Tree结构中, 位于索引页中的索引数据是按照树的形式来 组织的, 同时, 每个层次的索引数据是按照顺序进行存储的。 也就是说, 当将 索引数据插入到索引页中存储时, 其必须插入到符合顺序要求的索引页中, 而 不能插入到其它的索引页中 (即使其它索引页有足够的存储空间)。 如果符合 顺序要求的索引页的空闲空间不足, 还会申请新的页面用于存储索引数据。
由于索引具有上述特性,因此,当频繁发生删除和插入索引数据的操作时, 就很有可能造成索引树不平衡。例如, 所有的索引数据离散地分布在多个索引 页, 并且, 每个索引页中只存在极少量的索引数据。 显然, 这种结构的索引不 仅会造成存储空间的浪费,还会降低对索引的扫描效率, 进而进一步影响对数 据库基表的检索速度。
为了解决这个问题, 大多数数据库厂商都提供了重建索引的功能, 而一般 的重建索引是线下执行的, 由于线下重建索引的方式需要在重建过程中断业 务, 因此, 这种索引重建方式并不实用, 特别是对于一些全天都要进行业务处 理的应用来说, 这种重建方式是不可接受的。 为此, 当前主流的数据库厂商还 提供了在线重建索引的功能, 即, 在重建过程中不中断业务。
其中, 一种在线重建索引的方法为: 先创建源索引的目标索引 (该目标索 引与源索引具有相同的结构)和索引快照, 其中, 在创建过程中, 阻塞对基表 的写事务, 创建完毕后释放阻塞。 然后, 将索引快照中的源索引数据迁移到目 标索引中, 而如果在源索引数据迁移过程中产生了新索引数据, 则将新索引数 据同时插入到源索引和目标索引中。 最后, 当将源索引中的所有源索引数据全 部都迁移到目标索引上时, 在线重建过程完毕, 后续就可以使用目标索引。
但是,在实现本发明的过程中, 本发明的发明人发现现有技术中至少存在 如下问题: 在将源索引数据迁移过程中产生的新索引数据插入目标索引中时, 插入新索引数据的这个操作会打断源索引数据的迁移操作, 而插入操作越多, 被打断的次数也就越多。 对于重建系统而言, 就会增加系统随机 10的操作。 另外, 将新索引数据插入到源索引上, 插入操作也会相应地增加系统开销。
发明内容
为了解决上述技术问题,本发明实施例提供了一种在线重建索引的方法和 装置, 以减少系统随机 10的操作以及系统开销。
本发明实施例公开了如下技术方案:
根据本发明实施例的第一方面, 公开了一种在线重建索引的方法, 包括: 为源索引创建索引快照、 索引緩存和目标索引, 并在创建过程中阻塞对数 据库基表的写事务, 其中, 所述目标索引与所述源索引具有相同的结构; 目标索引中,并在迁移过程中通过索引快照对源索引中的无效源索引数据进行 过滤;
将迁移过程中所产生的新索引数据存入所述索引緩存中;
在迁移过程中,如果所述索引緩存中存在正在处理的当前索引页所需的新 索引数据,将所述新索引数据与当前索引页中的源索引数据一同迁移到所述目 标索引中; 或者, 在源索引数据全部迁移完毕后, 将所述索引緩存中的新索引 数据迁移到所述目标索引中。
结合本发明的第一方面, 本发明还具有第一种可能, 即还包括: 当在迁移 过程中将新索引数据与当前索引页中的源索引数据一同迁移到所述目标索引 中时,在迁移完毕后,检查所述索引緩存中是否还存在未存储在目标索引的新 索引数据; 如果是,继续将所述未存储在目标索引的新索引数据迁移到所述目标索引 中。
结合本发明的第一方面, 以及本发明第一方面的第一种可能, 本发明还具 有第二种可能, 即还包括:
在将所述索引緩存中的新索引数据全部存入到所述目标索引中之后,删除 所述索引緩存。
结合本发明的第一方面, 以及本发明第一方面的第一种可能, 本发明还具 有第三种可能, 即还包括:
在将所述源索引中的源索引数据全部迁移到所述目标索引中之后,将所述 源索引设置为不可用状态。
结合本发明的第一方面,本发明还具有第四种可能,即在索引重建过程中, 通过如下方式查询索引数据:
在迁移过程中, 在所述源索引和所述索引緩存中查询符合要求的索引数 据;
在迁移完毕后,在目标索引中或者在所述目标索引和所述索引緩存中查询 符合要求的索引数据。
结合本发明的第一方面, 本发明还具有第五种可能, 即在源索引数据迁移 完毕后, 通过如下方式添加新索引数据:
判断在所述索引緩存和所述目标索引中是否存在要添加的新索引数据;如 果在所述索引緩存和所述目标索引中都不存在要添加的新索引数据,将所述要 添加的新索引数据存入目标索引中。
根据本发明实施例的第二方面, 公开了一种在线重建索引的装置, 包括: 创建单元, 用于为源索引创建索引快照、 索引緩存和目标索引, 并在创建 过程中阻塞对数据库基表的写事务, 其中, 所述目标索引用于所述源索引具有 相同的结构; 中的源索引数据迁移到所述目标索引中,并在迁移过程中通过索引快照对源索 引中的无效源索引数据进行过滤;
新索引数据緩存单元,用于将在迁移过程中产生的新索引数据存入所述索 引緩存中;
新索引数据重建单元, 用于在迁移过程中,如果所述索引緩存中存在正在 处理的当前索引页所需的新索引数据,将所述新索引数据与当前索引页中的源 索引数据一同迁移到所述目标索引中, 或者, 用于在源索引数据全部迁移完毕 后, 将所述索引緩存中的新索引数据迁移到所述目标索引中。
结合本发明的第二方面, 本发明还具有第一种可能, 即所述装置还包括: 检查单元,用于当在源索引数据迁移过程中将新索引数据与当前索引页中 的源索引数据一同迁移到所述目标索引中时,在迁移到完毕后,检查所述索引 緩存中是否还存在未存储在目标索引的新索引数据;
新索引数据补建单元,用于所述检查单元检查出所述索引緩存中还存在未 存储在目标索引的新索引数据,继续将所述未存储在目标索引的新索引数据迁 移到所述目标索引中。
结合本发明的第二方面, 以及本发明第二方面的第一种可能, 本发明还具 有第二种可能, 即所述装置还包括:
删除单元,用于在将所述索引緩存中的新索引数据全部存入到所述目标索 引中之后, 删除所述索引緩存。
结合本发明的第二方面, 以及本发明第二方面的第一种可能, 本发明还具 有第三种可能, 即所述装置还包括:
设置单元,用于在将所述源索引中的源索引数据全部迁移到所述目标索引 中之后, 将所述源索引设置为不可用状态。
由上述实施例可以看出, 与现有技术相比, 本发明的优点在于: 将在索引快照与目标索引之间的源索引数据迁移过程中产生的新索引数 据保存到索引緩存中 (而不是新索引和目标索引中), 减少了因将新索引数据 存入源索引而带来的系统开销。
而对于索引緩存中的新索引数据, 一种方式是: 在将索引快照中某一索引 页的源索引数据迁移到目标索引时,如果此时索引緩存中存在该索引页有关的 新索引数据,也该新索引数据与该索引页中的源索引数据一同迁移到目标索引 中。 另一种方式是, 在将源索引中的源索引数据全部迁移完毕后, 再将索引緩 存中的新索引数据迁移到目标索引中。从而保证向目标索引插入新索引数据的 操作会打断源索引数据的迁移操作, 减少了系统随机 10的操作。
另外, 在整个重建过程中, 只需阻塞一次 DML事务, 阻塞时间短。 附图说明 为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施 例中所需要使用的附图作简单地介绍, 显而易见地, 下面描述中的附图仅仅是 本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的 前提下, 还可以根据这些附图获得其他的附图。
图 1为本发明一种在线重建索引的方法的一个实施例的流程图; 图 2 为本发明中一种将索引緩存中的新索引数据保存到目标索引的示意 图;
图 3 为本发明中另一种将索引緩存中的新索引数据保存到目标索引的示 意图;
图 4为本发明一种在线重建索引的方法的另一个实施例的流程图; 图 5为本发明一种在线重建索引的装置的一个实施例结构图;
图 6为本发明一种在线重建索引的装置的另一个实施例结构图。 具体实施方式 本发明实施例提供了一种在线重建索引的方法和装置。本发明技术方案的 关键在于,如果在将索引快照中的源索引数据迁移到目标索引的过程中产生了 新索引数据, 先将该新索引数据存入到索引緩存中(而不是存入源索引和目标 索引中)。 而对于索引緩存中的新索引数据, 一种方式是: 在将索引快照中某 一索引页的源索引数据迁移到目标索引时,如果此时索引緩存中存在该索引页 有关的新索引数据,也该新索引数据与该索引页中的源索引数据一同迁移到目 标索引中。 另一种方式是, 在将源索引中的源索引数据全部迁移完毕后, 再将 索引緩存中的新索引数据迁移到目标索引中。
为使本发明的上述目的、特征和优点能够更加明显易懂, 下面结合附图对 本发明实施例进行详细描述。 实施例一
请参阅图 1, 其为本发明一种在线重建索引的方法的一个实施例的流程 图, 该方法包括以下步骤:
步骤 101 : 为源索引创建索引快照、 索引緩存和目标索引, 并在创建过程 中阻塞对数据库基表的写事务, 其中, 所述目标索引与所述源索引具有相同的 结构;
一旦数据库管理员发现索引树出现了不平衡,就可以通过命令触发在线重 建索引请求, 数据库在接收到该请求后对指定的索引进行在线重建。
在进行重建之前,可以先检查一下当前是否存在基于索引对应的基表的写 事务, 如果存在, 可等待该写事务结束后, 然后再阻塞对数据库基表的任何写 事务(而不会阻塞对数据库基表的读事务), 为源索引创建索引快照、 索引緩 存和与源索引具有相同的结构的目标索引, 创建完毕后释放对写事务的阻塞。
显然, 通过上述阻塞操作, 可以保证: 当在迁移过程中出现写事务时, 由 该写事务产生的新索引数据全部都存入到索引緩存中,而不是源索引和目标索 引中。 另外, 还可以保证: 当由索引快照对源索引中的无效源索引数据进行过 滤时,过滤后并迁移到目标索引中的源索引数据与重建索引前源索引中的源索 引数据之间的一致性, 即源索引数据是完全相同的。
另外, 通过设置, 使创建的目标索引处于不可用状态, 即, 不能对目标索 引进行查询、 插入和删除操作。
步骤 102: 按照索引页的先后顺序逐页将所述索引快照中的源索引数据迁 移到所述目标索引中,并在迁移过程中通过索引快照对源索引中的无效源索引 数据进行过滤;
索引页, 即为索引数据存储的基本单位,数据库中未索引文件分配的磁盘 空间可以从逻辑上划分成页 (从 0到 n连续编号), 每页的大小固定。 逐个索 引页地将索引快照中的源索引数据迁移到目标索引中。
步骤 103: 将迁移过程中所产生的新索引数据存入所述索引緩存中; 在将源索引中的源索引数据迁移到目标索引的同时,也会出现对数据库基 表的 DML事务, 如写事务, 而这些写事务就会引起对索引的操作, 如插入或 删除操作, 进而产生新索引数据, 一旦产生新索引数据, 将这些新索引数据全 部都存入到索引緩存中。
索引緩存由两个队列组成,即,新增元组队列和原有元组删除队列。其中, 新增元组队列按照键值大小进行排序存储,而原有元组删除队列则按照被删除 的原有元组的唯一标识进行排序, 例如, 该唯一标识可以为用于定位数据库基 表中的元组的标识。
另外, 索引緩存运行时, 还需要处理下面的情况, 即当索引緩存空间不足 时, 为了给新增元组提供存储空间, 就需要释放部分元组的空间。 这时, 釆用 的方式是, 把已迁移到目标索引的新增元组(和 /或原有元组的删除标识)批 量插入到源索引的原有元组上, 并释放新增元组所占空间(由于源索引还需提 供查询操作, 所以需要存储这部分元组)。
步骤 104: 在迁移过程中, 如果所述索引緩存中存在正在处理的当前索引 页所需的新索引数据,将所述新索引数据与当前索引页中的源索引数据一同迁 移到所述目标索引中; 或者, 在源索引数据迁移全部完毕后, 将所述索引緩存 中的新索引数据迁移到所述目标索引中。
例如, 针对第一种方式, 4叚设当前正在将源索引的第 1索引页(第 1索引 页为正在处理的当前索引页) 中的源索引数据迁移到目标索引的第 1 索引页 中, 查看索引緩存中是否存在源索引的第 1索引页所需的新索引数据,如果存 在, 将该新索引数据与第 1索引页内的源索引数据一同迁移到目标索引的第 1 索引页中, 依次类推。 其实现过程如图 2所示。 针对第二种方式, 在将源索引 中的源索引数据全部迁移到目标索引之后,再将索引緩存中存在的源索引的第 1索引页所需的新索引数据迁移到目标索引的第 1索引页中, 将索引緩存中存 在的源索引的第 2索引页所需的新索引数据迁移到目标索引的第 1索引页中, 依此类推。 其实现过程如图 3所示。
由于索引快照中的源索引数据是以元组为单位有序排列的,我们把其迁移 到目标索引时, 只需按照其原有顺序迁移即可。 当把索引快照中的一个个元组 迁移到目的索引的索引页面时,会同时查看索引緩存中是否存在比待迁移元组 的键值小的元组,如果没有,直接把该待迁移元组插入到目标索引中,如果有, 则先将索引緩存中的元组插入到目标索引中,直到索引緩存中的元组的键值大 于该待迁移元组的键值为止,然后再把索引快照中待迁移元组插入到目标索引 中。
在把索引快照中待迁移元组插入到目标索引中时,先查看该待迁移元组是 否在索引緩存的原有元组删除队列中, 如果存在,在插入的同时为该待迁移元 组打上一个删除标识。 在将索引緩存中的新索引数据全部存入到目标索引之后,可删除该索引緩 存, 以释放系统的存储空间。 并且, 此时通过设置使目标索引由不可用状态转 变为可用状态, 而在设置目标索引的可用状态过程中, 需要短暂地阻塞 DML 事务, 设置完毕后即可释放阻塞。
另外,在将源索引中的源索引数据迁移到目标索引的过程中,各种索引操 作只能在源索引上, 而不能在新索引上。 而在将源索引中的源索引数据全部迁 移到目标索引之后, 源索引即为不可用, 可将源索引删除, 各种索引操作都只 在新索引上。
由上述实施例可以看出, 与现有技术相比, 本发明的优点在于: 将在索引快照与目标索引之间的源索引数据迁移过程中产生的新索引数 据保存到索引緩存中 (而不是新索引和目标索引中), 减少了因将新索引数据 存入源索引而带来的系统开销。
而对于索引緩存中的新索引数据, 一种方式是: 在将索引快照中某一索引 页的源索引数据迁移到目标索引时,如果此时索引緩存中存在该索引页有关的 新索引数据,也该新索引数据与该索引页中的源索引数据一同迁移到目标索引 中。 另一种方式是, 在将源索引中的源索引数据全部迁移完毕后, 再将索引緩 存中的新索引数据迁移到目标索引中。从而保证向目标索引插入新索引数据的 操作会打断源索引数据的迁移操作, 减少了系统随机 10的操作。
另外, 在整个重建过程中, 只需阻塞一次 DML事务, 阻塞时间短。 实施例二
在上述步骤 104中, 针对第一种方式,假设在将索引緩存中存在的源索引 的第 1索引页所需的新索引数据迁移到目标索引的第 1索引页中之后,又有源 索引的第 1索引页所需的新索引数据存入到索引緩存中,如果不将这些新索引 数据再迁移到目标索引中, 必然会在线重建过程中遗漏索引数据。 针对这一问题, 本实施例与实施例一不同之处在于, 还进一步检查索引緩 存中是否有遗漏的新索引数据 (即, 未存储到目标索引的新索引数据), 并在 确定遗漏的情况下, 将遗漏的新索引数据补入目标索引中。 请参阅图 4, 其为 本发明一种在线重建索引的方法的另一个实施例的流程图,该方法包括以下步 骤:
步骤 401 : 为源索引创建索引快照、 索引緩存和目标索引, 并在创建过程 中阻塞对数据库基表的写事务, 其中, 所述目标索引与所述源索引具有相同的 结构;
步骤 402: 按照索引页的前后顺序逐页地将所述索引快照中的源索引数据 迁移到所述目标索引中,并在迁移过程中通过索引快照对源索引中的无效源索 引数据进行过滤;
步骤 403: 将迁移过程中所产生的新索引数据存入所述索弓 )緩存中; 步骤 404: 在迁移过程中, 如果所述索引緩存中存在正在处理的当前索引 页所需的新索引数据,将所述新索引数据与当前索引页中的源索引数据一同迁 移到所述目标索引中;
上述步骤的详细执行过程可以参见实施例一中的步骤 101-104。
步骤 405: 检查所述索引緩存中是否还存在未存储在目标索引的新索引数 据, 如果是, 进入步骤 406, 否则, 结束流程;
步骤 406: 继续将所述未存储在目标索引的新索引数据迁移到所述目标索 引中, 结束流程。
此处,先查看索引緩存中是否存在目标索引的第 1索引页所需的且也未存 储在目标索引中的新索引数据,如果存在,将该部分新索引数据从索引緩存中 迁移到目标索引中,再继续查看索引緩存中是否存在目标索引的第 2索引页所 需的且也未存储在目标索引中的新索引数据,如果存在,将该部分新索引数据 从索引緩存中迁移到目标索引中, 依此类推。
由上述实施例可以看出, 与现有技术相比, 本发明的优点在于: 将在索引快照与目标索引之间的源索引数据迁移过程中产生的新索引数 据保存到索引緩存中 (而不是新索引和目标索引中), 减少了因将新索引数据 存入源索引而带来的系统开销。
而对于索引緩存中的新索引数据, 一种方式是: 在将索引快照中某一索引 页的源索引数据迁移到目标索引时,如果此时索引緩存中存在该索引页有关的 新索引数据,也该新索引数据与该索引页中的源索引数据一同迁移到目标索引 中。 另一种方式是, 在将源索引中的源索引数据全部迁移完毕后, 再将索引緩 存中的新索引数据迁移到目标索引中。从而保证向目标索引插入新索引数据的 操作会打断源索引数据的迁移操作, 减少了系统随机 10的操作。
另外, 在整个重建过程中, 只需阻塞一次 DML事务, 阻塞时间短。 在整个索引重建过程都是在线完成的, 即, 在索引重建的同时, 也不中断 业务, 使系统仍然可以对索引进行查询、 插入和删除。
其中,在将索引快照中的源索引数据迁移到目标索引的迁移过程中,查询、 插入和删除处理具体如下:
插入处理: 若索引是唯一索引, 则会基于源索引和索引緩存进行唯一性验 证, 如果验证通过, 将要插入的新索引数据存入到索引緩存中。
删除处理: 删除分两种情况, 第一种情况是要删除的索引在源索引中, 那 么只需在索引緩存上记录该索引的删除标记即可;第二种情况是要删除的索引 是重建过程中新插入的索引, 而该索引在索引緩存中, 那么只需在索引緩存中 直接打上删除标识即可。 查询处理: 需要从源索引和索引緩存两处获得索引数 据,如果从源索引中获得索引数据后,还需要从索引緩存中查看该索引数据是 否被删除。
在将索引快照中的源索引数据全部迁移到目标索引之后(此时源索引已不 再可用), 查询、 插入和删除处理具体如下:
插入处理: 若索引是唯一索引, 则会基于目标索引, 或者目标索引和索引 緩存进行唯一性验证,如果验证通过, 将要插入的新索引数据存入到目标索引 中。
删除处理: 删除分两种情况, 第一种情况是要删除的索引在目标索引中, 那么只需在目标索引上记录该索引的删除标记即可;第二种情况是要删除的索 引在索引緩存中, 那么只需在索引緩存中直接打上删除标识即可。 查询处理: 需要从源索引和索引緩存两处获得索引数据, 如果从源索引中 获得索引数据后, 还需要从索引緩存中查看该索引数据是否被删除。 实施例三
与上述一种在线重建索引的方法相对应,本发明实施例还提供了一种在线 重建索引的装置。 请参阅图 5, 其为本发明一种在线重建索引的装置的一个实 施例结构图, 该装置包括: 创建单元 501、 源索引数据重建单元 502、 新索引 数据緩存单元 503和新索引数据重建单元 504。 下面结合该装置的工作原理进 一步介绍其内部结构以及连接关系。
创建单元 501, 用于为源索引创建索引快照、 索引緩存和目标索引, 并在 创建过程中阻塞对数据库基表的写事务, 其中, 所述目标索引用于所述源索引 具有相同的结构;
源索引数据重建单元 502, 用于按照索引页的先后顺序逐页地将所述索引 快照中的源索引数据迁移到所述目标索引中,并在迁移过程中通过索引快照对 源索引中的无效源索引数据进行过滤;
新索引数据緩存单元 503, 用于将在迁移过程中产生的新索引数据存入所 述索引緩存中;
新索引数据重建单元 504, 用于在迁移过程中, 如果所述索引緩存中存在 正在处理的当前索引页所需的新索引数据,将所述新索引数据与当前索引页中 的源索引数据一同迁移到所述目标索引中, 或者, 用于在源索引数据全部迁移 完毕后, 将所述索引緩存中的新索引数据迁移到所述目标索引中。
优选的, 如图 6所示, 该装置还包括: 检查单元 505和新索引数据补建单 元 506, 其中,
检查单元 505, 用于当在源索引数据迁移过程中将新索弓 )数据与当前索引 页中的源索引数据一同迁移到所述目标索引中时, 当新索引数据迁移到完毕 后, 检查所述索引緩存中是否还存在未存储在目标索引的新索引数据;
新索引数据补建单元 506, 用于所述检查单元检查出所述索引緩存中还存 在未存储在目标索引的新索引数据,将所述未存储在目标索引的新索引数据迁 移到所述目标索引中。 进一步优选的, 所述装置还包括: 删除单元, 用于在将所述索引緩存中的 新索引数据全部存入到所述目标索引中之后, 删除所述索引緩存。
或者, 进一步优选的, 所述装置还包括: 设置单元, 用于在将所述源索引 中的源索引数据全部迁移到所述目标索引中之后,将所述源索引设置为不可用 状态。
由上述实施例可以看出, 与现有技术相比, 本发明的优点在于: 将在索引快照与目标索引之间的源索引数据迁移过程中产生的新索引数 据保存到索引緩存中 (而不是新索引和目标索引中), 减少了因将新索引数据 存入源索引而带来的系统开销。
而对于索引緩存中的新索引数据, 一种方式是: 在将索引快照中某一索引 页的源索引数据迁移到目标索引时,如果此时索引緩存中存在该索引页有关的 新索引数据,也该新索引数据与该索引页中的源索引数据一同迁移到目标索引 中。 另一种方式是, 在将源索引中的源索引数据全部迁移完毕后, 再将索引緩 存中的新索引数据迁移到目标索引中。从而保证向目标索引插入新索引数据的 操作会打断源索引数据的迁移操作, 减少了系统随机 10的操作。
另外, 在整个重建过程中, 只需阻塞一次 DML事务, 阻塞时间短。 所述领域的技术人员可以清楚地了解到, 为了描述的方便和简洁, 上述描 述的系统、装置和单元的具体工作过程, 可以参考前述方法实施例中的对应过 程, 在此不再赘述。
在本发明所提供的几个实施例中, 应该理解到, 所揭露的系统、 装置和方 法, 可以通过其它的方式实现。 例如, 以上所描述到的装置实施例仅仅是示意 性的, 例如, 所述单元的划分, 仅仅为一种逻辑功能划分, 实际实现时可以有 另外的划分方式, 例如多个单元或组件可以结合或可以集成到另一个系统, 或 一些特征可以忽略, 或不执行。 另一点, 所显示或讨论的相互之间的耦合或直 接輛合或通信连接可以是通过一些接口, 装置或单元的间接輛合或通信连接, 可以是电性、 机械或其它的形式。 元显示的部件可以是或者也可以不是物理单元, 即可以位于一个地方, 或者也 可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单 元来实现本实施例方案的目的。
另外, 在本发明各个实施例中的各功能单元可以集成在一个处理单元中, 也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元 中。上述集成的单元既可以釆用硬件的形式实现, 可以釆用软件功能单元的形 式实现。
需要说明的是,本领域普通技术人员可以理解实现上述实施例方法中的全 部或部分流程,是可以通过计算机程序来指令相关的硬件来完成, 所述的程序 可存储于一计算机可读取存储介质中, 该程序在执行时, 可包括如上述各方法 的实施例的流程。 其中, 所述的存储介质可为磁碟、 光盘、 只读存储记忆体 ( Read-Only Memory, ROM )或随机存储记忆体 ( Random Access Memory, RAM )等。
以上对本发明所提供的一种在线重建索引的方法和装置进行了详细介绍, 的说明只是用于帮助理解本发明的方法及其核心思想; 同时,对于本领域的一 般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之 处, 综上所述, 本说明书内容不应理解为对本发明的限制。

Claims

权 利 要 求
1、 一种在线重建索引的方法, 其特征在于, 包括:
为源索引创建索引快照、 索引緩存和目标索引, 并在创建过程中阻塞对数 据库基表的写事务, 其中, 所述目标索引与所述源索引具有相同的结构; 目标索引中,并在迁移过程中通过索引快照对源索引中的无效源索引数据进行 过滤;
将迁移过程中所产生的新索引数据存入所述索引緩存中;
在迁移过程中,如果所述索引緩存中存在正在处理的当前索引页所需的新 索引数据,将所述新索引数据与当前索引页中的源索引数据一同迁移到所述目 标索引中; 或者, 在源索引数据全部迁移完毕后, 将所述索引緩存中的新索引 数据迁移到所述目标索引中。
2、 根据权利要求 1所述的方法, 其特征在于, 所述方法还包括: 当在迁移过程中将新索引数据与当前索引页中的源索引数据一同迁移到 所述目标索引中时,在迁移完毕后,检查所述索引緩存中是否还存在未存储在 目标索引的新索引数据;
如果是,继续将所述未存储在目标索引的新索引数据迁移到所述目标索引 中。
3、 根据权利要求 1或 2所述的方法, 其特征在于, 还包括:
在将所述索引緩存中的新索引数据全部存入到所述目标索引中之后,删除 所述索引緩存。
4、 根据权利要求 1或 2所述的方法, 其特征在于, 还包括:
在将所述源索引中的源索引数据全部迁移到所述目标索引中之后,将所述 源索引设置为不可用状态。
5、 根据权利要求 1所述的方法, 其特征在于, 在索引重建过程中, 通过 如下方式查询索引数据:
在迁移过程中, 在所述源索引和所述索引緩存中查询符合要求的索引数 据;
在迁移完毕后,在目标索引中或者在所述目标索引和所述索引緩存中查询 符合要求的索引数据。
6、根据权利要求 1所述的方法, 其特征在于, 在源索引数据迁移完毕后, 通过如下方式添加新索引数据:
判断在所述索引緩存和所述目标索引中是否存在要添加的新索引数据;如 果在所述索引緩存和所述目标索引中都不存在要添加的新索引数据,将所述要 添加的新索引数据存入目标索引中。
7、 一种在线重建索引的装置, 其特征在于, 包括:
创建单元, 用于为源索引创建索引快照、 索引緩存和目标索引, 并在创建 过程中阻塞对数据库基表的写事务, 其中, 所述目标索引用于所述源索引具有 相同的结构; 中的源索引数据迁移到所述目标索引中,并在迁移过程中通过索引快照对源索 引中的无效源索引数据进行过滤;
新索引数据緩存单元,用于将在迁移过程中产生的新索引数据存入所述索 引緩存中;
新索引数据重建单元, 用于在迁移过程中,如果所述索引緩存中存在正在 处理的当前索引页所需的新索引数据,将所述新索引数据与当前索引页中的源 索引数据一同迁移到所述目标索引中; 或者, 用于在源索引数据全部迁移完毕 后, 将所述索引緩存中的新索引数据迁移到所述目标索引中。
8、 根据权利要求 7所述的装置, 其特征在于, 所述装置还包括: 检查单元,用于当在源索引数据迁移过程中将新索引数据与当前索引页中 的源索引数据一同迁移到所述目标索引中时,在迁移到完毕后,检查所述索引 緩存中是否还存在未存储在目标索引的新索引数据;
新索引数据补建单元,用于所述检查单元检查出所述索引緩存中还存在未 存储在目标索引的新索引数据,继续将所述未存储在目标索引的新索引数据迁 移到所述目标索引中。
9、 根据权利要求 7或 8所述的装置, 其特征在于, 所述装置还包括: 删除单元,用于在将所述索引緩存中的新索引数据全部存入到所述目标索 引中之后, 删除所述索引緩存。
10、 根据权利要求 7或 8所述的装置, 其特征在于, 所述装置还包括: 设置单元,用于在将所述源索引中的源索引数据全部迁移到所述目标索引 中之后, 将所述源索引设置为不可用状态。
PCT/CN2014/076185 2013-10-14 2014-04-25 一种在线重建索引的方法和装置 WO2015054998A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP14854786.2A EP3002687A4 (en) 2013-10-14 2014-04-25 METHOD AND DEVICE FOR RECREATING AN ONLINE INDEX
US14/981,111 US20160132542A1 (en) 2013-10-14 2015-12-28 Online index rebuilding method and apparatus

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310478786.3A CN103605657A (zh) 2013-10-14 2013-10-14 一种在线重建索引的方法和装置
CN201310478786.3 2013-10-14

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US14/981,111 Continuation US20160132542A1 (en) 2013-10-14 2015-12-28 Online index rebuilding method and apparatus

Publications (1)

Publication Number Publication Date
WO2015054998A1 true WO2015054998A1 (zh) 2015-04-23

Family

ID=50123882

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/076185 WO2015054998A1 (zh) 2013-10-14 2014-04-25 一种在线重建索引的方法和装置

Country Status (4)

Country Link
US (1) US20160132542A1 (zh)
EP (1) EP3002687A4 (zh)
CN (1) CN103605657A (zh)
WO (1) WO2015054998A1 (zh)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605657A (zh) * 2013-10-14 2014-02-26 华为技术有限公司 一种在线重建索引的方法和装置
CN105373566B (zh) * 2014-08-30 2018-01-23 华为技术有限公司 在线重建索引方法及装置
CN106897345B (zh) * 2016-07-22 2021-01-05 创新先进技术有限公司 一种数据存储的方法及装置
CN107766386B (zh) * 2016-08-22 2023-01-10 中兴通讯股份有限公司 一种solr数据迁移方法和装置
CN106407376B (zh) * 2016-09-12 2019-12-20 杭州数梦工场科技有限公司 重建索引方法及装置
US11055264B2 (en) * 2017-05-10 2021-07-06 Dropbox, Inc. Automatically coordinating application schema changes in a distributed data storage system
CN108062358B (zh) * 2017-11-28 2020-12-29 厦门市美亚柏科信息股份有限公司 innodb引擎删除记录的离线恢复方法、存储介质
CN108376156B (zh) * 2018-02-08 2020-08-14 上海达梦数据库有限公司 创建数据库索引的方法、装置、服务器及存储介质
CN111857539B (zh) * 2019-04-25 2024-04-12 伊姆西Ip控股有限责任公司 用于管理存储系统的方法、设备和计算机可读介质
CN110990377B (zh) * 2019-11-21 2023-08-22 上海达梦数据库有限公司 一种数据装载方法、装置、服务器及存储介质
US11768621B2 (en) * 2021-12-06 2023-09-26 Gong.Io Ltd. Live data migration in document stores

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6591269B1 (en) * 1999-05-19 2003-07-08 Sybase, Inc. Database system with methodology for online index rebuild
CN102955792A (zh) * 2011-08-23 2013-03-06 崔春明 一种实时全文搜索引擎事务处理的实现方法
CN103605657A (zh) * 2013-10-14 2014-02-26 华为技术有限公司 一种在线重建索引的方法和装置

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8195702B2 (en) * 2007-07-30 2012-06-05 Oracle International Corporation Online index builds and rebuilds without blocking locks

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6591269B1 (en) * 1999-05-19 2003-07-08 Sybase, Inc. Database system with methodology for online index rebuild
CN102955792A (zh) * 2011-08-23 2013-03-06 崔春明 一种实时全文搜索引擎事务处理的实现方法
CN103605657A (zh) * 2013-10-14 2014-02-26 华为技术有限公司 一种在线重建索引的方法和装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3002687A4 *

Also Published As

Publication number Publication date
CN103605657A (zh) 2014-02-26
US20160132542A1 (en) 2016-05-12
EP3002687A4 (en) 2016-07-20
EP3002687A1 (en) 2016-04-06

Similar Documents

Publication Publication Date Title
WO2015054998A1 (zh) 一种在线重建索引的方法和装置
JP6556911B2 (ja) 注釈付きアトミック書き込み操作を行う方法および装置
US9798728B2 (en) System performing data deduplication using a dense tree data structure
US11775485B2 (en) Concurrent access and transactions in a distributed file system
WO2018099397A1 (zh) 数据库集群中数据迁移的方法、装置及存储介质
US8209307B2 (en) Systems and methods for data migration in a clustered file system
US8694469B2 (en) Cloud synthetic backups
US8499004B2 (en) File system with optimistic I/O operations on shared storage
US9990225B2 (en) Relaxing transaction serializability with statement-based data replication
US9274716B2 (en) Systems and methods for hierarchical reference counting via sibling trees
US9251003B1 (en) Database cache survivability across database failures
US20170031768A1 (en) Method and apparatus for reconstructing and checking the consistency of deduplication metadata of a deduplication file system
US11829606B2 (en) Cloud object storage and versioning system
US10747727B2 (en) Concurrent access and transactions in a distributed file system
US9984139B1 (en) Publish session framework for datastore operation records
US20140181036A1 (en) Log consolidation
US20170109246A1 (en) Database-level automatic storage management
US10909091B1 (en) On-demand data schema modifications
JP2015203927A (ja) 計算機システム、データの検査方法及び計算機
US20170193000A1 (en) Recovering from a pending uncompleted reorganization of a data set
US10387384B1 (en) Method and system for semantic metadata compression in a two-tier storage system using copy-on-write
US20170286442A1 (en) File system support for file-level ghosting
US10452496B2 (en) System and method for managing storage transaction requests
EP3082050A1 (en) Mass data fusion storage method and system
US10628391B1 (en) Method and system for reducing metadata overhead in a two-tier storage architecture

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14854786

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 2014854786

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE