Would it be safe to add indexes to wp_posts manually?

[ad_1]

I notice in my slow query log I have many calls like so:

SELECT post_date_gmt FROM wp_posts WHERE post_status = ‘publish’ AND post_type IN (‘post’, ‘page’, ‘attachment’, ‘qwerty’, ‘xyz’, ‘abc’) ORDER BY post_date_gmt DESC LIMIT 1;

and

SELECT post_modified_gmt FROM wp_posts WHERE post_status = ‘publish’ AND post_type IN (‘post’, ‘page’, ‘attachment’, ‘qwerty’, ‘xyz’, ‘abc’) ORDER BY post_modified_gmt DESC LIMIT 1;

I notice wp_posts does not have an index on `post_date_gmt ` nor `post_modified_gmt`

Generally speaking, would it be safe to add an index here, and worst comes to worst I can just delete it if it negatively affects anything?

[ad_2]
2 Comments
  1. I added the index on a cloned database and ran the same queries.

    Went from 1.5s to 0.005 (give or take). So definitely improves the speed.

    Just worried on a live site, more users doing more things, unforeseen things may explode

    I’m just leery touching such an important core WP table

  2. what is calling that query? it’s the post_type IN array that gets me. that doesn’t seem like a frontend function.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer