Is it a good idea to improve meta query performance by adding tax query?


I’m aware that using taxonomies over metadata is preferred when it comes to posts grouping. In simple words this and this are saying “use meta for unique data and taxonomy for repeating data(the one which groups posts)”.

But I’m wondering if it is possible to improve meta query performance by introducing a taxonomy that will represent different ranges of that meta?

Let’s suppose I have a shop with post type Products. Each Product has Price meta. I have millions of rows in the database meta table.
What if I’ll add a Price Range taxonomy which will be used on front-end filters? Price Range will be like “1-100$”, “100-1000$”, etc. User clicks on “100-1000$” + sort by Price. This way I’ll query posts tagged by “100-1000$” and only after that will sort them by Price meta. Will it increase query performance?

And how could it be implemented in case the user is allowed to input “from” and “to” Price? It is probably a good idea to use the approach above and just to add taxonomy meta for Price Range? This will look like this:
– User selects “90-900$”
– Fetch all the Price Range terms which match that range. Ie. “1-100” and “100-1000”
– Query posts that are in “1-100” and “100-1000” Price Range(terms) and set meta value Price as >90 and <900
Will it increase performance too? This approach requires 2 queries : get terms(filtered by term meta), get posts.

I have no chance to check that with a really huge database as all my projects are not so big. But I’m still interested if any of my approaches will work for big sites?

, , , Vadim C. 3 years 2020-04-01T16:51:15-05:00 0 Answers 89 views 0

Leave an answer