Title: about query optimization
Last modified: August 18, 2016

---

# about query optimization

 *  Resolved [RL](https://wordpress.org/support/users/yofazza/)
 * (@yofazza)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/about-query-optimization/)
 * 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)

 *  [Pizdin Dim](https://wordpress.org/support/users/pizdin_dim/)
 * (@pizdin_dim)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/about-query-optimization/#post-459299)
 * 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](https://wordpress.org/support/users/yofazza/)
 * (@yofazza)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/about-query-optimization/#post-459458)
 * 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.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [index](https://wordpress.org/support/topic-tag/index/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 2 replies
 * 2 participants
 * Last reply from: [RL](https://wordpress.org/support/users/yofazza/)
 * Last activity: [19 years, 8 months ago](https://wordpress.org/support/topic/about-query-optimization/#post-459458)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
