Add indexing to meta_value in wp_postmeta

Don’t limit the field, instead, limit the index, e.g.

ALTER TABLE wp_postmeta ADD key(meta_value(100))

This limits the index to the first hundred bytes of meta_value.

You’ll probably want an index on post_id, meta_key, meta_value for joins. How much of meta_key and meta_value is required depends on your data, for example

ALTER TABLE wp_postmeta ADD key(post_id, meta_key(100), meta_value(100));

Whether that helps with your query is another question. Get the SQL generated with $query->request and then run it with “EXPLAIN $SQL” to see how MySQL handles it, which indexes are used etc pp.

Leave a Comment