表A:
a_id(int), b_id(int), category(int), status(int)
表B:
b_id(int), rate(int)表A数据量几十万,表B数据量几百,现在要求两表联合查询 A.category = [一个整数] A.status = [一个整数] 然后 ORDER BY B.rate DESC 最后要求提取前N个结果,要求能尽可能快的返回结果,请问这样的多表联合查询的索引该如何建?同时SQL语句要怎么写呢?谢谢了!
a_id(int), b_id(int), category(int), status(int)
表B:
b_id(int), rate(int)表A数据量几十万,表B数据量几百,现在要求两表联合查询 A.category = [一个整数] A.status = [一个整数] 然后 ORDER BY B.rate DESC 最后要求提取前N个结果,要求能尽可能快的返回结果,请问这样的多表联合查询的索引该如何建?同时SQL语句要怎么写呢?谢谢了!
from a inner join b on a.b_id=b.b_id
where a.category=123
and a.status=456
order by b.rate
limit 100create index xxx on a(category,status)
create index xxx2 on a(b_id)