我为Codeigniter写了一个带Temp表的查询。它返回近25000行。 但是当我在实时服务器上使用此查询时,它会丢失数据库连接。
这是我的查询:
SELECT temp.id office_id,
temp.office_name,
temp.svcic,
count(service_transaction.service_id) AS service_total
FROM (SELECT users.id, users.office_name, service_list.id svcic
FROM users,service_list
WHERE users.del_status = 0
AND users.type='agency'
AND service_list.del_status = 0
AND users.id != '-1' ) temp
LEFT JOIN service ON temp.id = service.office_id
AND service.del_status=0
AND (service.date
BETWEEN '2017-07-26'
AND '2017-08-26' )
LEFT JOIN service_transaction ON service_transaction.service_id = temp.svcic
AND service_transaction.service_transaction_id=service.id
LEFT JOIN recipient ON recipient.id =service.recipient_number
AND recipient.gender != 'all'
GROUP BY temp.id,
temp.office_name,
temp.svcic
ORDER BY temp.office_name
如何在不使用temp的情况下简化查询。我相信它发生在Temp表中。
答案 0 :(得分:0)
根据我的理解,其中一个原因可能是
innodb_buffer_pool_size可以设置为大于服务器上可用的RAM大小。修复可能是使用innodb_buffer_pool_size的正确设置更新my.cnf。