加速大表上的SELECT查询

时间:2016-11-29 13:59:24

标签: mysql sql

如何改善查询时间?我有一个用这些领域存钱的交易表:

id, customersId, paymentId, amount, cash, createDate

我的查询获取客户交易:

SELECT id,amount,cash,createDate
FROM customers_transactions
WHERE customersId = 2784

此表有1000万条以上的记录。查询大约需要13秒才能执行。

该表包含以下索引:

id, customersId (unique)
customersId, createDate (unique)

这些分区:

10 partiotions By RANGE on customersId
LESS THAN 1000
LESS THAN 2000
LESS THAN 3000
LESS THAN 4000
LESS THAN 5000
LESS THAN 6000
LESS THAN 7000
LESS THAN 8000
LESS THAN 9000
LESS THAN 10000

服务器有8 GB RAM,CORE i5 3.2GHz

我希望运行此查询少于0.5秒

1 个答案:

答案 0 :(得分:0)

摆脱分区,除非你需要其他东西。

我们可以创建覆盖索引(索引包含所有需要的列),但这是一种过度杀伤。

另外 -
将Id设为主键并抛出id, customersId (unique)

P.S。
你为什么createDatecustomersId, createDate (unique)

相关问题