CodeBlanks Logo Icon CodeBlanks

Search index

Speed up search with CREATE INDEX.

Search index

To speed up title search you add an index on the title column.

CREATE INDEX idx_title ON posts (title);

This query speeds up title searches.

The index idx_title is created.

Search index — details

An index speeds up search queries. It goes on frequently searched columns.

For example, WHERE title LIKE 'SQL%' benefits from an index on title, but searches starting with a wildcard such as '%SQL%' can't use it.

Practice Search index

Add an idx_title index on title of posts.

Starter code

query.sql
-- title index
CREATE INDEX

Sample solution

query.sql
CREATE INDEX idx_title ON posts (title);

Expected output

İndeks oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Add CREATE INDEX

Question
CREATE ____ idx_title ON posts (title);
Answer
CREATE INDEX idx_title ON posts (title);

Explanation: An index on title speeds up searches by title.

2 What does an index speed up?

  • Creating tables
  • Searches Correct answer
  • Deletes
  • Backup

Explanation: An index speeds up searches.

3 Search index: match the terms

Term Meaning
CREATE INDEX create
title title
search fast
frequent index

All lessons in Intermediate