ALTER MATERIALIZED VIEW ADD INDEX

Adds an index to a SYMBOL column in a materialized view, improving query performance for filtered lookups.

Syntax​

ALTER MATERIALIZED VIEW viewName ALTER COLUMN columnName ADD INDEX [ CAPACITY n ]

Parameters​

ParameterDescription
viewNameName of the materialized view
columnNameName of the SYMBOL column to index
CAPACITYOptional index capacity (advanced; use default unless you understand implications)

When to use​

Add an index when:

  • Queries frequently filter by a SYMBOL column (e.g., WHERE symbol = 'BTC-USD')
  • The column has high cardinality (many distinct values)
  • Query performance on the materialized view needs improvement

Example​

Add index to symbol column
ALTER MATERIALIZED VIEW trades_hourly
ALTER COLUMN symbol ADD INDEX;

Behavior​

AspectDescription
Operation typeAtomic, non-blocking, non-waiting
Immediate effectSQL optimizer starts using the index once created
Column requirementColumn must be of type SYMBOL
note

Index capacity and symbol capacity are different settings. Only change index capacity if you understand the implications.

Permissions (Enterprise)​

Adding an index requires the ALTER MATERIALIZED VIEW permission:

Grant alter permission
GRANT ALTER MATERIALIZED VIEW ON trades_hourly TO user1;

Errors​

ErrorCause
materialized view does not existView with specified name doesn't exist
column does not existColumn not found in the view
column is not a symbolIndex can only be added to SYMBOL columns
index already existsColumn is already indexed
permission deniedMissing ALTER MATERIALIZED VIEW permission (Enterprise)

See also​