Optimizing Gravity Forms with custom indexes

🚨 Make sure to back up your database before applying any index changes! Every site’s query patterns are unique, and what improves performance in one case may not in another.

Modifying your database is a serious action and should be done with care. GravityKit is not responsible for any issues resulting from these modifications.

Gravity Forms stores large volumes of entry and meta data in the database, which can lead to performance bottlenecks when using plugins like GravityView. This guide outlines how to optimize your database by adding custom indexes to improve query performance and reduce server load.

🚀 Why indexes matter

When using GravityKit add-ons, Gravity Forms tables like gf_entry and gf_entry_meta are heavily queried. By default, Gravity Forms includes some basic indexes, but these may not be sufficient for advanced filtering, sorting, or joining patterns, especially when:

  • Sorting by custom field values
  • Filtering by meta_key and meta_value
  • Joining entry_meta to entry frequently

🧩 SQL script

Run this SQL in your database admin tool (like phpMyAdmin or Adminer) or via command line:

Note: This assumes a wp_ table prefix. Update the wp_gf_entry_meta code with your full table name, if needed!

-- NOTE: This assumes a "wp_" table prefix. Update the code with your prefix, as-needed!
ALTER TABLE wp_gf_entry_meta 
  ADD INDEX idx_entry_meta_key_value (entry_id, meta_key, meta_value(191)) 
  ALGORITHM=INPLACE, LOCK=NONE;

🧪 Testing & validation

  • Use EXPLAIN SELECT [full query] to verify indexes are used in queries. Check what queries are happening on your site using the Debug Bar plugin.
  • Monitor query performance before and after.
  • Always test on a staging environment before deploying to production.

⚠️ Heads-up on index key length limits:

If you’re using MySQL 5.7 or earlier, be aware of the 767-byte index key prefix limit in InnoDB.

Creating a composite index on meta_key(191) + meta_value(191) may exceed this limit, especially with multibyte character sets like utf8mb4 (where each character can use up to 4 bytes).

🔍 What to do:

  • Consider reducing the indexed prefix length (e.g., meta_key(100) + meta_value(100) )
  • Ensure you’re using innodb_large_prefix = ON and a file format that supports it (e.g., Barracuda)
  • Upgrade to MySQL 5.7+ or MariaDB 10.2+, where the limit is lifted when using DYNAMIC or COMPRESSED row formats

⏲️ How long does it take to add indexes on a large Gravity Forms dataset?

Adding indexes to a large table like gf_entry_meta can take time and temporarily impact site performance.

Factors that affect index creation time:

  • Table Size: More rows = longer time.
  • Server Specs: CPU, RAM, and disk I/O make a big difference.
  • Database Engine: InnoDB is common and allows reads during indexing, but writes may still block.
  • Existing Load: Busy sites will see more contention and delays.
  • Index Type: Composite indexes and prefix indexes (like on meta_value(191) ) are slower to create.

Estimated time to add composite indexes (like meta_key, meta_value(191), entry_id ):

Rows in gf_entry_meta Estimated Time per Index
100,000 ~5–15 seconds
1,000,000 ~30–60 seconds
5,000,000+ ~2–5 minutes
10,000,000+ ~5–15+ minutes

Will the site go down?

  • Reads will continue to work with InnoDB.
  • Writes (form submissions) may be slightly delayed.
  • On high-traffic sites, expect brief performance hits during index creation.

Best practices:

  • Run on a staging clone first to benchmark.
  • Schedule indexing during off-peak hours.
  • Backup your database before making changes.
  • Consider using maintenance mode to prevent submissions.
  • Use EXPLAIN SELECT to validate performance before and after.

Helpful SQL:

-- Estimate row count
SELECT COUNT(*) FROM wp_gf_entry_meta;

-- Check table size
SHOW TABLE STATUS LIKE 'wp_gf_entry_meta';
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us