tencent cloud

TDSQL Boundless

Columnar Storage Secondary Index

Download
Modo Foco
Tamanho da Fonte
Última atualização: 2026-07-08 17:25:19

Index Introduction

Indexes are a crucial capability for accelerating database queries. To fully meet the query requirements of different businesses and enhance overall query performance, the TDSQL Boundless read-only analysis instance comprehensively supports columnar storage-based secondary index capabilities. It currently supports the following three index types:
Zonemap Index: a built-in zone map index that is automatically maintained and requires no user creation.
Bloom Filter Index: a skip index based on a Bloom filter, which is suitable for accelerating equality queries.
Bitmap Index: a bitmap-based index that is suitable for scenarios such as multidimensional analysis and ad-hoc queries.
Generally, creating an index for predicate queries on high-cardinality columns with low selectivity can significantly reduce the amount of data scanned by queries, thereby markedly improving query speed.
Attention:
Zonemap Index is automatically maintained by the system. Users do not need to create it and cannot proactively create or delete it via SQL.

Zonemap Index

Zonemap Index is a built-in system index that requires no configuration from users. The system automatically records statistical information, such as the maximum value, minimum value, and whether NULL values are included, for each column and each data block.
For scenarios such as equality queries (=), range queries (>, <, >=, <=, BETWEEN), and IS NULL, the optimizer can use the maximum value, minimum value, and NULL flag to determine whether a data file or data block contains data that meets the conditions. If it does not, the corresponding file or data block is skipped. This approach reduces unnecessary I/O overhead and effectively accelerates the query process.

Bloom Filter Index

Bloom Filter Index is a skip index based on a Bloom filter. It uses the Bloom filter to quickly determine whether a specified data block might contain data that matches an equality query condition. Data blocks that cannot possibly contain matches are skipped directly, thereby reducing I/O and accelerating queries.
A Bloom filter is a space-efficient probabilistic data structure used to check whether an element belongs to a set. For a query on a single element, the Bloom filter returns only two possible results: possibly present or definitely absent.

Scenarios

Bloom Filter Index is suitable for accelerating equality queries (= and IN), and it performs even better on high-cardinality fields (fields with a large number of distinct values).

Limitations

Bloom Filter Index accelerates queries only for predicates such as = and IN. It is ineffective for other predicates, including !=, NOT IN, >, <, and LIKE.
Only the following field types are supported:
Integer types: SMALLINT, MEDIUMINT, INT, BIGINT (does not support TINYINT).
Fixed-point number type: DECIMAL
String types: CHAR, VARCHAR, TEXT, and so on
Time types: DATE, TIME, DATETIME
Creating an index based on an expression is not supported.
Multi-column composite indexes are not supported. Each index can only be created on a single column.
Creating tables in the system database is not supported.

Using Indexes

When a query is executed, if a Bloom Filter Index has been created on a field involved in an equality predicate or an IN predicate within the WHERE clause, the optimizer automatically applies that index to accelerate the query. No explicit user specification is required.

Related Commands

Create an index.
CREATE INDEX [IF NOT EXISTS] index_name USING BLOOM_FILTER ON table_name (column_name);
Delete an index.
DROP INDEX [IF EXISTS] index_name ON table_name;
Viewing an Index
-- Method 1: View the table creation statement.
SHOW CREATE TABLE table_name;

-- Method 2: View all indexes on a table.
SHOW INDEX FROM table_name;

-- Method 3: Query metadata.
SELECT * FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';

Bitmap Index

Bitmap Index is an index represented by bitmaps, where a bitmap is created for each key value in a column. Compared to other indexes, Bitmap Index occupies less storage space and offers higher efficiency for both construction and queries. However, its modification operations involve a larger lock granularity, making it unsuitable for scenarios with frequent updates.

Scenarios

It is suitable for columns with high value repetition. The number of distinct values in a column is recommended to be between 100 and 100,000, for example: occupation, prefecture-level city, etc. When the repetition rate is too high, its advantage over other index types is not significant. When the repetition rate is too low, both space efficiency and query performance will degrade.
It is suitable for scenarios involving multi-condition combined queries. For example, the following queries:
SELECT COUNT(*) FROM users
WHERE city = 'Nanjing' AND job = 'doctor' AND device_type = 'iphone' AND gender = 'male';
If a Bitmap Index is established on each query condition column, the database can precisely locate target data through efficient bitwise operations (AND / OR), reducing disk I/O. The smaller the filtered result set, the more pronounced the advantage of the Bitmap Index becomes.
It is suitable for analytical scenarios such as ad-hoc queries and multidimensional analysis. For example, for a wide table containing 100 columns, if business requirements necessitate using 20 of those columns as query conditions (in any combination), you can establish a Bitmap Index on each of those 20 columns, enabling all related queries to benefit from index acceleration.

Scenarios Not Applicable

Columns with low value repetition, for example: ID card numbers, mobile phone numbers, etc.
Columns with excessively high repetition rates, for example: gender. An index can be created on them, but it is not recommended to use them as a standalone query condition. It is recommended to filter them in combination with other conditions.
Columns that are frequently updated.

Limitations

Bitmap Index supports the following predicates: =, !=, >, <, >=, <=, IN, IS NULL, IS NOT NULL. When multiple predicates are combined, using AND connections yields the best pruning effect.
Only the following field types are supported:
Integer types: TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT
Fixed-point number type: DECIMAL
String types: CHAR, VARCHAR, TEXT, and so on.
Time types: DATE, TIME, DATETIME
Creating an index based on an expression is not supported.
Multi-column composite indexes are not supported. Each index can only be created on a single column.
Creating tables in the system database is not supported.

Related Commands

Create an index.
CREATE INDEX [IF NOT EXISTS] index_name USING BITMAP ON table_name (column_name);
Delete an index.
DROP INDEX [IF EXISTS] index_name ON table_name;
Viewing an Index
-- Method 1: View the table creation statement.
SHOW CREATE TABLE table_name;

-- Method 2: View all indexes on a table.
SHOW INDEX FROM table_name;

-- Method 3: Query metadata.
SELECT * FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name';

Ajuda e Suporte

Esta página foi útil?

comentários