MySQL: JSON Functions: Performance
Module: Database-Specific Features
JSON performance depends on indexing and query complexity: (1) Generated columns: Essential for indexing (100x faster), use STORED for indexes, VIRTUAL for computed values. (2) Index frequently queried paths: Create generated column + index for paths used in WHERE clauses. (3) Avoid deep nesting: 3+ levels slow down extraction, flatten structure if possible. (4) Use ->> for text: Faster than JSON_EXTRACT + JSON_UNQUOTE. (5) Batch updates: Update multiple JSON fields in single JSON_SET() call. Real-world: Shopify uses generated columns for product brand/category (100x faster queries). Slack uses generated columns for user theme/language. Use JSON for flexible schemas (< 1M rows), normalized tables for fixed schemas or large scale.
Generated columns: 100x faster with indexes, use STORED for indexes
Index frequently queried paths: Create generated column + index for WHERE clauses
Use ->> for text: Faster than JSON_EXTRACT + JSON_UNQUOTE
Avoid deep nesting: 3+ levels slow down extraction, flatten if possible
Batch updates: Update multiple JSON fields in single JSON_SET() call
Limit JSON size: Keep < 1MB, large JSON slow down queries
Use JSON_CONTAINS() for arrays: Faster than extracting and comparing
Not indexing JSON paths: Sequential scan 100x slower, use generated columns + indexes
Using TEXT instead of JSON: No validation, no JSON functions, use JSON type
Deep nesting: 3+ levels slow, flatten structure or use normalized tables
Not using generated columns: Cannot index JSON directly, must use generated columns
Forgetting quotes in JSON_CONTAINS(): Must use "value" not value