我正在尝试调整以下查询。
SELECT jsondata_c,
id_c
FROM accounts
LEFT JOIN accounts_cstm
ON accounts.id = accounts_cstm.id_c
WHERE ispropagated_c = 0
AND deleted=0
AND jsondata_c is not null
ORDER BY accounts.date_modified DESC LIMIT 5
其执行计划如下
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: accounts_cstm
partitions: NULL
type: ALL
possible_keys: PRIMARY,id_c
key: NULL
key_len: NULL
ref: NULL
rows: 1325982
filtered: 9.00
Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: accounts
partitions: NULL
type: eq_ref
possible_keys: PRIMARY,idx_accnt_id_del,idx_accnt_assigned_del
key: PRIMARY
key_len: 108
ref: oasyscrm.accounts_cstm.id_c
rows: 1
filtered: 50.00
Extra: Using where
2 rows in set, 1 warning (0.00 sec)
我不确定为什么查询使用filesort和temp而没有任何order by和group_cstm表的group by子句。 请建议调整此查询的方法,因为它需要大约1分钟才能执行。