Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a WordPress theme framework, that will likely have many options as development progresses.

I found a related question: When is it appropriate to create a new table in the WordPress database?, which indicates that a new table would be more efficient, but I'd like to know more.

It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries. What's more, the wp_options table can become very cluttered.

What are the differences in query execution time, memory usage, and other factors between these two options?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries.

Performance is not about the pure number rows – the real amount of data and their structure counts. Usually, you use just the theme mod API. Your theme data is on a predictable place and can easily exported or changed by plugins. The theme mod API stores all data in one single option, so a cluttered options table will not be your problem.

But if you put very deep arrays or objects in your theme data the (de-)serialization may slow down reading and writing these options. I’d rather work on my data structures in this case than creating a new table. And I’d use a good caching plugin to decrease database queries.

If you opt for separate tables – find a good solution for child themes and multi site installations. Imagine a small network with 100 blogs. Do you create a new table for each blog? Or do all blogs share one table?

I would use a separate table only if WordPress’ table schema could not map my data structure. In a theme this is probably not the case.

share|improve this answer
    
Thanks toscho. This is great advice and informative. I'll use the KISS method in the options table. I always cache, but as One Trick Pony pointed out, most don't. –  Jeff Sebring Jul 31 '11 at 0:53
add comment

If your theme framework has so many options that you're contemplating putting them in a separate table, you're Doing It Wrong™.

What are the differences in query execution time, memory usage, and other factors between these two options?

It depends on how you build the table (column data types, indexes), how many rows it has and what kind of queries you're doing.

The wp_options table (along with the associated API) is optimized for simple key-value lookup, which is exactly what you need to store theme options.

share|improve this answer
    
I appreciate your experienced opinion, but that doesn't answer my question at all. I'm more interested in learning about performance than being given a rule to follow. –  Jeff Sebring Jul 30 '11 at 23:40
    
Updated answer. –  scribu Jul 31 '11 at 0:00
    
Thanks for the update. I likely will use the options table. It's just in my nature to want to know why. This might be a question better suited for the main StackOverflow, for the DBA's. I'm sure the difference with key->value lookups is negligible, especially since everyone should be caching. –  Jeff Sebring Jul 31 '11 at 0:06
    
Everyone should be caching? Besides a portion of dedicated-hosted sites nobody caches database queries... –  onetrickpony Jul 31 '11 at 0:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.