Tagged articles
subquery
37 articles · Page 1 of 1
This article provides a comprehensive guide to MySQL's EXPLAIN command, detailing each column in the execution plan output with practical examples to help developers analyze and optimize SQL query performance.
EXPLAINMySQLSQL Performance
0 likes · 8 min read

This tutorial demonstrates four methods for multi-table updates in MySQL—INNER JOIN, LEFT JOIN, subquery, and direct multi-table UPDATE—using order and product tables, showing how each handles non-matching rows differently with concrete SQL examples and result comparisons.
INNER JOINLEFT JOINMySQL
0 likes · 7 min read

MySQL silently resolves missing column names in subqueries to outer scope columns, turning filters into correlated subqueries that always evaluate true, causing full-table updates or deletes without errors or warnings; no sql_mode prevents this behavior.
Best PracticesMySQLcolumn resolution
0 likes · 10 min read


liandkAug 20, 2026 · Databases
This guide explains why subqueries are essential after learning JOINs, outlines their core characteristics, common use cases, two main types, step‑by‑step examples—including single‑row, multi‑row, aggregate, and derived‑table queries—and lists five key rules to avoid pitfalls while showing when to prefer subqueries over JOINs.
Database TutorialJOIN vs SubqueryNested Query
0 likes · 6 min read

This article walks through a MySQL 5.6 case study where a sub‑query that originally took over eight hours is accelerated to a few milliseconds by analyzing the execution plan, adding single‑column and composite indexes, rewriting the query as EXISTS or JOIN, and applying best‑practice indexing techniques.
MySQLQuery PerformanceSQL Optimization
0 likes · 13 min read

This article explains MySQL join types, demonstrates inner, left, right, and self joins with sample tables, shows how to write subqueries (correlated and non‑correlated) and UNION/UNION ALL, compares their performance, and provides practical indexing and query‑writing tips.
MySQLSQLUNION
0 likes · 11 min read

This article explains three techniques for performing cumulative queries in SQL—using a subquery, a Cartesian product with grouping, and a window function—detailing when each method is appropriate, especially for MySQL versions lacking native window support.
MySQLSQLcartesian join
0 likes · 2 min read

This article reproduces a slow‑query scenario caused by deep pagination with LIMIT, explains the underlying index mechanics, and presents several practical SQL techniques—subquery, INNER JOIN, and anchor‑record methods—to dramatically reduce execution time.
Back-tableINNER JOINIndex Optimization
0 likes · 11 min read

The article explains how using a large OFFSET with MySQL LIMIT forces the engine to scan and sort hundreds of thousands of index and data pages, then presents three concrete optimizations—covering index scans, subqueries, and partitioned tables—to dramatically reduce the work.
B+TreeCovering IndexIndex Optimization
0 likes · 9 min read

This article analyzes a MySQL query that originally took nine seconds, identifies redundant joins and an EXISTS subquery on the same table, and demonstrates how restructuring the query eliminates duplicate scans, reducing execution time to 0.2 seconds.
MySQLSQL Optimizationjoin
0 likes · 7 min read

This article explains how to identify and remove duplicate rows in a MySQL table—keeping a single record per duplicate group—by using a self‑join DELETE statement or a nested subquery approach, complete with sample table creation and data insertion scripts.
DELETE JOINMySQLSQL
0 likes · 6 min read

This article explains how to perform relational updates in MySQL using JOINs, subqueries, and multi‑table UPDATE statements, demonstrating table creation, sample data insertion, and the differences between INNER, LEFT, and RIGHT joins for keeping dependent tables in sync.
MySQLSQLUpdate
0 likes · 7 min read

This article explains why correlated subqueries are a performance bottleneck, introduces the Apply (Correlated Join) operator and a systematic set of transformation rules that push Apply down and replace subqueries with efficient joins, covering scalar, existential, and quantified subqueries, aggregation handling, and set operations, all illustrated with TPC‑H examples.
Apply OperatorDatabase EnginesDecorrelate
0 likes · 17 min read

This article explains why correlated subqueries are costly, introduces the Apply (correlated join) operator, and presents a series of systematic transformation rules that convert scalar, existential, and aggregate subqueries into efficient join‑based plans while preserving SQL semantics.
Apply OperatorDecorrelationSQL
0 likes · 17 min read

This article explains the process by which MySQL transforms uncorrelated IN subqueries into correlated subqueries, details the differences in EXPLAIN output columns, explores optimizer trace information, compares materialization versus correlated execution costs, and provides best‑practice recommendations for writing efficient queries.
Database PerformanceMySQLoptimizer trace
0 likes · 15 min read

This article walks through a MySQL 5.6 scenario where a subquery that originally took over eight hours is accelerated by orders of magnitude through strategic index creation, query rewriting, and join optimization, illustrating the impact of single‑column, composite, and covering indexes on execution plans.
Index OptimizationMySQLjoin
0 likes · 13 min read

The article explains why a MySQL query with a large LIMIT offset becomes extremely slow, demonstrates the underlying I/O behavior, and shows how rewriting the query with a sub‑query that fetches primary keys first can cut execution time from seconds to milliseconds while also reducing buffer‑pool pollution.
Buffer PoolInnoDBLIMIT
0 likes · 9 min read

This article demonstrates how a MySQL pagination query on a 9.5‑million‑row table that originally took over 16 seconds can be accelerated to under 0.4 seconds by moving the LIMIT condition into a subquery that selects only primary‑key IDs and then joining to retrieve the remaining columns, with detailed code and experimental verification.
InnoDBLimit OptimizationMySQL
0 likes · 10 min read

The article explains why large‑offset LIMIT queries on a MySQL table with millions of rows are slow, demonstrates how rewriting the query to use a subquery that first selects primary‑key IDs dramatically reduces execution time, and validates the improvement by measuring buffer‑pool page usage.
Buffer PoolDatabase PerformanceMySQL
0 likes · 9 min read

The article explains how using a large OFFSET in MySQL pagination forces the server to read and discard many rows, causing severe performance degradation, and demonstrates that rewriting the query to first fetch primary‑key IDs via a subquery dramatically reduces I/O and execution time, with buffer‑pool experiments confirming the improvement.
Buffer PoolMySQLPagination
0 likes · 9 min read

This article explains MySQL 8.0’s optimizer architecture and walks through the detailed transformation steps for subqueries, scalar‑to‑derived conversions, flattening, join simplification, partition pruning, and condition push‑down, illustrating each phase with code examples and execution‑plan screenshots.
Derived TablesMySQLOptimizer
0 likes · 25 min read

This article explains why correlated subqueries are a performance bottleneck, introduces the Apply (Correlated Join) operator, classifies subquery types, shows how to transform them into efficient joins, and discusses rule‑based push‑down techniques for Project, Filter, Aggregate, and Set operations.
Apply OperatorDecorrelationSQL
0 likes · 15 min read

This article explains why MySQL subqueries often cause performance bottlenecks, describes the underlying execution mechanism, and presents practical optimization strategies—including semi‑join, materialization, and EXISTS—plus a real‑world case study showing how to rewrite a slow query into a fast join.
MySQLSQLoptimization
0 likes · 7 min read


ITPUBFeb 5, 2021 · Databases
This article explains why correlated subqueries are a performance bottleneck, introduces the Apply (Correlated Join) operator, and presents a comprehensive set of transformation rules—including basic unnesting, Project/Filter push‑down, Aggregate handling, and Set‑operation rewrites—to convert subqueries into efficient join plans for modern SQL engines.
Apply OperatorSQLUnnesting
0 likes · 18 min read


21CTOJan 5, 2021 · Databases
This article presents five practical rules—return only needed rows, use proper indexes, avoid subqueries, replace OFFSET pagination with key‑based limits, and understand SQL's logical execution order—to help developers write efficient, high‑performance SQL queries across major relational databases.
PaginationSQLindexes
0 likes · 13 min read

This article demonstrates how to dramatically improve MySQL LIMIT offset query performance by moving the filter into a subquery that selects only primary keys, then joining to retrieve full rows, and validates the approach with buffer pool statistics and execution time measurements.
Buffer PoolLIMIT OFFSETMySQL
0 likes · 9 min read

This article examines why a MySQL 5.7 query that finds tables lacking primary or unique keys runs extremely slowly, demonstrates an experiment reproducing the issue, analyzes the optimizer's subquery rewrite, and shows how adding hints and materialization reduces execution time from over 16 seconds to under one second.
MySQLinformation_schemaoptimizer hint
0 likes · 4 min read

This article explains why a DELETE statement with a sub‑query can cause a full‑table scan in MySQL, describes the optimizer's semijoin, materialization and exists strategies for different sub‑query types, and shows how to rewrite the statement using a JOIN for better performance.
DELETEMySQLjoin
0 likes · 9 min read

A MySQL 5.6 database with three large tables suffered a 30,000‑second query when searching for students scoring 100 in a specific subject; by analyzing the execution plan, adding indexes on filter columns, and rewriting the query as a join, execution time dropped to under a second.
MySQLSQL Optimizationexecution plan
0 likes · 8 min read


21CTONov 21, 2019 · Databases
This article walks through a real‑world MySQL performance case where a nested sub‑query on millions of rows took over eight hours, explains why the plan used full table scans, and shows step‑by‑step index creation and query rewrites that cut the execution time to a millisecond.
MySQLSQL Optimizationindexes
0 likes · 7 min read

This article investigates a MySQL slow query caused by a subquery that triggers a full‑table scan, explains MySQL's query rewrite behavior, and shows how Django's lazy ORM evaluation can worsen performance, offering practical fixes using explicit query execution or join rewrites.
Database PerformanceDjango ORMMySQL
0 likes · 8 min read

This article shows step‑by‑step how to identify duplicate rows in a MySQL table—whether the duplication is based on a single column, multiple columns, or either column—and provides reliable SQL patterns, including GROUP BY with HAVING, UNION, sub‑queries, temporary tables, and a safe DELETE statement to clean the data.
DELETEHAVINGMySQL
0 likes · 11 min read


ITPUBMay 25, 2017 · Databases
A practical MySQL case study shows that replacing a subquery with a join reduced execution time from several seconds to a few milliseconds, and the article explains the underlying query processing, common pitfalls, and concrete optimization techniques for faster database access.
MySQLjoinsubquery
0 likes · 6 min read

This article examines why a seemingly simple MySQL IN subquery on tens of thousands of rows can take 33 seconds, explains the optimizer’s behavior in MySQL 5.5, and presents practical fixes such as using temporary tables or JOINs to dramatically improve performance.
IN ClauseMySQLjoin
0 likes · 5 min read


ITPUBFeb 20, 2017 · Databases
A production page stalled because a complex SQL query took over 20 seconds, leading the author to dissect joins and nested subqueries, pinpoint the bottleneck, validate assumptions with quick tests, and share practical lessons on query optimization and table‑size effects.
MySQLSQLdatabase
0 likes · 6 min read


ITPUBNov 3, 2016 · Databases
The article recounts a real‑world incident where a complex SQL query took over 20 seconds, explains how to pinpoint whether the slowdown originates from joins or nested subqueries, and shares practical steps and insights for diagnosing and fixing such performance issues.
SQLdatabaseoptimization
0 likes · 6 min read

A high‑load MySQL server was investigated, revealing that a seemingly simple subquery caused full table scans, but rewriting it as a JOIN or using an equality subquery enabled index usage, and newer MySQL versions have fixed the optimizer bug.
MySQLdatabasejoin
0 likes · 8 min read
