Loading...

SQL AI Optimizer - Run #3

Exported on 2026-12-04 15:41:27

Perfect! I've successfully analyzed your MySQL 8 performance schema and submitted 4 groups of 20 queries each (80 total queries) covering different optimization perspectives:

Summary of Groups Submitted:

Group 1: High Total Execution Time ✅

Focused on queries consuming the most cumulative database time. The top query alone consumed over 15 hours (55,806 seconds) of total execution time across 892K executions.

Group 2: Missing Indexes & Full Table Scans ✅

Identified queries performing millions of full table scans without proper indexes. Some queries had 100% of executions using no indexes (SUM_NO_INDEX_USED equal to execution count).

Group 3: High IOPS & Row Examination ✅

Targeted queries with massive I/O overhead. Found queries with examination ratios as poor as 2,255:1 (examining 2,255 rows to return just 1 row), indicating catastrophic inefficiency.

Group 4: Memory & Sort Intensive Operations ✅

Captured queries causing memory pressure through excessive sorting and temporary table creation. One query sorted 1.99 billion rows with 777K sort merge passes spilling to disk.

Key Performance Issues Identified:

  1. Subquery anti-patterns - Excessive use of SELECT DISTINCTROW in subqueries
  2. Missing composite indexes - Filtering and sorting without proper index coverage
  3. Function usage preventing indexes - NOW() in WHERE clauses forcing full scans
  4. Inefficient join patterns - Cartesian products and missing join indexes
  5. Memory exhaustion - Sorts spilling to disk due to inadequate sort buffer

Each query was selected based on concrete metrics (execution time, row counts, index usage, etc.) and includes specific reasoning about why it's worth optimizing.

Run Information

Created: 2026-12-04 15:41:27 (localhost:3306)

Total Queries: 79

Query Groups

High Total Execution Time

20

Queries with the highest cumulative execution time that are impacting overall database performance. These queries consume the most total database resources and optimizing them will provide immediate performance improvements.

This query consumes 55,806 seconds total (over 15 hours) across 892,449 executions, examining 612M rows. It creates 2.4M temporary tables and performs 778K sort merge passes, indicating severe memory pressure and inefficient sorting.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
This query consumes 10,018 seconds total across 1.29M executions. It performs full table scans on every execution and creates 2.58M temporary tables, sorting 41M rows with significant overhead.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
This query takes 9,927 seconds total with 1.28M executions, examining 728M rows while only returning 61M rows. The 11.89:1 rows examined to sent ratio indicates poor join efficiency or missing indexes.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This query consumes 7,197 seconds total across 1.28M executions, examining 724M rows and performing 1.27M full table scans. It sorts 112M rows, indicating inefficient query execution.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This high-frequency query (5.76M executions) takes 4,203 seconds total. Despite examining 0 rows, it has 9.61 seconds total lock time, suggesting contention issues or view/materialized table problems.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW DATA 
FROM `contractoffersfull` 
WHERE `networkname` = ? 
ORDER BY 1
This query takes 3,995 seconds total across 899,901 executions, performing full table scans on each execution with 1.35M rows examined. Each execution creates temporary tables for DISTINCT and sorting.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This query consumes 3,439 seconds across 3.6M executions with 958K full table join operations and 2.64M table scans. The subquery-based join pattern is extremely inefficient at this scale.
Schema: handsetdeals
SQL:
SELECT `n` . `id` , `n` . `name` 
FROM ( 
SELECT DISTINCTROW `networkid` 
FROM `contractoffersfull` `cof` ) `cof` JOIN `network` `n` ON `n` . `id` = `cof` . `networkid` 
WHERE `n` . `piggyback` = ? ORDER
This complex aggregation query takes 2,461 seconds across 104,870 executions, performing both aggregations and joins. It examines 5.27M rows with 94K full join operations and 105K table scans.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `f` . `name` AS `fname` , `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof` 
WHERE NAME IS NOT NUL
This query consumes 2,015 seconds across 899,902 executions, performing full table scans each time. It examines 2M rows and sorts 7.2M rows across all executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query takes 1,868 seconds across 31,461 executions with an average of 59ms per execution. It performs complex joins examining 5M rows and includes 58.6K full join operations.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `f` . `name` AS `fname` , `fh` . `predecessor`
, `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof
This query consumes 1,527 seconds across 10,487 executions with 146ms average per query. It examines 3.48M rows with a 41.44:1 examination ratio, performing aggregations and joins inefficiently.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof` 
WHERE NAME IS NOT NULL 
GROUP BY 1 , 2 
HAVING `c
This high-frequency query (2.17M executions) takes 1,300 seconds total. Despite examining 0 rows (suggesting a covered index issue), it still has 5.85 seconds lock time and significant overhead.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `size` 
FROM `model` 
WHERE `size` > ? 
ORDER BY `size`
This query takes 1,241 seconds across 1.29M executions, performing full table scans each time. It examines 2.79M rows and creates 1.29M temporary tables for sorting.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This very high frequency query (2.43M executions) consumes 1,145 seconds total, performing 2.43M full table scans. Even though it's selecting from a small reference table, the frequency makes this a significant bottleneck.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
This query consumes 948 seconds across 1.29M executions, performing 1.29M full table scans. It examines and sorts 4.56M rows with temporary table creation overhead.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query takes 784 seconds across 82,719 executions with multiple joins. It examines 63.9M rows with a 3.74:1 examination ratio and performs 155,922 full join operations.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
This high-frequency query (989,583 executions) consumes 545 seconds, performing full table scans each time and examining 38.6M rows total. The use of NOW() prevents index usage on the date range.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
This query takes 543 seconds across 899,902 executions, performing full table scans and creating temporary tables for DISTINCT and ORDER BY operations on 14.4M rows.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
This query consumes 498 seconds across 899,907 executions. Despite examining 0 rows (likely hitting an index), it still has 1.92 seconds lock time and significant execution time overhead.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `contractlength` 
FROM `contractoffersfull` 
WHERE `contractlength` > ? 
ORDER BY `contractlength`
This query has extremely poor performance with 423 seconds across only 408 executions (1.04 seconds average). It examines 71.8M rows but returns only 41K, giving a 1,734:1 examination ratio.
Schema: amazon
SQL:
SELECT `a` . * , ? AS `section` , `price` / `rrp` AS `discountpercentage` , `rrp` - `price` AS
`discountamount` 
FROM ( 
SELECT `title` , `asin` , NEW AS `rrp` , `image` , `price` , `condition2` , `node

Missing Indexes & Full Table Scans

20

Queries performing full table scans without proper index usage. These queries have high SUM_NO_INDEX_USED or SUM_SELECT_SCAN values, indicating missing or unused indexes that cause inefficient data access patterns.

This query performs 3.6M full table scans (SUM_NO_INDEX_USED=3,599,624) across its executions, with 958K full join operations. A covering index on contractoffersfull(networkid) would eliminate the subquery scan.
Schema: handsetdeals
SQL:
SELECT `n` . `id` , `n` . `name` 
FROM ( 
SELECT DISTINCTROW `networkid` 
FROM `contractoffersfull` `cof` ) `cof` JOIN `network` `n` ON `n` . `id` = `cof` . `networkid` 
WHERE `n` . `piggyback` = ? ORDER
Every single execution (1,288,964 of them) uses no index. A composite index on simfreeoffersfull(make, name, colour) would eliminate all full table scans and dramatically improve performance.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query performs 1.29M full table scans (SUM_NO_INDEX_USED=1,288,960) and 2.58M table scans. An index on simfreeoffersfull(retailername) would enable index-only scans for the DISTINCT operation.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
All 1.29M executions use no index (SUM_NO_INDEX_USED=1,288,959). A composite index on simfreeoffersfull(make, name, size) would provide index-only access and eliminate table scans.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This query performs 989,578 full table scans despite only selecting the id column. If id is the primary key, DISTINCTROW is unnecessary. If not, an index on blagged(id) is needed, or query logic should be reviewed.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blagged`
Similar to the blagged table query, this performs 989,581 full table scans. An index on blaggedremove(id) or query refactoring is needed to avoid scanning 77.2M rows across executions.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blaggedremove`
All 899,902 executions use no index. A composite index on contractoffersfull(make, name, colour) would enable efficient lookups and eliminate full scans.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query performs 899,901 full table scans. An index on contractoffersfull(retailername) would allow the DISTINCT operation to use an index-only scan.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
All 899,899 executions use no index. A composite index on contractoffersfull(make, name, size) is essential for this frequently-executed filtering and sorting pattern.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This massive query has 892,445 executions without index use and 2.29M table scans. Complex calculation in SELECT makes it hard to index, but underlying table joins need composite indexes.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
All 104,870 executions use no index, with 94,393 full join operations. The subquery with GROUP BY and joins needs indexes on contractoffersfull(name, make) and proper join column indexes.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `f` . `name` AS `fname` , `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof` 
WHERE NAME IS NOT NUL
All 41,948 executions use no index. The subquery pattern with UNION requires indexes on simonlyoffers(networkid) and network(piggyback, id) for efficient execution.
Schema: handsetdeals
SQL:
SELECT `n` . `name` 
FROM ( 
SELECT DISTINCTROW `networkid` 
FROM `simonlyoffers` `sof` ) `sof` JOIN `network` `n` ON `n` . `id` = `sof` . `networkid` 
WHERE `n` . `piggyback` = ? 
UNION 
SELECT DISTINCTROW
This simple query performs 34,757 full table scans. If TEXT is frequently accessed, consider if this table needs better structure or if queries should be refactored.
Schema: handsetdeals
SQL:
SELECT TEXT 
FROM `toppickstext`
All 31,461 executions use no index with 58,639 full join operations. Complex multi-table joins with aggregation need composite indexes on all join columns.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `f` . `name` AS `fname` , `fh` . `predecessor`
, `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof
All 10,522 executions use no index. The three-way UNION with DISTINCT on retailerid needs indexes on each table's retailerid column for efficient DISTINCT operations.
Schema: handsetdeals
SQL:
SELECT COUNT ( * ) 
FROM ( 
SELECT DISTINCTROW `retailerid` 
FROM `contractoffersfull` 
UNION 
SELECT DISTINCTROW `retailerid` 
FROM `simfreeoffersfull` 
UNION 
SELECT DISTINCTROW `retailerid` 
FROM `simonlyof
All 10,487 executions use no index. The GROUP BY with HAVING clause and subsequent join needs covering index on contractoffersfull(name, make) and join column indexes.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `cof` . `make` , `cof` . `name` , `h` . `date` 
FROM ( 
SELECT `make` , NAME , COUNT ( * ) AS `counter` 
FROM `contractoffersfull` `cof` 
WHERE NAME IS NOT NULL 
GROUP BY 1 , 2 
HAVING `c
All 10,487 executions use no index with 31,461 table scans. The UNION with IN subqueries needs indexes on network(id, name), retailer(id, name), and the referenced foreign key columns.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT NAME 
FROM `network` 
WHERE `id` IN ( 
SELECT DISTINCTROW `networkid` 
FROM `simonlyoffers` ) 
UNION 
SELECT NAME 
FROM `retailer` 
WHERE `id` IN ( 
SELECT DISTINCTROW `retailerid` 
FROM
This query performs 2.43M full table scans despite being a simple SELECT. Either add WHERE clause to make it selective, or if the full table is needed, consider caching at application level.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
This query performs 989,582 full table scans. The use of NOW() function prevents index usage. Need index on note(start, finish, id, note) and possibly rewrite to use passed timestamp parameter.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Similar to the note query, this performs 989,582 full table scans. Using NOW() prevents index usage. Add index on expirydate(expirydate, id) and consider passing timestamp as parameter.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )

High IOPS & Row Examination

19

Queries with extremely high row examination counts relative to rows returned, causing excessive disk I/O. These queries have poor selectivity and inefficient access patterns that result in reading far more data than necessary.

This query examines 728M rows but returns only 61M (11.89:1 ratio), indicating inefficient joins or missing indexes. The massive row examination suggests Cartesian products or unoptimized join conditions.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This query examines 724M rows returning 56M (12.9:1 ratio). Multiple join operations without proper indexes cause excessive row scanning across 1.28M executions.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This query examines 612M rows across 892,449 executions with a 1:1 ratio but the sheer volume of I/O (612M rows read) makes it a major bottleneck. The complex calculations on every row prevent optimization.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
This query examines 153M rows but returns only 93.8M (1.63:1 ratio). Despite relatively good ratio, the total I/O of 153M rows across 97,134 executions indicates missing join indexes.
Schema: handsetdeals
SQL:
SELECT `nr` . * , `n` . `name` AS `networkname` , `c` . `name` 
FROM `networkroaming` `nr` 
LEFT JOIN `country` `c` ON `nr` . `countryid` = `c` . `id` 
LEFT JOIN `network` `n` ON `nr` . `networkid` = `n`
This simple query examines 143.5M rows across 989,583 executions for DISTINCT operation. Full table scans on nearly 1M executions create massive I/O load, suggesting missing index or unnecessary DISTINCT.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blagged`
This query examines 91.3M rows returning 20.2M (4.52:1 ratio). The join without proper indexes on the join columns forces 97,224 table scans examining excessive rows.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
This query examines 82.7M rows across 2.43M full table scans. Even if the network table is small, 2.43M executions create significant I/O. Should be cached or filtered.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
This query examines 77.2M rows across 989,581 executions. Similar to the blagged table, full table scans for DISTINCT on id column are extremely wasteful.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blaggedremove`
This query has catastrophic I/O efficiency: examines 71.8M rows but returns only 41K (1,734:1 ratio). Each of 408 executions reads 176K rows on average, indicating severely missing indexes or poor query design.
Schema: amazon
SQL:
SELECT `a` . * , ? AS `section` , `price` / `rrp` AS `discountpercentage` , `rrp` - `price` AS
`discountamount` 
FROM ( 
SELECT `title` , `asin` , NEW AS `rrp` , `image` , `price` , `condition2` , `node
This query examines 63.9M rows returning 17.1M (3.74:1 ratio). Multiple LEFT JOINs without proper indexes cause excessive row examination across 82,719 executions.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
This query examines 40.9M rows for DISTINCT operation across 1.29M executions. Full table scans on the entire simfreeoffersfull table without index on retailername.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
This query examines 38.9M rows returning only 1.3M (29.46:1 ratio). The UNION ALL subquery with IN clause creates inefficient execution plan, scanning both tables multiple times.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW NAME AS `retailername` 
FROM `retailer` 
WHERE `ID` IN ( 
SELECT `retailerid` 
FROM `simonlyoffers` `sof` 
UNION ALL 
SELECT `retailerid` 
FROM `paygsims` ) 
ORDER BY NAME
This query examines 38.6M rows returning 30.7M (1.26:1 ratio). While the ratio is acceptable, the use of NOW() forces full table scans on 989,583 executions, generating massive I/O.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
This query examines 35.2M rows returning 1.1M (32.17:1 ratio). The UNION ALL with IN subquery pattern is inefficient, causing multiple scans of the subquery results.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `piggyback` 
FROM `network` 
WHERE `id` IN ( 
SELECT DISTINCTROW `networkid` 
FROM `paygsims` `p` 
UNION ALL 
SELECT DISTINCTROW `networkid` 
FROM `simonlyoffers` `sof` ) 
ORDER BY NAME
This query examines 31.8M rows with 1:1 return ratio but across 10,518 executions. Full table scans on images table should be avoided with proper WHERE clauses or caching.
Schema: handsetdeals
SQL:
SELECT `make` , `model` , `colour` , `filename` 
FROM `images`
This query examines 22.2M rows but returns only 9,848 (2,255:1 ratio). The nested subquery with JOIN in the IN clause creates catastrophic execution plan scanning far too many rows.
Schema: bumdeal
SQL:
SELECT `id` , NAME 
FROM `brand` 
WHERE `id` IN ( 
SELECT DISTINCTROW `brandid` 
FROM `nappy` JOIN `offers` ON `offers` . `nappyid` = `nappy` . `id` 
WHERE `offers` . `cost` > ? AND `nappy` . `map_size` >
This self-join query examines 19.3M rows returning 4M (4.82:1 ratio). The LEFT JOIN on network table without proper index causes 166,286 full join operations.
Schema: handsetdeals
SQL:
SELECT `network` . `name` , `network` . `id` , `network` . `piggyback` , `n2` . `name` AS
`piggybackname` 
FROM `network` 
LEFT JOIN `network` `n2` ON `network` . `piggyback` = `n2` . `id` 
WHERE `networ
This query examines 16.3M rows returning 5.4M (3.02:1 ratio). The subquery with join pattern scans contractoffersfull table 3.6M times for DISTINCT operation.
Schema: handsetdeals
SQL:
SELECT `n` . `id` , `n` . `name` 
FROM ( 
SELECT DISTINCTROW `networkid` 
FROM `contractoffersfull` `cof` ) `cof` JOIN `network` `n` ON `n` . `id` = `cof` . `networkid` 
WHERE `n` . `piggyback` = ? ORDER
This query examines 15.2M rows returning 2.7M (5.63:1 ratio). The combination of IN and NOT IN clauses with multiple conditions creates inefficient index usage across 1,584 executions.
Schema: amazon
SQL:
SELECT `title` , `asin` , NEW , `image` , `price` , `condition2` , `nodeid` 
FROM `headlines` 
WHERE `condition1` = ? AND `condition2` IN (...) AND `nodeid` NOT IN (...) AND `adult` = ? AND
`asin` NOT I

Memory & Sort Intensive Operations

20

Queries creating excessive temporary tables, performing large sort operations, and causing memory pressure. These queries have high SUM_CREATED_TMP_TABLES, SUM_SORT_ROWS, or SUM_SORT_MERGE_PASSES values, indicating memory-intensive operations that may spill to disk.

This query sorts 1.99 billion rows and performs 777,916 sort merge passes, indicating massive memory pressure with sorts spilling to disk. It creates 2.42M temporary tables across 892,449 executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
This query sorts 112M rows across 1.28M executions, creating 1.27M temporary tables. Multiple joins with complex result sets require substantial memory for materialization and sorting.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This query sorts 67.8M rows across 97,224 executions. The DISTINCTROW operation with JOIN requires temporary tables for deduplication and sorting, creating significant memory pressure.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
This query sorts 61.3M rows across 1.28M executions. Complex multi-table joins produce large intermediate result sets requiring sorting and temporary table creation.
Schema: handsetdeals
SQL:
SELECT `sfo` . `id` , `sfo` . `upfrontcost` , `sfo` . `url` , `sfo` . `note` , `ma` . `make` , `m` .
`name` , `m` . `colour` , `m` . `size` , `m` . `refurbished` , `m` . `5genabled` , `r` . `name` AS
This query creates 2.58M temporary tables and sorts 41.3M rows, with 57 sort merge passes. The DISTINCTROW with ORDER BY requires materializing and sorting large result sets across 1.29M executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
This query sorts 17.1M rows and creates 82,719 temporary tables. Multiple LEFT JOINs with complex expressions create large intermediate results requiring sorting and temporary storage.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
This query creates 899,901 temporary tables and sorts 14.4M rows. The pattern of DISTINCTROW followed by ORDER BY requires materialization in temporary tables for nearly 900K executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
This query sorts 7.2M rows across 899,902 executions, creating 1.1M temporary tables. Each execution requires a temporary table for DISTINCT and another for ORDER BY operations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query sorts 5.46M rows with 3,168 sort merge passes across only 1,584 executions. The merge passes indicate the sorts are too large for memory and are spilling to disk.
Schema: amazon
SQL:
SELECT `title` , `asin` , NEW , `image` , `price` , `condition2` , `nodeid` 
FROM `headlines` 
WHERE `condition1` = ? AND `condition2` IN (...) AND `nodeid` NOT IN (...) AND `adult` = ? AND
`asin` NOT I
This query creates 7.2M temporary tables and sorts 5.4M rows across 3.6M executions. The subquery with DISTINCTROW requires temporary table creation before the join operation.
Schema: handsetdeals
SQL:
SELECT `n` . `id` , `n` . `name` 
FROM ( 
SELECT DISTINCTROW `networkid` 
FROM `contractoffersfull` `cof` ) `cof` JOIN `network` `n` ON `n` . `id` = `cof` . `networkid` 
WHERE `n` . `piggyback` = ? ORDER
This query sorts 4.77M rows across 989,582 executions. The DISTINCTROW operation with function-based WHERE clause forces sorting without index usage.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )
This query creates 1.29M temporary tables and sorts 4.56M rows. Each execution requires temporary storage for the DISTINCTROW operation followed by ORDER BY.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
This query sorts 4.17M rows across 5,642 executions. The LEFT JOIN on string columns without proper indexing creates large intermediate results requiring sorting.
Schema: broadband
SQL:
SELECT * 
FROM `broadbandchoices` 
LEFT JOIN `rating` ON `broadbandchoices` . `provider_name` = `rating` . `providerName` 
WHERE ? = ? AND ( `offerExpiryDate` IS NULL OR `offerExpiryDate` > `UNIX_TIMESTA
This self-join query sorts 4M rows across 166,286 executions. The LEFT JOIN on the same table requires temporary tables for intermediate results and sorting.
Schema: handsetdeals
SQL:
SELECT `network` . `name` , `network` . `id` , `network` . `piggyback` , `n2` . `name` AS
`piggybackname` 
FROM `network` 
LEFT JOIN `network` `n2` ON `network` . `piggyback` = `n2` . `id` 
WHERE `networ
This query sorts 3.08M rows across 3,723 executions. Complex WHERE clause with NOT IN subquery requires materialization and sorting of result sets.
Schema: broadband
SQL:
SELECT * 
FROM `broadbandchoices` 
WHERE ? = ? AND ( `offerExpiryDate` IS NULL OR `offerExpiryDate` > `UNIX_TIMESTAMP` ( NOW ( ) ) )
AND `serviceIds` < ? AND `dealTypes` IN (...) AND `id` NOT IN ( SELEC
This query creates 1.29M temporary tables and sorts 2.79M rows. The DISTINCTROW with ORDER BY pattern requires temporary storage for 1.29M executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This query sorts 2.34M rows across 51,933 executions. Complex multi-table joins with calculated columns create large result sets requiring sorting and temporary table creation.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `paygsims` . * , `network` . `name` AS `piggybackname` , `retailer` . `name` AS
`retailername` , `retailer` . `name` AS `networkname` , ? AS `contractlength` , `g` . `name` AS `
This query creates 1.09M temporary tables and sorts 1.35M rows across 899,901 executions. Each execution requires temporary storage for DISTINCTROW and ORDER BY operations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
This query creates 1,224 temporary tables and sorts 390,661 rows with 68 sort merge passes. The merge passes indicate sorts spilling to disk despite only 408 executions.
Schema: amazon
SQL:
SELECT `a` . * , ? AS `section` , `price` / `rrp` AS `discountpercentage` , `rrp` - `price` AS
`discountamount` 
FROM ( 
SELECT `title` , `asin` , NEW AS `rrp` , `image` , `price` , `condition2` , `node
This query sorts 1M rows with 396 sort merge passes across only 396 executions. One merge pass per execution indicates consistent memory pressure with sorts spilling to disk.
Schema: amazon
SQL:
SELECT `eb` . `id` , `title` , `condition` , `price` , `rrp` , `price` / `rrp` AS `pricerrp` , URL ,
`image` 
FROM `ebaystoreproducts` `eb` 
LEFT JOIN `ebaycategorylist` `ecl` ON `eb` . `category` = `ec