Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dotherightthing/00d5f8004a06e487cece8d31e96ab5c8 to your computer and use it in GitHub Desktop.
Save dotherightthing/00d5f8004a06e487cece8d31e96ab5c8 to your computer and use it in GitHub Desktop.
[Post meta vs separate database tables] #database #wordpress

Post meta vs separate database tables

An interesting read from Post meta vs separate database tables

If your plugin is going to have A LOT of data, then using the wp_postmeta is NOT a good idea as demonstrated below:

Taking Woocommerce as an example,

In a store with ~30,000 products, say there will be an average of ~40 post meta (attributes and everything) per product, 5 product images per product, which means there will be ~4 image meta for each image:

30,000 products x 40 meta each = 1,200,000 rows in wp_postmeta

[+]

30,000 products x 5 images each x 4 image meta for each = 600,000 rows in wp_postmeta

So with merely 30,000 products you are looking at having 1,800,000 rows in wp_postmeta.

If you add more properties to your products or your product images, this number will multiply.

Then i hooked into get_(post_type)_meta filter to override retrieval of metadata to serve them from new custom tables.

Now the same query from earlier, which took ~ 3 seconds to fetch from wp_postmeta takes ~0.006 seconds. The site now behaves as if it was a fresh WP installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment