慢sql top 10,缺少索引,
2.解决方案: 在晚上业务使用量少的时候创建
- 建议在数据表 irobotbox_amazonphoenix.Apx_BasicPlan_LogDetail 的 Status,ExecuteType,PlanType,CustomerId,ExecuteGuid 列上添加如下索引,以提高查询性能:
ALTER TABLE `irobotbox_amazonphoenix`.`Apx_BasicPlan_LogDetail` ADD INDEX `idx_Status_ExecuteType_PlanType_CustomerId_ExecuteGuid` (`Status`, `ExecuteType`, `PlanType`, `CustomerId`, `ExecuteGuid`)
注意:在业务高峰期,变更表结构存在风险,请谨慎操作!
2. in子查询的创建临时表tableB并建主键索引
select a.* from tableA a
inner join (select id from tableB)b on a. id=b. id
3.SQL
SELECT `PlanId` AS `PlanId`, `DeleteCheckId` AS `DeleteCheckId`, `ExecuteGuid` AS `ExecuteGuid`, `CustomerId` AS `CustomerId`, `Id` AS `Id`
, 2 AS `Status`
FROM `Apx_BasicPlan_LogDetail`
WHERE `CustomerId` = 1
AND `PlanType` = 4
AND `ExecuteType` = 5
AND `Status` = 1
AND `ExecuteGuid` IN (5251071350292080723, 5495536287884756395, 4937525211672912130, 5364869225245820723, 4774969505588427379, 4621701753346737921, 5050222109998904667, 5682727289690300273, 5678728941297165975, 4853967316592933963, 5636815260219718552, 4789935968247896952, 5258709543538120288, 5689006295504019742, 5200255073290623956, 4795608454398589964, 5500567425647753467, 5304568130967420949, 4794141700010067268, 5127198884045478821, 5124593846858805850, 5051842961885785660, 4822257545049454202, 5059073330550432063, 4786302550542665036, 5653312715074082025, 4739469841965865648, 5077295548714059965, 4827986757462203836, 5644917772769090855, 4772721477731310033, 4780676974461723281, 5460690825256837768, 4983884847213063422, 4663674243463803251, 5565061417339880086, 5538420364472876066, 5362842495418642949, 5113454374667978380, 4800134306582998600, 5271706525943657423, 4967530050294115471, 5423937328267093202, 5097304059590173860, 5491008316664732647, 5576442902162342683, 5318399635288230082, 5437475764740223492, 5094289519732306721, 4890431955756612080, 5637530524264662877, 5377017646571433400, 5340070394308221095, 4862016938164455288, 4690274969739815458, 5563996328723156639, 5495748464443266691, 5044875667978090741, 5070245142464896050, 5364403711044322244, 5172067919107163423, 5197367373103974892, 5406386865256065544, 5674651150796608088, 5679132701192153106, 4900979784583031473, 4932157839240669135, 5086126610842914693, 4741681645749881610, 5027338429359613710, 5182491722925333220, 5764423813745752022, 5577163542011758450, 5474939072293120835, 5713052406567886183, 5187142260724833536, 4634450757887185752, 4851665945439598217, 4995142873520426140, 4893771929076550211, 5020384387025459762, 5220599061831083475, 4877876628574818208, 5259185944920009622, 5476786431428554969, 5467296533779414594, 5592342945995308338, 5337314256630240424, 4802743556994568477, 5475848972945819895, 5180976935779956645, 4820157538665956257, 5398430921920120087, 5486694176772888596, 5318944436993668043, 5518790707385694723, 5192517158937061189, 5106361665738799331, 4656587711102746068, 5122361943833325537, 5432425460078759265, 5562739753112136994, 5679924626412377089, 5287965990512099222, 5141924976714212520, 4697296840780036332, 4861888386852283263, 5422475499147649456, 4680280239768189248, 5433287120022550536, 5016802746052038975, 4769954631747072978, 5406824138896285341, 4928160792558245758, 4811059886584068771, 5395664608710261613, 4801107768059521429, 5243808039611117648, 4777628867886535487, 5445865599606358626, 4975389007460954327, 5043915736093399879, 5027612714200181911, 5757653964678202085, 5425748353848052540, 5561182956083818647, 5322453315139828616, 4645680948091093907, 5010113237028407938, 5107712354583966937, 4870408896134652439, 5599494787735408031, 5178343809380838089, 5352915968506606445, 5482037092028388254, 5254333610830759258, 4800795500184881840, 5536507710566685550, 5527232868995501146, 4878871681416591235, 5258200094337399137, 5676092836140696765, 5201326977726745636, 4683716125338774415, 5261797684999846992, 4742180289097447703, 5422710161216967116, 5230654389613018211, 5317274965233806138, 5318657328781937074, 5553673729242552964, 4898856800194880408, 5303424865100671408, 5084687387846956037, 5237162908782912145, 4902465985538662396, 4882848641877442185, 5456465466646914721, 5624116194444996303, 5265237230523705189, 4665145140561071055, 5190660779595547514, 5244173881085480181, 5505133705371416190, 5574890845334940856, 4904849382498661624, 5352333092621530878, 5374648840152064048, 5627630753968110191, 5065513900103273482, 5523268614836607576, 5257803562488672068, 4913564651916770639, 5708672943948646667, 5477261716147423100, 5475722721451156556, 5046830370179020763, 5439737542518380341, 5399896648426449900, 4787995682831799811, 5011956766653746444, 5089042613242855242, 5148404089139693524, 4939660856630442351, 5753736658072542005, 4632728279616995267, 5363031033677151317, 5153239826397241118, 4933959346352944865, 5117352219168215959, 5344385889111563542, 5500942996030374433, 5008983328421165779, 5657447584535709990, 4727536166542155630, 4868407246701958580, 5135281408562840921, 4684094227166261069, 4875288281055514233, 5588720916037294024)
原SQL执行时间:
改后SQL执行时间: