Skip to main content
Beta feature Advice on use of Beta features Since version 3.3.0, the database supports full-text inverted indexes, which can break the text into smaller words, and create an index entry for each word that can show the mapping relationship between the word and its corresponding row number in the data file. For full-text searches, the database queries the inverted index based on the search keywords, quickly locating the data rows that match the keywords. Primary Key tables support full-text inverted indexes from v4.0 onwards. Since v4.1, the database supports a built-in inverted index implementation in addition to the default CLucene-based implementation. The built-in implementation supports both shared-nothing and shared-data clusters. For details, see built-in inverted index.

Overview

The database stores its underlying data in the data files organized by columns. Each data file contains the full-text inverted index based on the indexed columns. The values in the indexed columns are tokenized into individual words. Each word after tokenization is treated as an index entry, mapping to the row number where the word appears. Currently supported tokenization methods for English tokenization, Chinese tokenization, multilingual tokenization, and no tokenization. For example, if a data row contains “hello world” and its row number is 123, the full-text inverted index builds index entries based on this tokenization result and row number: hello->123, world->123. During full-text searches, the database can locate index entries containing the search keywords using full-text inverted indexes, and then quickly find the row numbers where the keywords appear, significantly reducing the number of data rows that need to be scanned.

Basic operation

Create full-text inverted index

Note When creating a full-text inverted index for a table, you must disable the replicated_storage feature for the table.
  • For v4.0 and later, this feature is automatically disabled when you create the index.
  • for versions earlier than v4.0, you must manually set the table property replicated_storage to false.

Create full-text Inverted Index at table creation

Creating a full-text inverted index on column v with English tokenization.
  • The parser parameter specifies the tokenization method. Supported values and descriptions are as follows:
    • none (default): no tokenization. The entire row of data in the indexed column is treated as a single index item when the full-text inverted index is constructed.
    • english: English tokenization. This tokenization method typically tokenizing at any non-alphabetic character. Also, uppercase English letters are converted to lowercase. Therefore, keywords in the query conditions need to be lowercase English rather than uppercase English to leverage the full-text inverted index to locate data rows.
    • chinese: Chinese tokenization. This tokenization method uses the CJK Analyzer in CLucene for tokenization.
    • standard: Multilingual tokenization. This tokenization method provides grammar based tokenization (based on the Unicode Text Segmentation algorithm) and works well for most languages and cases of mixed languages, such as Chinese and English. For example, this tokenization method can distinguishes between Chinese and English when these two languages coexist. After tokenizing English, it converts uppercase English letters to lowercase. Therefore, keywords in the query conditions need to be lowercase English rather than uppercase English to leverage the full-text inverted index to locate data rows.
  • The data type of the indexed column must be CHAR, VARCHAR, or STRING.

Add full-text inverted index after table creation

After table creation, you can add a full-text inverted index using ALTER TABLE ADD INDEX or CREATE INDEX.

Manage full-text inverted index

View full-text inverted index

Execute SHOW CREATE TABLE to view full-text inverted indexes.

Delete full-text inverted index

Execute ALTER TABLE ADD INDEX or DROP INDEX to delete full-text inverted indexes.

Accelerate queries by full-text inverted index

After creating a full-text inverted index, you need to ensure that the system variable enable_gin_filter is enabled, so the inverted index can accelerate queries. Also, you need to consider whether the index column values are tokenized to determine which queries can be accelerated.

Supported queries when indexed column is tokenized

When a full-text inverted index column is enabled with tokenization (parser = standard | english | chinese), only the MATCH, MATCH_ANY, or MATCH_ALL predicates are supported for filtering. The supported formats are:
  • <col_name> (NOT) MATCH '%keyword%'
  • <col_name> (NOT) MATCH_ANY 'keyword1, keyword2'
  • <col_name> (NOT) MATCH_ALL 'keyword1, keyword2'
Here, keyword must be a string literal; expressions are not supported. For a nullable indexed column, rows whose value is NULL are not returned by NOT MATCH, NOT MATCH_ANY, or NOT MATCH_ALL.
  1. Create a table and insert a few rows of test data.
  2. Use the MATCH predicate for querying.
  • Query data rows whose value column contains the keyword starrocks.
  • Retrieve data rows whose value column contains the keyword starting with data.
  1. Use the MATCH_ANY predicate for querying.
  • Query data rows whose value column contains the keyword database or data.
  1. Use the MATCH_ALL predicate for querying.
  • Query data rows whose value column contains both the keyword database and data.
Notes:
  • During queries, keywords can be matched fuzzily using %, in the format of %keyword%. However, the keyword must contain a part of a word. For example, if the keyword is starrocks , it cannot match the word starrocks because it contains spaces.
  • If English or multilingual tokenization is used to construct the full-text inverted index, uppercase English words are converted to lowercase when the full-text inverted index is actually stored. Therefore, during queries, keywords need to be lowercase instead of uppercase to utilize the full-text inverted index to locate data rows.
  • The MATCH, MATCH_ANY, or MATCH_ALL predicate in the query conditions must be used as a pushdown predicate, so it must be in the WHERE clause and be performed against the indexed column. Take the following table and test data as an example:
    The following query statements do not meet the requirement:
    • Because the MATCH, MATCH_ANY, or MATCH_ALL predicate in the query statement is not in the WHERE clause, it can not be pushed down, resulting in a query error.
    • Because the column value_test against which the MATCH, MATCH_ANY, or MATCH_ALL predicate in the query statement is performed is not an indexed column, the query fails.

Supported queries when indexed column is not tokenized

If the full-text inverted index does not tokenize the indexed column, that is, 'parser' = 'none', all pushdown predicates in the query conditions listed below can be used for data filtering using the full-text inverted index:
  • Expression predicates: (NOT) LIKE, (NOT) MATCH, (NOT) MATCH_ANY, (NOT) MATCH_ALL Note
    • In this case, MATCH is semantically equivalent to LIKE.
    • MATCH and LIKE only support the format (NOT) <col_name> MATCH|LIKE '%keyword%'. The keyword must be a string literal and does not support expressions. Note that if LIKE does not meet this format, even if the query can be executed normally, it will degrade to a query that does not use the full-text inverted index to filter data.
  • Regular predicates: ==, !=, <=, >=, NOT IN, IN, IS NOT NULL, NOT NULL

Verify whether a query is accelerated by the full-text inverted index

After executing the query, you can view the detailed metrics GinFilterRows and GinFilter in the scan node of the Query Profile to see the number of rows filtered and the filtering time using the full-text inverted index.

Built-in inverted index

Since v4.1, the database provides a built-in inverted index implementation in addition to the default CLucene-based implementation. The built-in implementation is the database’ native inverted index built on top of bitmap index, and supports both shared-nothing and shared-data clusters. Note The CLucene-based inverted index implementation is not supported in shared-data clusters. For shared-data clusters, you must use the built-in implementation.

Implementation comparison

You can explicitly specify the implementation type using the imp_lib parameter when creating an index. If not specified, the system automatically selects the appropriate implementation based on the cluster mode:
  • In shared-nothing clusters, the default is CLucene.
  • In shared-data clusters, the default is built-in (CLucene is not supported).

Create built-in inverted index

Create at table creation

Add after table creation

Built-in inverted index in shared-data clusters

In shared-data clusters, the built-in implementation is automatically selected even if imp_lib is not specified. You can create the index using the same syntax as for a regular inverted index:
You can also explicitly specify "imp_lib" = "builtin" for clarity:

dict_gram_num

The dict_gram_num parameter is available exclusively for the built-in inverted index implementation. It controls the n-gram size used to build an n-gram dictionary index on top of the inverted index dictionary, which can significantly accelerate wildcard and substring queries.

How it works

When dict_gram_num is set to a positive integer (e.g., 2), the built-in inverted index splits each dictionary entry into n-grams (substrings of the specified character length) during index construction. For example, if dict_gram_num is set to 2 and a dictionary entry is "starrocks", the following 2-grams are generated: "st", "ta", "ar", "rr", "ro", "oc", "ck", "ks". During a query like MATCH '%rock%', the query string "rock" is also split into 2-grams ("ro", "oc", "ck"), and the n-gram index quickly narrows down candidate dictionary entries, avoiding a full dictionary scan. This greatly improves the performance of wildcard queries, especially on columns with a large number of distinct values.

Parameter details

Guidelines for choosing dict_gram_num

  • A smaller value (e.g., 2) generates more n-grams per dictionary entry, increasing index size but providing better filtering for short query patterns.
  • A larger value (e.g., 4) generates fewer n-grams, resulting in smaller index size but less effective filtering for short query patterns.
  • If your queries primarily use short wildcard patterns (e.g., %ab%), a smaller dict_gram_num value (such as 2) is recommended.
  • If the query pattern is shorter than the dict_gram_num value, the n-gram index cannot be used for that query and falls back to a full dictionary scan.

Examples

Create built-in inverted index with dict_gram_num
  1. Create a table with a built-in inverted index and dict_gram_num set to 2.
  2. Insert test data.
  3. Query with wildcard patterns. The n-gram dictionary index accelerates these queries.
Add dict_gram_num to an existing table You can also specify dict_gram_num when adding a built-in inverted index after table creation:

lower_case

The lower_case parameter is available exclusively for the built-in inverted index implementation with English tokenization ("parser" = "english"). It controls whether English tokens are normalized to lowercase when the index is built and when queries are matched against it.

Parameter details

  • true (default): Uppercase English letters are converted to lowercase both when the index is built and when query keywords are matched, so matching is case-insensitive. This preserves the existing behavior.
  • false: Case is preserved during both indexing and matching, so matching is case-sensitive. Use this when you need to distinguish words that differ only in case, such as Apple, apple, and APPLE.

Example

Create a built-in English inverted index with case-sensitive matching: