Optimizing SQL query for metadata
-
I’m looking at the limits of WordPress and have an optimization question. For the designers of WP, I’m trying to understand the following query in admin-functions.php:
SELECT meta_key from $wpdb->postmeta GROUP BY meta_key ORDER BY meta_id DESC LIMIT 10
I built a blog with the contents of a mailing list (https://blogs.semperen.com/nblog). The code I wrote to do the import (in *cough* perl) stuffs the info in to the db and saves the original RFC822 headers as meta data. You can see this from the front page of a post as the author of the post, which is a meta data retrieval. That’s pretty quick.
I have 83,147 blog posts in the db with a total of 1,180,243 rows in the meta data table. When editing a post, the above query takes about 5 minutes and 11 seconds, which doesn’t make it terribly interactive ??
So my question is, what is the point of the query? Is it to retrieve the metadata for that particular post? If so, why not do something like
SELECT meta_key FROM $wpdb->postmeta WHERE post_id = *thepostid* ORDER BY meta_id DESC
Takes about 0.01 seconds. In the original query, what relates it to the post. Looking for some guidance on this and I’m putting an articles together on it.
- The topic ‘Optimizing SQL query for metadata’ is closed to new replies.