0

So I have this custom post type and I have atleast 20 custom meta boxes for it which means there will be 20 postmeta rows.

So my question is, since I have that many, would it make more sense to just create a custom table to handle this instead of having 20 separate rows, one for each meta value...etc.

I would think there would be some kind of efficiency issues down the line if each 1 custom post equates to 20 post meta rows. It can add up pretty quickly I would assume.

And yes I realize I can serialize the data so it only takes 1 row however, this would prevent search query from finding anything.

What are your thoughts on this?

1
  • I don't think WP search covers wp_postmeta by default so I wouldn't worry about that.
    – totels
    Commented Nov 15, 2012 at 23:00

1 Answer 1

0

Short answer- It Depends

Long answer-

It's generally faster to query to 1 row in a single table rather than 20 rows of meta information but there are somethings you should cosider

20 custom meta boxes doesn't mean that there are 20 postmeta values. User might be filling only 5 of them & then that would mean that post meta table is faster

Wordpress automatically queries the post's meta when quering the posts, so that means you're already issuing a database query, even when meta information is in other table. If the information in the custom table is not heavy, it would make more sense to add it to post meta even if it means 20 rows. You could though, ask wp not to query for meta information

Think about when the fields are actually used. Is it used everytime the post is queried? Is it used at multiple places on same page? If yes, it probably is better to let wordpress handle it & use automatic caching. On the other hand if the field is only displayed on single page, it makes more sense to do a separate query just on that page.

This also depends on other things that you don't have much control over such as your server's RAM

If the meta information are articles, then it's best to issue a separate query to another table. If they are small sentences, url's etc. then postmeta will work fine.

The efficient way might even have a mix of postmeta as well as custom table & we can't say that one is better than other without actually knowing the data(which sometimes even the developer doesn't know). I recommend trying out both methods & see what works best for you

8
  • Yeah all 20 fields are filled and currently i have around 2000 rows of data which means in the postmeta, I have 40,000 postmetas...so you can imagine when I get to 10000 posts...etc..The data for the values isn't large at all, just 10 or so characters each. So if the database can handle that efficiently, then I will go with using custom post type...If not, then I will create my own table....
    – user23654
    Commented Nov 15, 2012 at 22:36
  • If the meta information are articles, then it's best to issue a separate query to another table. If they are small sentences, url's etc. then postmeta will work fine. wp_postmeta.meta_value is a longtext field, it may actually be more effective to use a custom table when dealing with specific data and leaving unknowns in wp_postmeta
    – totels
    Commented Nov 15, 2012 at 23:02
  • It's generally faster to query to 1 row in a single table rather than 20 rows of meta information but there are somethings you should cosider ... This isn't really true with good table indexes, this is like saying "It's faster to determine the color of one blue car vs. 100 blue cars"
    – totels
    Commented Nov 15, 2012 at 23:05
  • @totels Agree.. This slide presentation on MySQL refers to the very topic of optimized indexes and the large performance gains to be had. I recommend the whole presentation with regards to this question.
    – Adam
    Commented Nov 16, 2012 at 0:15
  • it may actually be more effective to use a custom table when dealing with specific data and leaving unknowns in wp_postmeta. I agree with you, what i meant was that mysql performs better in a table form when the size(in bytes) of data is big. Commented Nov 16, 2012 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.