Hubro
Hubro

Reputation: 59408

Does an UNIQUE constraint remove the need for an explicit index in Sqlite?

There are some columns that I wish to create indexes for to improve look-up and sorting speeds. If that column is marked as UNIQUE, for instance:

CREATE TABLE "foo" (
    "bar" TEXT NOT NULL UNIQUE
)

is the column "bar" now indexed in such a way that this:

CREATE INDEX foo_bar ON foo(bar)

will provide no speed bonus for searches and sorts?

Upvotes: 30

Views: 4213

Answers (1)

CL.
CL.

Reputation: 180290

UNIQUE and PRIMARY KEY constraints indeed create an internal index to speed up their lookups, so you do not need to create your own.
(see the documentation)

Upvotes: 27

Related Questions