如果我有复合唯一约束,是否仍需要显式创建复合索引

时间:2014-03-28 16:30:22

标签: sqlite

我有一个具有唯一约束的表

create table if not exists watchlist(
    _id integer primary key autoincrement, 
    country text not null, 
    name text not null, 
    unique (country, name) on conflict replace
);

由于我的查询大部分时间都会在WHERE子句中涉及countryname。为了加快查询速度,我想知道我还需要创建

create index idx_country_name on watchlist(country, name);

1 个答案:

答案 0 :(得分:1)

您的唯一约束将创建一个隐式索引,该索引将由sqlite自动创建。因此,无需在这些列上创建唯一索引。