Support » Everything else WordPress » about query optimization

  • Resolved RL

    (@yofazza)


    Hello,

    I see in wp_post2cat that category_id is not indexed. It is indexed but after post_id. I believe queries like "SELECT post_id FROM wp_post2cat WHERE category_id = 5" will not get any advantage from the index? (am I wrong?)

    I have a feeling that I’m missing something. Can you guys tell me (the right way on) how to retrieve posts from a certain category manually? I need to do it in a page of mine, outside wordpress. Not using RSS because I need all of the posts (or is there a way to use RSS to get all posts?).

    Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • No, you’re NOT wrong. This appears to go back all the way to WP 1.5x and looking at the source of WP 2.04 it appears that only the admin function wp_dropdown_cats() will benefit from the added index and that’s probably the reason it wasn’t implemented.

    Your SQL syntax above IS correct and you should modify the “post2cat” table:

    alter table wp_post2cat add index category_id (category_id);

    Thread Starter RL

    (@yofazza)

    Thank you,

    alter table wp_post2cat add index category_id (category_id);

    I’ll do that.

    But btw, does WP (default install) really look into the whole row in wp_post2cat, when it wants to retrieve posts from just a single category? Is there a reason for this? I mean, it’s hard to believe that no one in the development team realize this “problem”. That’s why I think there might be some kind of “unusual” way in WP’s core to retrieve posts by category, efficiently.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘about query optimization’ is closed to new replies.