【发布时间】:2016-06-25 05:12:18
【问题描述】:
给定一个有四列的表格
create table user
(
id int primary key,
username varchar(100),
age int,
country varchar(100)
);
最常见的查询是基于用户名、年龄和国家/地区的 where 子句。例如:
select *
from user
where username = "Join Smith" and age > 18 and country = "UK"
如何建立最有效的索引,为什么?
如果查询变为
select *
from user
where username like "John Smith" and age = 18 and country = "UK"
我将对所有三列用户名、年龄和国家/地区使用复合索引。但我不知道这对哪种情况最有效。请帮忙。
【问题讨论】:
-
这适用于哪个 RDBMS?请添加标签以指定您使用的是
mysql、postgresql、sql-server、oracle还是db2- 或其他完全不同的东西。