我遇到了一些在INNODB MySql表中执行速度非常慢的SQL查询的问题。只有32,000行,并且where子句中的所有条件都被索引,并且位或bigints。我根本不会想到速度问题,但有时候查询需要2分钟才能完成。由于缓存很难判断,但如果我从查询中删除除id之外的所有选择条件,那么查询将在几毫秒内执行。
这些行很大,因为它们存储电子邮件html,因此通常一行是1MB。当查询运行时,计算机使用大量的硬盘资源,这似乎是速度减慢的源头。据我所知,虽然添加选择条件时数据库不需要使用任何其他资源,但首先它会找到行,然后它会为这些行提取所需的信息。如果我错了,有人可以纠正我,或者让我知道是否有其他设置可以解释这种行为。
这里要求的是查询:
选择aplosemail0_.id为id4353_,aplosemail0_.active为active4353_,aplosemail0_.deletable为deletable4353_,aplosemail0_.editable为editable4353_,aplosemail0_.persistentData为persiste5_4353_,aplosemail0_.dateCreated为dateCrea6_4353_,aplosemail0_.dateInactivated为dateInac7_4353_,aplosemail0_.dateLastModified as dateLast8_4353_,aplosemail0_.displayId如displayId4353_,aplosemail0_.owner_id如owner37_4353_,aplosemail0_.userIdCreated如userIdC10_4353_,aplosemail0_.userIdInactivated如userIdI11_4353_,aplosemail0_.userIdLastModified如userIdL12_4353_,aplosemail0_.parentWebsite_id如parentW38_4353_,aplosemail0_.automaticSendDate如automat13_4353_,aplosemail0_.emailFrame_id如emailFrame39_4353_, aplosemail0_.emailGenerationType为emailGe14_4353_,aplosemail0_.email_generator_type为email15_4353_,aplosemail0_.email_generator_id为email16_4353_,aplosemail0_.emailReadDate为emailRe17_4353_,aplosemail0_.emailSentCount为emailSe18_4353_,aplosemail0_.emailS entDate如emailSe19_4353_,aplosemail0_.emailStatus如emailSt20_4353_,aplosemail0_.emailTemplate_id如emailTe40_4353_,aplosemail0_.emailType如emailType4353_,aplosemail0_.encryptionSalt如encrypt22_4353_,aplosemail0_.forwardedEmail_id如forward41_4353_,aplosemail0_.fromAddress如fromAdd23_4353_,aplosemail0_.hardDeleteDate如hardDel24_4353_,aplosemail0_.htmlBody如htmlBody4353_,aplosemail0_.incomingReadRetryCount如incomin26_4353_,aplosemail0_.isAskingForReceipt如isAskin27_4353_,aplosemail0_.isIncomingEmailDeleted如isIncom28_4353_,aplosemail0_.isSendingPlainText如isSendi29_4353_,aplosemail0_.isUsingEmailSourceAsOwner如isUsing30_4353_,aplosemail0_.mailServerSettings_id如mailSer42_4353_,aplosemail0_.maxSendQuantity如maxSend31_4353_,aplosemail0_.originalEmail_id如origina43_4353_, aplosemail0_.outerEmailFrame_id为outerEm44_4353_,aplosemail0_.plainTextBody为plainTe32_4353_,aplosemail0_.removeDuplicateToAddresses为removeD33_4353_,aplosemail0_.re pliedEmail_id as replied45_4353_,aplosemail0_.sendStartIdx as sendSta34_4353_,aplosemail0_.subject as subject4353_,aplosemail0_.uid as uid4353_来自AplosEmail aplosemail0_其中aplosemail0_.emailType = 0和aplosemail0_.emailStatus<> 2和aplosemail0_.mailServerSettings_id = 7和aplosemail0_.active = 1按aplosemail0_.id排序DESC限制50