Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨我有一个主要的表:
PRIMARY KEY(`x`,`y`,`Version`,`Revision`)
在桌子上像:
`x`,`y,`version`,`revision`,`data`
x, y,version并且revision都从零开始计数。
x
y
version
revision
我试图弄清楚如何返回最高revision和它data的每一个version,给定一个特定的x和y。我可以制作哪些索引来加快速度?
data
试试这个查询 -
SELECT t1.* FROM table t1 JOIN (SELECT Version, MAX(Revision) Revision FROM table GROUP BY Version) t2 ON t1.Version = t2.Version AND t1.Revision = t2.Revision
...为了加快查询速度,您可以在 Version 和 Revision 字段上添加索引。无论如何-您应该使用EXPAIN SELECT...语句对其进行分析。
EXPAIN SELECT...