Make WordPress Core

Opened 2 months ago

Last modified 5 weeks ago

#59442 assigned defect (bug)

Duplicate query in WP_Query

Reported by: spacedmonkey's profile spacedmonkey Owned by: joemcgill's profile joemcgill
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.2
Component: Query Keywords: has-patch dev-feedback commit early
Focuses: performance Cc:

Description

When a site using a classic theme and has sticky posts, that can result in duplicate query. ( See attached screenshot ). This is because post_type variable passed the sticky sub query, is empty string on the first run. See the line. This results in different cache query key being generating, resulting in duplicate queries.

Steps to replicate.

  1. Set theme to 2016.
  2. Import theme data test data.
  3. Go to home page.
  4. Open query monitor, see duplicate query.

Attachments (2)

Screenshot 2023-09-25 at 12.26.09.png (362.9 KB) - added by spacedmonkey 2 months ago.
Screenshot 2023-09-25 at 12.33.38.png (499.7 KB) - added by spacedmonkey 2 months ago.

Download all attachments as: .zip

Change History (16)

This ticket was mentioned in PR #5295 on WordPress/wordpress-develop by @thekt12.


2 months ago
#1

  • Keywords has-patch added

This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.


2 months ago

#4 @spacedmonkey
2 months ago

  • Milestone changed from Awaiting Review to 6.4

#5 @hellofromTonya
2 months ago

  • Keywords dev-feedback added

As this is touching WP_Query, I'm thinking it needs to be an early candidate. Why? Touching it is risky. Committing early in the alpha cycle gives a long soak time for follow-ups, testing, and feedback. Touching it during the 6.4 Beta cycle makes me nervous.

@spacedmonkey is this fix critical for 6.4? What do you think of moving it to early 6.5?

This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.


2 months ago

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


2 months ago

#8 @thekt12
2 months ago

One of the main reason we get multiple queries for the same SQL is the hash takes serialised args as string for hashing, leading to a different key for even slightest of change in args.

I have documented it in ->
https://core.trac.wordpress.org/ticket/59492

Following PR, solves the current issue along with possibility of any more duplicates in different scenerio.
https://github.com/WordPress/wordpress-develop/pull/5347/files

#9 @swissspidy
8 weeks ago

  • Owner set to spacedmonkey
  • Status changed from new to assigned

#10 @thekt12
8 weeks ago

Sticking to the original problem, this PR https://github.com/WordPress/wordpress-develop/pull/5295 fixes the issue.

This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.


8 weeks ago

#12 @spacedmonkey
8 weeks ago

  • Keywords commit added

PR looks good to me. Marking as ready to commit.

#13 @spacedmonkey
8 weeks ago

  • Keywords early added
  • Milestone changed from 6.4 to 6.5
  • Owner changed from spacedmonkey to joemcgill

Based on feedback from @hellofromTonya and @joemcgill I am going to punt this to WP 6.5. Marking as early, in hope of commit early and giving the whole release cycle to test. Assigning to Joe to own.

This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.


5 weeks ago

Note: See TracTickets for help on using tickets.