Make WordPress Core

Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#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: deepakrohilla's profile deepakrohilla Owned by: deepakrohilla's profile deepakrohilla
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)

Screenshot from 2025-01-03 1.zip (62.7 KB) - added by deepakrohilla 4 months ago.
Screenshot from 2025-01-03 12-26-48.png (33.8 KB) - added by deepakrohilla 4 months ago.
Screenshot from 2025-01-03 11-17-58.png (33.8 KB) - added by deepakrohilla 4 months ago.

Download all attachments as: .zip

Change History (9)

#1 @mukesh27
4 months ago

  • Component changed from Query to Database
  • Keywords needs-patch added; has-patch removed
  • Type changed from defect (bug) to enhancement

Thanks @deepakrohilla for the ticket!

Could you please share performance numbers before/after the changes with posts(10/100/1000)?

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 @mukesh27
4 months ago

In #39242, It add the caching to count_user_posts() that also help to improve the performance.

#4 @deepakrohilla
4 months ago

@mukesh27: https://ibb.co/q0scX1c .yes thanks for sharing #39242 this, it will help to improve performance of count query.

Last edited 4 months ago by deepakrohilla (previous) (diff)

#5 @swissspidy
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from assigned to closed

Duplicate of #39242.

Let‘s close this as a duplicate then :-) This can be tackled in the same ticket.

@narenin commented on PR #8081:


4 months ago
#6

@deepakrohillas Good catch! PR looks good to me.

Note: See TracTickets for help on using tickets.