简体   繁体   中英

Why is this MySQL select query slowing things down?

I have this query:

"SELECT * FROM forum_posts WHERE post_deleted='0'"

I can see via New Relic that it's eating up 60% of my MySQL resources, and therefore slowing down my entire website.

I have no idea why such a simple query would slow anything down? My table is an InnoDB table, with index on "id".

  • Create index on post_deleted
  • Verify that post_deleted is of type boolean (tinyint, smallint, or even integer will outperform string)
  • Don't compare against the string '0' but against the number 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM