感谢, 暂时无法提供了, 因为我目前通过global binding算是稳定住了线上吧(不过不敢保证以后没有问题), 所以现在有binding的情况找了几个sql执行计划都是对的, 现在线上在跑, 我也不敢删binding去做测试. 等有机会我再提供吧
14:38:04 [db]> show global bindings\G
*************************** 1. row ***************************
Original_sql: select count ( ? ) as `num` , `ifnull` ( sum ( `amount` ) , ? ) as `sum_amount` from `db` . `T1` where ( `c1` = ? and `c2` in ( ... ) and `c3` in ( ... ) and `c4` >= ? and `c4` <= ? )
Bind_sql: SELECT /*+ USE_INDEX(`T1` `id3`, `idx4`)*/ COUNT(1) AS `num`,IFNULL(SUM(`amount`), 0) AS `sum_amount` FROM `db`.`T1` WHERE (`c1` = 1 AND `c2` IN ('537575323462586369','537678695138119693','537828424752869376','537819286719221762','537836464424140806','537836464424140808','537837753023377408','537836464424140810','537836464424140812','537837753023377410','537836464424140814','537842880232861698','537842880232861710','537849368728879104','537854992422322176','537854992422322186','537849368728879114','538026973843214342','538026973843214344','538049076822855686','538100342286499852','538100342286499854','538100342957584386','538100342957584388','538121636163928064','538100342957584390','538100342957584392','538121636163928066','538100342957584394','538121636163928068','538100342957584396','538129792327790602','538132036779552768','538129792327790604','538129792327790606','538132036779552772','538132036779552774','538158899547648000','538132036779552776','538158899547648002','538158899547648010','538158899547648012','538132036779552781','538132036779552783','538158899547648014','538179862163148802','538186833616486400','538186833616486406','538179862163148804','538179862163148806','538186833616486408','538186833616486410','538179862163148808','538186833616486412','538179862163148810','538179862163148812','538770198568677382') AND `c3` IN (11001,11002,11003) AND `c4` >= '2021-05-28 00:00:00' AND `c4` <= '2021-05-28 23:59:59')
Default_db: db
Status: using
Create_time: 2021-05-31 15:10:30.534
Update_time: 2021-05-31 15:10:30.534
Charset: utf8
Collation: utf8_general_ci
Source: manual
*************************** 2. row ***************************
Original_sql: select `id` from `db` . `T1` where ( `c1` = ? and `c2` in ( ... ) and `c3` in ( ? ) and `c4` >= ? and `c4` <= ? ) order by `c4` desc , `id` desc limit ...
Bind_sql: SELECT /*+ USE_INDEX(`T1` `id3`, `idx4`)*/ `id` FROM `db`.`T1` WHERE (`c1` = 1 AND `c2` IN ('524744873262649350','524744873262649351','524744873262649352','524744873262649355','524744873262649356','524744873262649357','524744873262649358','527165583977287681','527165583977287682','527165583977287691','527165583977287692','527165583977287693','527165583977287694','527231031330672642','527523339804127234','527523339804127245','527523339804127246','527541505372508164','527541505372508165','527588219076792321','527620307947663374','530441560127488001','530140433821929473','531261477290553358','531279080398565381','531553805662212098','531576527062618112','531976329306886145','530140433821929474','532327870802997259','530140433821929475','530140433821929476','532379041311801356','532798402140880897','532798402140880898','532798402140880911','533039270890356746','533039270890356747','533512397780987908','533691765295722511','533520792084856838','533520792084856839','533704061409607680','533520792084856840','533704061409607681','533704061409607682','533520792084856841','533520792084856842','533704061409607683','534072251893469193','534119072820940814','534119072820940815','534122654836248586','534122654836248587','534122654836248588','534197491936051200','534197491936051211','534197491936051212','534197554590560261','534197554590560262','534403836761133071','534422258198818830','534493896877588483','534477266449641477','534513460919189504','534515388759724037','534515388759724038','534582684018589703','534864371612954626','534886886355812361','534886886355812362','534886886355812363','534886886355812366','534886630582964232','534886630582964233','534886630582964234','534886886355812367','534896463428239360','534939570765090817','534939570765090818','534896463428239369','534939570765090819','534896463428239370','534896463428239371','534939570765090820','534896463428239372','534939570765090821','534939570765090822','534896463428239373','534939570765090823','534896463428239374','534939570765090824','535261710244691971','535249761104613387','535249761104613388','535261710244691978','535261710244691979','535261710244691980','535261710244691981','535249761104613389','535261710244691982','535261710244691983','535283930987810816','535284041545465856','535283930987810817','535283930987810818','535284041545465857','535284041545465858','535283930987810819','535283930987810820','535284041545465859','535283930987810821','535284041545465860','535283930987810822','535283930987810823','535284041545465861','535284041545465862','535283930987810824','535284041545465863','535283930987810825','535283930987810826','535284041545465864','535283930987810827','535284041545465865','535283930987810828','535283930987810829','535283930987810830','535299109783916545','535299109783916546','535299109783916549','535299109783916550','535331799484649485','535594485246115842','535600881513582596','535594485246115843','535600881513582597','535600881513582598','535594485246115844','535594485246115845','535594485246115846','535600881513582599','535594485246115847','535594485246115848','535594485246115849','535594485246115850','535600881513582600','535594485246115851','535600881513582601','535594485246115852','535600881513582602','535594485246115855','535634388642222092','535634388642222093','535634388642222094','535726561865805825','535726561865805826','535726561865805827','536230534603386890','536228231980826627','536230534603386891','536228231980826628','536228231980826629','536230534603386892','536230534603386895','536235238448218112','536228231980826636','536235238448218123','536235238448218124','536235238448218125','536228231980826637','536235238448218126','536235238448218127','536238157042073600','536228231980826638','536238157042073601','536238157042073602','536238157042073603','536240045338705921','536240045338705922','536240045338705923','536240045338705924','536240045338705925','536240045338705926','536238157042073606','536240045338705927','536240045338705928','536238157042073607','536240045338705929','536238157042073608','536238157042073609','536238157042073610','536240045338705932','536240045338705933','536238157042073611','536238157042073612','536246909279457292','536246909279457293','536247820642988033','536247820642988034','536247820642988037','536247820642988038','536247820642988039','536253817235230722','536253817235230723','536253817235230724','536260900907167750','536260900907167751','536260900907167752','536260900907167753','536260900907167754','536268883129053195','536268883129053196','536260900907167755','536268883129053197','536260900907167756','536268883129053198','536260900907167757','536260900907167758','536260900907167759','536291446391615488','536268883129053199','536292285332107264','536292285332107265','536292285332107266','536292285332107267','536291446391615489','536291446391615490','536291446391615491','536291446391615492','536292285332107268','536292285332107269','536291446391615493','536292285332107270','536292285332107271','536292285332107272','536292285332107273','536291446391615500','536664542357274632','536671706207531013','536671706207531014','536948282845347845','536993919926317059','536994122880307230','536994122880307231','537067667996065800','537067709888778244','537067709888778251','537068433003560963','537068520215719940','537068789376798724','537068789376798725','537068789376798730','537081801064099851','537081801257037833','537081801257037834','537099920625160198','537099920625160205','537100557152731138','537100695199854595','537100557152731145','537100695199854600','537100695199854605','537100557152731148','537101199032233990','537101449331527683','537101199032233993','537101449331527692','537232828312629257','537232828312629258','537232828312629259','537300875891232770','537301514830528512','537300875891232781','537301514830528517','537304437849374728','537305197425246215','537305197425246216','537307247773011970','537305197425246217','537307247773011971','537307247773011972','537318826329550860','537318826329550861','537318826329550862','537318825385840653','537318826329550863','537318825385840654','537321363262713856','537321363262713857','537321363262713858','537321363262713859','537318825385840655','537322364787019776','537321363262713870','537321363262713871','537322364787019777','537323081018945536','537323081018945537','537322364787019778','537322364787019779','537322364787019784','537322364787019785','537322364787019786','537322364787019787','537323081018945542','537323081018945547','537323081018945548','537322364787019788','537323081018945549','537322364787019789','537325617218109442','537323081018945550','537325617218109443','537325617218109444','537325617218109445','537325868402393089','537325868402393090','537325868402393091','537325868402393096','537325868402393097','537325617218109450','537325617218109451','537325868402393098','537325868402393099','537325868402393100','537327631092199424','537327631092199427','537327516805812229','537327631092199428','537327516805812230','537327631092199429','537327516805812231','537327516805812236','537327516805812237','537333687109341188','537333687788814338','537333687109341191','537333687788814339','537338201988190218','537390651810033678','537401397650440201','537401397650440202','537406455767158791','537406455767158792','537405079943163919','537410250601443328','537410250601443329','537406455767158793','537410250601443330','537406455767158794','537410250601443331','537406455767158795','537406455767158796','537410250601443332','537406455767158797','537410250601443333','537406455767158798','537406455767158799','537413539342635010','537413539342635011','537413836681031680','537413539342635012','537413539342635013','537413539342635014','537413539342635015','537413539342635016','537678695138119695','537678741778776069','537678741778776070','537693325419917322','537693325419917323','537693325419917324','537678741778776071','537693325419917325','537693325419917326','537693325419917327','537697163119996938','537678741778776072','537697163119996939','537697163119996940','537697163119996941','537678741778776073','537697163119996942','537697163119996943','537678741778776074','537700045730918400','538026973851598858','538026973851598859','538026973851598860','538026973851598861','538026973843214346','538026973851598862','538026973843214347','538026973851598863','538026973843214348','538049076822855680','538026973843214349','538026973843214350','538049076822855681','538026973843214351','538049076822855682','538049925200527360','538049925200527361','538049076822855683','538049076822855684','538049925200527362','538049925200527363','538049076822855685','538049925200527364','538049925200527371','538132036779552778','538158899547648004','538132036779552779','538158899547648005','538132036779552780','538158899547648006','538158899547648007','538158899547648008','538158899547648009','538179862163148801','538391285216628740','538391285216628741','538490384708321290','538491647369986052','538491647369986061','538490384708321293','538490384708321294','538491647369986062','538761504254640137','538491647369986063','538763038954668036','538762527283130378','538762527283130379','538762527283130380','538763038954668037','538770198568677384','538804791028011019','538804791028011020','538804791028011021','538804523506913289','538804791028011022','538804523506913290','538804523506913291','538804791028011023','538834084038758400','538834084038758401','538834084038758402','538834084038758403','538834084038758404','538804523506913292','538804523506913293','538834084038758405','538834084038758406','538836274144919556','538834084038758407','538836274144919565','538836631281520640') AND `c3` IN (110001) AND `c4` >= '2021-05-01 00:00:00' AND `c4` <= '2021-05-31 23:59:59') ORDER BY `c4` DESC,`id` DESC LIMIT 0,20
Default_db: db
Status: using
Create_time: 2021-05-31 17:07:55.722
Update_time: 2021-05-31 17:07:55.722
Charset: utf8
Collation: utf8_general_ci
Source: manual
*************************** 3. row ***************************
Original_sql: select `id` from `db` . `T1` where ( `c1` = ? and `c2` in ( ... ) and `c3` in ( ... ) and `c4` >= ? and `c4` <= ? ) order by `c4` desc , `id` desc limit ...
Bind_sql: SELECT /*+ USE_INDEX(`T1` `idx4`, `id3`)*/ `id` FROM `db`.`T1` WHERE (`c1` = 1 AND `c2` IN ('525853901912592392','525868485553737729','525868741431443470','525868485553737731','526081610638999561','526087495339786244','526081610638999563','526137642434220033','526087495339786246','526137642434220035','526137642434220037','526157855485636623','526184463487520778','526184463487520780','526190421022396417','526184463487520782','526257977791918080','526190421022396419','526257977791918082','526190421022396421','526190421022396423','526190421022396425','526190421022396427','526257977791918084','526190421022396429','526257977791918086','526190421022396431','526556472998412298','526554170656870409','526556472998412300','526554170656870411','526554170656870413','526556472998412302','526631532492804096','526796462714048526','526827932518240271','526871171593981961','526886266894073868','526886266894073870','526928734607945728','526938204977283077','526938204977283079','526928734607945730','526938204977283081','526928734607945732','526938204977283083','526938204977283085','526928734607945734','526928734607945736','526928734607945742','526988760324288519','527234268938682368','527238064167239686','527239855164403716','527239855164403718','527239855164403720','527254438843305986','527239855164403722','527239855164403724','527254438843305998','527294607592050696','527311181573042176','527311181573042178','527294607592050702','527376658060066816','527588220876144654','527615702492827658','527643814987354112','527633829649760259','527643814987354114','527643814987354120','527633829649760267','527693354390040584','527693354390040586','528060474986647553','527693354390040588','528060474986647555','527693354390040590','528060474986647557','528060474986647559','528060474986647567','528633260469698564','528633260469698566','528633260469698568','528759588942565377','528759588942565379','528805551996452866','528759588942565389','528805551996452872','528805551996452874','528814147077451783','528818023029587976','528814147077451789','528818023029587978','528814147077451791','529420794531467264','529420794531467266','529420794531467268','529420794531467270','529114963021713419') AND `c3` IN (11001,11002,11003) AND `c4` >= '2021-05-28 08:00:00' AND `c4` <= '2021-05-29 07:59:59') ORDER BY `c4` DESC,`id` DESC LIMIT 0,100
Default_db: db
Status: using
Create_time: 2021-05-31 15:23:44.424
Update_time: 2021-05-31 15:23:44.424
Charset: utf8
Collation: utf8_general_ci
Source: manual
3 rows in set (0.00 sec)
不过有个问题还想确认下
第二个binding Original_sql是
select `id` from `db` . `T1` where ( `c1` = ? and `c2` in ( ... ) and `c3` in ( ? ) and `c4` >= ? and `c4` <= ? ) order by `c4` desc , `id` desc limit ...
第三个binding Original_sql是
select `id` from `db` . `T1` where ( `c1` = ? and `c2` in ( ... ) and `c3` in ( ... ) and `c4` >= ? and `c4` <= ? ) order by `c4` desc , `id` desc limit ...
我注意到这两个sql一个c3 in 多值, 一个c3 in 单值, 所以这里Original_sql 一个为
`c3` in ( ? )
一个为
`c3` in ( ... )
请问 c3 in ( ? )
是否等于 c3 in ( ... )
?
就是说以下语句是否能够匹配第二个binding?
select `id` from `db` . `T1` where ( `c1` = 1 and `c2` in ( 1,2,3 ) and `c3` in ( 1,2,3 ) and `c4` >= ''2021-05-28 08:00:00'' and `c4` <= '2021-05-29 07:59:59' ) order by `c4` desc , `id` desc limit 0,20