Updated on 2024-10-09 GMT+08:00

Introduction to HBase Global Secondary Indexes

Scenarios

HBase secondary indexes can be used to accelerate conditional queries with filters. HBase secondary indexes support local secondary indexes (HIndexes) and global secondary indexes (GSIs). Compared with local indexes (HIndex), global secondary indexes have better query performance and are suitable for scenarios that require high read latency.

HBase global secondary indexes use independent index tables to store index data. When a given query condition can hit an index, a full table query on a data table can be converted into an exact range query on an index table, thereby improving a query speed. After the global secondary index feature is enabled, the code on the application side does not need to be modified, which is easy to use.

For MRS 3.3.0 or later, HBase global secondary index is enable by default. To modify the related parameters, log in to FusionInsight Manager, choose Cluster > Services > HBase > Confiurations > All Configurations, select RegionServer(Role) > Secondary Indexes and HMaster(Role) > Secondary Indexes.

HBase global secondary indexes support the following key features:

  • Composite Index

    Multiple columns can be specified as index columns (cross-column-family is supported).

  • Overwrite Index

    Multiple columns or column families can be specified as overwrite columns or column families and stored in the index table in redundancy mode. This function is used to quickly query non-index columns in index query.

  • Index TTL

    Index table TTL is used when TTL is enabled for a data table. To ensure consistency with the data table, the index table TTL automatically inherits the TTL of the index column and overwrites column of the data table and cannot be manually specified.

  • Online index change

    Indexes can be created, deleted, and their status can be modified online without affecting data table read and write.

  • Online index repair

    When the index data hit by the query is invalid, index repair can be triggered to ensure that the final query result is correct.

  • Index Tool

    Supports index consistency check, index repair, index creation, deletion, and status modification, and index data rebuilding.

Restrictions on HBase Global Secondary Indexes

  • Application Scenario Restrictions
    • GSI cannot be used together with HIndex. That is, local indexes and global indexes cannot be created in the same data table at the same time.
    • Index tables do not support DR.
    • Rolling upgrade is not supported for index data.
    • DISABLE, DROP, MODIFY, and TRUNCATE cannot be directly performed on index tables.
    • DDL operations on indexes allow you to modify index status, delete indexes, and create indexes. Index definitions cannot be modified. To modify index definitions, delete them and create indexes again.
  • Constraints on Index Creation
    • The index name must comply with the regular expression requirements and does not support other characters. The regular expression must support the following characters: [a-zA-Z_0-9-.]:
    • The data table must exist. The index to be created cannot exist.
    • The index table does not support multiple versions.

      Indexes cannot be created on data tables with multiple versions (VERSION>1), and the version of the index table is 1.

    • The number of indexes in a single data table cannot exceed 5.

      You are not advised to create too many indexes for a single data table. If there are too many indexes, the storage cost is high and the write time is long. If more than five indexes need to be created, add the hbase.gsi.max.index.count.per.table parameter to the customized configuration hbase.hmaster.config.expandor of HMaster and set the parameter to a value greater than 5. Restart HMaster for the configuration to take effect.

    • The index name can contain a maximum of 18 characters.

      You are not advised to use an excessively long index name. To create a long index name, add the hbase.gsi.max.index.name.length parameter to the customized configuration hbase.hmaster.config.expandor of HMaster, set the parameter to a value greater than 18, and restart HMaster for the configuration to take effect.

    • Indexes cannot be created for index tables.

      Multiple indexes cannot be created in nested mode. Index tables are used only to accelerate query and do not provide data table functions.

    • Indexes that can be overwritten by existing indexes cannot be created.

      When you create an index, if the existing index can completely overwrite the new index (that is, the created index is a subset of the existing index), the index cannot be created. Indexes with duplicate functions cause storage waste. For example, index 2 cannot be created if you perform the following operations:

      Create a data table: create't1','cf1'

      Create index 1: hbase org.apache.hadoop.hbase.hindex.global.mapreduce.GlobalTableIndexer -Dtablename.to.index='t1' -Dindexspecs.to.add='idx1=>cf1:[q1],[q2]'

      Create index 2: hbase org.apache.hadoop.hbase.hindex.global.mapreduce.GlobalTableIndexer -Dtablename.to.index='t1' -Dindexspecs.to.add='idx2=>cf1:[q1]'

    • Indexes with the same name cannot be created in the same data table. Indexes with the same name can be created in different data tables.
    • The TTL of the index table column family is inherited from the original table. The TTL of the index column family must be the same.

      The TTLs of all column families in an index table are the same and are inherited from a data table. The TTLs of related column families in the data table must be the same. Otherwise, related indexes cannot be created.

    • Other attributes of the user-defined index table are not supported.
  • Constraints on Writing Indexes
    • Only the Put/Delete interface can be used to generate index data. When data is written to a data table in other modes (such as Increment, Append, and Bulkload), the corresponding index is not generated.
    • When the index column data is defined as the string type, do not write the special characters \x00 and \x01 (special invisible characters).
    • Do not write data to index columns by specifying timestamps.
  • Constraints on Index Query
    • The index status must be ACTIVE during index query.
    • The index query does not support the query by specifying the timestamp range. If you need to query data within the time range by index, add a time column to store the timestamp of the data. Otherwise, the data table will be used for query.
    • Index query does not support range query by specifying StartRow and StopRow. If either of them is specified, the query operation does not use the index query. Instead, the Range Scan+Filter filtering function of the primary table is used.
    • Index query supports only SingleColumnValueFilter. Index acceleration cannot be triggered when other filters are used or no filter condition is used.