lower to the name column: CREATE INDEX users_name_idx ON users (lower(name)). The value of the expression is stored only in the expression index, not in the primary family index.
Both and support expressions. You can use expressions in and .
You can reference multiple columns in an expression index.
Create an expression index
To create an expression index, use the syntax:View index expression
To view the expression used to generate the index, runSHOW CREATE TABLE:
Examples
Create various expression indexes
Suppose you have a table with the following columns:Use an expression to index a field in a JSONB column
You can use an expression in an index definition to index a field in a JSON column. You can also use an expression to create a on a subset of the JSON column.
Normally an index is used only if the cost of using the index is less than the cost of a full table scan. To disable that optimization, turn off statistics collection:
user_profile column:
user_profile->'birthdate' column:
birthdate field:
parse_timestamp(user_profile->'birthdate'), only the row matching the filter is scanned:
Known limitations
Expression indexes have the following limitations:- The expression cannot reference columns outside the index’s table.
-
Functional expression output must be determined by the input arguments. For example, you can’t use the
now()to create an index because its output depends on more than just the function arguments. - CockroachDB does not allow expression indexes to reference .
-
CockroachDB does not support expressions as
ON CONFLICTtargets. This means that unique expression indexes cannot be selected as arbiters for statements. For example:

