我正在执行一个查询,如下所示。现在的问题是限制增加执行时间。
我正在使用PHP脚本添加限制。所以,有人建议停止增加mysql的执行时间吗?
总共有12042993份记录,我得把它从一张表复制到另一张桌子。但是当我不受限制地执行单个查询时,它就不能工作了。
那么,请您提出一个更好的方法,以避免这种增长的时间?
现在,我增加了一个指数,如下所示。我知道这是错误的。但对我来说,我只需要专注于这个查询。在整个服务器/数据库上没有任何其他查询正在运行。
alter table cdrs add index cdrs_data (`callstart`,`uniqueid`,`accountid`,
`type`,`callerid`,`sip_from_uri`,`callednum`,`billseconds`,trunk_id,disposition,
debit,cost,provider_id,pricelist_id, package_id,pattern,notes,reseller_id,
provider_call_cost, call_direction,calltype,progress_media_stamp,
progress_mediamsec, is_recording,call_reward_amount);
insert into cdrs_data(uniqueid,accountid,type,callerid,sip_from_uri,callednum,
billseconds,trunk_id,disposition,callstart,debit,cost,provider_id,pricelist_id,
package_id,pattern,notes,reseller_id,provider_call_cost,call_direction,
calltype,progress_media_stamp,progress_mediamsec,is_recording,call_reward_amount)
select uniqueid,accountid,type,callerid, sip_from_uri, callednum,billseconds,
trunk_id,disposition, callstart,debit,cost, provider_id,pricelist_id,package_id,
pattern,notes,reseller_id,provider_call_cost, call_direction,calltype,
progress_media_stamp,progress_mediamsec, is_recording,call_reward_amount
from callinfo
where callstart >= '2017-01-30 00:00:00' and callstart < '2019-05-06 00:00:00'
order by callstart asc limit 24000,3000所有的建议都被采纳了。
发布于 2019-05-11 16:33:34
您要传输的1200万行中的百分比是多少?
随着OFFSET的增加,这会变得越来越慢:
limit 24000,3000相反,“记住你停下来的地方”。更多:http://mysql.rjweb.org/doc.php/pagination和http://mysql.rjweb.org/doc.php/deletebig#deleting_在……里面_分块
callstart上有索引吗?
INDEX cdrs_data是一个非常长的指数。唯一有用的方法是,如果它是“覆盖”的话。
TABLE cdrs_data --它有索引吗?其中,在启动插入之前禁用索引可能会加快速度。之后再重新启用。
另一个选项是使用带有--where子句的mysqldump。用于转储端;然后是mysql,用于在新位置加载。
https://dba.stackexchange.com/questions/237897
复制相似问题