#3083 closed defect (bug) (fixed)
Voice counter not optimized properly
Reported by: | januzi_pl | Owned by: | netweb |
---|---|---|---|
Milestone: | 2.6 | Priority: | highest omg sweet tea |
Severity: | critical | Version: | 2.5.12 |
Component: | Component - Replies | Keywords: | has-patch |
Cc: |
Description
Hello
So, every time when somebody adds reply to the topic, the bbpress voice counter runs query:
SELECT COUNT( DISTINCT post_author ) FROM wp_posts WHERE ( post_parent = 121646 AND post_status = 'publish' AND post_type = 'reply' ) OR ( ID = 121646 AND post_type = 'topic' );
which leads to the:
# Query_time: 74.156613 Lock_time: 0.000067 Rows_sent: 1 Rows_examined: 4156148
(Yes, 4 million records).
How to fix it:
Split query into two different ones, or use union. Here's explain for single queries:
select DISTINCT post_author FROM wp_posts WHERE ( ID = 121646 AND post_type = 'topic' ) type=const, key=PRIMARY, rows=1 SELECT DISTINCT post_author FROM wp_posts WHERE ( post_parent = 121646 AND post_status = 'publish' AND post_type = 'reply' ) type=ref, key=post_parent, rows=5
As for union this would return proper amount of distinct authors without the need to filter whole wp_posts table:
select count( distinct( post_author ) ) from ( select post_author FROM wp_posts WHERE ( ID = 121646 AND post_type = 'topic' ) union SELECT post_author FROM wp_posts WHERE ( post_parent = 121646 AND post_status = 'publish' AND post_type = 'reply' ) ) as u1
(0.0007 - 0.0010 sec)
Attachments (1)
Change History (6)
#2
@
8 years ago
Hello,
I need one Help. How to fix this error?
This is My current Website : http://indianengineers.com/ Developed using by MyBB.
Now I am moved to New Theme. ( under Construction URL is : ) http://indian.dubaishoppingmalls.com/
I want Move Current Website Datas ( user details, forums Articles and etc ) move to new theme BuddyPress. That has an option to import MYBB Database.
When I try it Shows Error like
Repair any missing information: Continue
No reply_to parents to convert
No replies to convert
No tags to convert
No super stickies to stick
No stickies to stick
No stickies to stick
#4
@
8 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 2.6
- Owner set to netweb
Assigning to @netweb to look into whether UNION
queries are safe for:
- Supported MySQL versions
- Supported MySQLi versions
- Supported MariaDB versions (probably same as MySQL)
- HyperDB and other WPDB drop-ins (LudicrousDB, etc...)
I believe the attached patch is A-OK, but because nothing in core uses UNION
style queries for anything, I'm reluctant to commit this right away.
wp-content/plugins/bbpress/includes/topics/functions.php
line 2610:
replace old query with the
And voila, done.