[英]Order by takes forever for one column
I'm using MySql. 我正在使用MySql。 I got to simplify a query. 我必须简化查询。 The (query is just for understanding) original is as bellow: (查询只是为了了解)原始信息如下:
SELECT id from (SELECT id FROM table ORDER BY C1, C2) ORDER BY C1
This one works fine, takes few seconds. 这一个工作正常,需要几秒钟。
And the simplified version should be: 简化版本应为:
SELECT id FROM table ORDER BY C1
But the second query is taking time forever for a large table. 但是第二个查询将花费大量时间永久用于大型表。 Both C1 and C2 are indexed separately. C1和C2都分别索引。
Please help, 请帮忙,
Show index results 显示索引结果
Primary id 4312718 candidates 主要ID 4312718候选人
C1 130688 candidates C1 130688候选人
C2 22 candidates C2 22名候选人
That is an expected result for large tables. 这是大型表的预期结果。 Try using LIMIT 100;
尝试使用LIMIT 100;
or whatever You need. 或您需要的任何东西。
在MysqL Workbench mysql.com/products/workbench或类似的GUI DB实用程序中运行EXPLIAN,因为它们可以提供很多更好的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.