例如,这是一个示例表
id int PK,
pid int,
cid int,
deleted int,
createdAt timestamp,
UNIQUE KEY pid_cid(pid, cid)
Run Code Online (Sandbox Code Playgroud)
使用的 WHERE 子句是
where pid=$pid and cid=$cid [and deleted = 1];
where pid=$pid [and deleted = 1];
where cid=$pid [and deleted = 1];
Run Code Online (Sandbox Code Playgroud)
既然我已经索引了UNIQUE KEY pid_cid(pid, cid),我应该分别索引 pid 和 cid 吗?
还是选择 aindex pid比选择a快UNIQUE KEY pid_cid(pid, cid)?