0

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?

2 Answers 2

4

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.

1
  • 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. Jul 31, 2011 at 0:53
3

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.

4
  • 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. Jul 30, 2011 at 23:40
  • Updated answer.
    – scribu
    Jul 31, 2011 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. Jul 31, 2011 at 0:06
  • Everyone should be caching? Besides a portion of dedicated-hosted sites nobody caches database queries... Jul 31, 2011 at 0:38

Your Answer

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

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