Make WordPress Core

Opened 11 months ago

Last modified 11 months ago

#59269 new enhancement

Add support for adding metadata in bulk

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords: has-patch has-unit-tests
Focuses: performance Cc:

Description

Related: #34848

This ticket aims to introduce functions for bulk inserting metadata in a manner that's more performant than calling the add_*_meta() functions multiple times per object. This is particularly beneficial during large imports or data generation where add_*_meta() is called many times for a large number of users, posts, comments, or terms.

This can be achieved by inserting all the metadata for the object in one INSERT query and only deleting the object's meta cache once. The existing filters and actions that are triggered when calling the add_*_meta() functions individually should still all be fired as expected, once for each meta key.

The performance benefit should grow as the number of rows to insert increases, because both the number of database queries and the number of cache deletions for the object should remain constant (O(1)) rather than increasing correspondingly to the number of rows (O(n)).

That said, there does appear to be a sweet spot after which the performance of one large INSERT query starts to degrade, although according to the PHPBench tests I've added it still remains overall more performant than multiple queries. Some more testing is needed across different payload sizes and database versions.

Change History (3)

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


11 months ago
#1

  • Keywords has-patch has-unit-tests added

#2 @swissspidy
11 months ago

#34848 already covers adding meta in bulk according to the patches, so what‘s the difference?

#3 @johnbillion
11 months ago

Yes the patches on that ticket mostly cover adding (and deleting) metadata in bulk but the ticket itself is about updating metadata in bulk. Adding is much more straight forward than updating, hence splitting it out into a separate ticket.

Note: See TracTickets for help on using tickets.