- Documentation
RDS for PostgreSQL
User guide
Extensions
Intelligent index recommendation (index_advisor)
Extensions
Intelligent index recommendation (index_advisor)
Intelligent index recommendation (index_advisor)
Introduction and applicable scenarios
index_advisor is a practical PostgreSQL extension that automatically analyzes given SQL queries and recommends optimal indexes to improve query performance. This extension generates specific index creation suggestions by internally using hypopg to create hypothetical indexes and evaluate their impact on query plans.
Typical applicable scenarios include:
- SQL tuning: use it to quickly retrieve index optimization suggestions for a slow query.
- Development phase: assist developers in designing reasonable index strategies for complex queries in new features during development.
- hypopg dependency: index_advisor's functionality fully depends on the hypopg extension. When installing index_advisor, ensure that hypopg is also installed and enabled.
- Index type limitation: currently, index_advisor only supports recommending single-column B-tree indexes. It cannot provide suggestions for multi-column indexes or other types of indexes.
- Parameterized query: when analyzing prepared statements containing parameters (such as $1, $2), if the extension cannot automatically infer the data type of the parameter, you may need to explicitly add type conversion for parameters in the query string, such as ... WHERE user_id = $1::integer.
Create and delete extension
Execute the CREATE EXTENSION command to install index_advisor. Using the CASCADE clause ensures its dependent hypopg extension is also installed automatically.
Execute the following command to delete the extension.
warning
Uninstalling index_advisor will not automatically uninstall hypopg. If hypopg is no longer needed, it must be uninstalled separately.
The core function of index_advisor is provided through the index_advisor() function. This function accepts a SQL query string as input and returns one or more index creation suggestions.
index_advisor(sql_query TEXT)
- Recommend an index for a simple query
- Analyze a query with a WHERE condition.
- Recommend indexes for parameterized queries
- Analyze a query using placeholders.
- Recommend indexes for complex JOIN queries
- The index_advisor can also handle complex queries with multi-table joins.
Last updated: 2026.05.09 16:35:06