Ticket #2604 (closed defect (bug): fixed)

Opened 6 years ago

Last modified 5 years ago

SQL Query Optimization

Reported by: ryan Owned by: ryan
Priority: normal Milestone: 2.1
Component: Administration Version: 2.0.2
Severity: normal Keywords: sql db performance
Cc:

Description

Improvements suggested by Domas Mituzas.

 http://dammit.lt/2006/03/25/wordpress-sql-query-review/

Attachments

sql_chat.txt Download (23.8 KB) - added by ryan 6 years ago.
Chat with Domas on #wordpress-dev
remove_distinct.diff Download (1.7 KB) - added by ryan 6 years ago.
Remove DISTINCT from main post query
remove_distinct_groupby.diff Download (3.1 KB) - added by ryan 6 years ago.
Remove DISTINCT and GROUP BY
type_status_date_key.diff Download (4.7 KB) - added by ryan 6 years ago.
Add (post_type, post_status, post_date) key and shorten post_type

Change History

comment:2   ryan6 years ago

Attached IRC log of chat with Domas on #wordpress-dev.

ryan6 years ago

Chat with Domas on #wordpress-dev

ryan6 years ago

Remove DISTINCT from main post query

comment:3   ryan6 years ago

Removing DISTINCT from the main post query resulted in a 6% performance improvement over current trunk. Benchmarked 500 requests using apache bench. The exact same front page was used for each run. Document length was 22205 bytes. This is with the default theme and the default install options. Imported the same 225 posts for each to prime the test with some realistic blog posts.

ryan6 years ago

Remove DISTINCT and GROUP BY

comment:4   ryan6 years ago

Removing DISTINCT and GROUP BY gives a 10% performance increase over baseline. Same test environment.

ryan6 years ago

Add (post_type, post_status, post_date) key and shorten post_type

comment:5   ryan6 years ago

Added composite key (post_type, post_status, post_date) and shortened post_type from 100 to 20. Didn't make a difference to performance.

comment:6   ryan6 years ago

[3678]

Let's try these on.

comment:7   ryan6 years ago

Just to note, we've already removed timestamps from queries and only check for a post_status of publish in the main post query. No more checks for static.

comment:8   ryan6 years ago

these two queries:
                    66 Query     SELECT * FROM wp_categories WHERE cat_ID > 0 HAVING category_count > 0 ORDER BY cat_name asc
                    66 Query     SELECT * FROM wp_categories WHERE cat_ID > 0 HAVING link_count > 0 ORDER BY cat_name ASC
could possibly be rewritten into link_count>0 or category_count>0

Anyone want to tackle this part? Eliminate "HAVING". Look in get_categories().

Replacing HAVING with AND works fine for me and should be less costly!

  • Status changed from new to closed
  • Resolution set to fixed

These are all done now, I believe.

Note: See TracTickets for help on using tickets.