Fetching page data & rendering components
Fetching page data & rendering components
How replacing complex multi-table SQL JOIN queries (articles, categories, tags, authors) with Elasticsearch document indexing boosted Google PageSpeed Performance score from 29 to 69.
In relational database systems like MySQL, querying article data often involves joining multiple tables: articles, categories, article_tags, tags, and authors.
While relational schema design is excellent for transactional integrity (ACID), running complex multi-table SQL JOINs—especially combined with wildcard text filtering (LIKE '%keyword%')—becomes a severe bottleneck as dataset sizes and concurrent traffic expand.
In this article, I share why and how we replaced heavy MySQL JOIN queries with Elasticsearch 8 document indexing, boosting our Google PageSpeed Performance score from 29 to 69 while significantly reducing database load.
When an end user or mobile application requests a list of articles or searches for a specific topic, a typical relational SQL query looks like this:
-- Generalized SQL JOIN query example across multiple tables
SELECT a.id, a.title, a.slug, c.name AS category_name, GROUP_CONCAT(t.name) AS tag_names
FROM articles a
LEFT JOIN categories c ON a.category_id = c.id
LEFT JOIN article_tags at ON a.id = at.article_id
LEFT JOIN tags t ON at.tag_id = t.id
WHERE a.status = 'published' AND (a.title LIKE '%skincare%' OR a.content LIKE '%skincare%')
GROUP BY a.id
ORDER BY a.published_at DESC
LIMIT 20;
(Note: The table schema and SQL query above have been generalized for illustration purposes).
LIKE '%term%' cannot utilize standard B-Tree indices efficiently, forcing MySQL to scan raw text blocks across disk.GROUP BY and ORDER BY force MySQL to create temporary memory/disk tables to aggregate JOIN results.Instead of forcing the database to perform expensive JOINs dynamically on every incoming HTTP request, we denormalized article data into a single, flat Elasticsearch JSON document.
{
"id": 10452,
"title": "Top 10 Skincare Essentials for Summer",
"slug": "top-10-skincare-essentials",
"category": {
"id": 4,
"name": "Skincare Routine"
},
"tags": ["Skincare", "Summer", "Hydration"],
"published_at": "2026-06-18T10:00:00Z"
}
By shifting article rendering and search queries from MySQL relational JOINs to Elasticsearch document retrieval:
Security & Anonymization Disclaimer: All database schemas, table names, column structures, and SQL query examples mentioned in this article have been generalized, sanitized, and anonymized to protect proprietary production database details while accurately illustrating the underlying backend architectural concepts.