#62774 closed enhancement (duplicate)
The query in the count_user_posts function within wp-includes/user.php can be optimized to improve performance.
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Database | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
Since the wp_posts table's ID column is indexed (as it is the primary key and has a dedicated index), using COUNT(ID) will be faster than COUNT(*) because MySQL can leverage the index for efficient counting. In InnoDB tables, COUNT(*) often requires a full table scan or index traversal since InnoDB does not maintain an exact row count. Therefore, replacing COUNT(*) with COUNT(ID) can improve query performance.
Attachments (3)
Change History (9)
#1
@
4 months ago
- Component changed from Query to Database
- Keywords needs-patch added; has-patch removed
- Type changed from defect (bug) to enhancement
This ticket was mentioned in PR #8081 on WordPress/wordpress-develop by @deepakrohilla.
4 months ago
#2
- Keywords has-patch added; needs-patch removed
#3
@
4 months ago
In #39242, It add the caching to count_user_posts()
that also help to improve the performance.
#4
@
4 months ago
@mukesh27: .yes thanks for sharing #39242 this, it will help to improve performance of count query.
Note: See
TracTickets for help on using
tickets.
Thanks @deepakrohilla for the ticket!
Could you please share performance numbers before/after the changes with posts(10/100/1000)?