Suggest indexes for a SQL query

Suggest SQL indexes from filters, joins, sort keys, and selectivity.

freeworks offlinenothing uploaded
ToolSQL Index Suggester
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Query predicates, join keys, ordering, and selectivity hints are compared with existing indexes to suggest single or composite access paths. The suggestion does not run EXPLAIN or create an index.

  • B-tree covers common equality, range, and ordering.
  • Specialized types remain workload-dependent.

Worked example

Analyze Query for Indexes
Suggest indexes for a query filtering and sorting on multiple columns
Input
											SELECT * FROM products WHERE category = 'Electronics' AND price > 100 ORDER BY rating DESC
										
Output
												-- Index Suggestions
-- Analyzed query: SELECT * FROM products WHERE category = 'Electronics' AND price > 100 ORDER BY r...

-- Suggestion 1: Columns used in WHERE clause conditions
-- Table: products, Columns: category, price
CREATE INDEX idx_products_category_price ON products (category, price);

-- Suggestion 2: Columns used in ORDER BY clause
-- Table: products, Columns: rating
CREATE INDEX idx_products_rating ON products (rating);

											

When to use this

Endpoint tuning, migration reviews, and composite-query analysis suggest indexes.

Edge cases

  • Indexing every column slows writes and consumes storage.
  • Composite column order controls usable prefixes.
  • Low-selectivity boolean indexes may not improve a scan.

References