Loading...

SQL AI Optimizer - Run #2

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

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

Summary of Query Groups Submitted:

Group 1: High Total Execution Time

Critical performance bottlenecks consuming the most server time. The top query alone consumed 55,798 seconds! These queries have the highest cumulative impact with complex operations, multiple joins, and inefficient view queries.

Group 2: Inefficient Table Scans & Poor Index Usage

Queries with terrible rows_examined to rows_sent ratios (up to 10,895:1!). These queries scan massive amounts of data due to missing indexes, with many having SUM_NO_INDEX_USED or SUM_NO_GOOD_INDEX_USED counts matching their execution counts.

Group 3: Memory & Disk I/O Issues

Queries creating excessive temporary tables and performing expensive sort operations. One query alone created 2.42M temp tables with 777K sort merge passes, indicating severe memory pressure and disk spillover.

Group 4: High Frequency Queries

Queries executed millions of times (up to 5.75M executions) that create cumulative impact through volume. These are excellent candidates for caching, materialized views, or query result caching since they're mostly lookup/reference queries.

Key Findings:

Each query includes specific metrics showing why it needs optimization, making it easy to prioritize your optimization efforts!

Run Information

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

Total Queries: 78

Query Groups

High Total Execution Time

20

Queries with highest cumulative wall-clock time causing major performance bottlenecks. These queries combined consume the most server time and should be prioritized for optimization.

Highest total execution time at 55,798 seconds across 892,363 executions. Query examines 611M rows and creates 2.4M temp tables with 777K sort merge passes, indicating severe memory pressure and inefficient operations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Total time 10,017 seconds with 1.29M executions. Uses no index (all executions miss index), examines 40.9M rows while returning same amount, and creates 2.5M temp tables with 57 merge passes.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Total time 9,926 seconds across 1.27M executions. Examines 728M rows (avg 571 per execution) with 1.2M full joins, indicating poor join optimization. Returns only 61M rows showing 11.89:1 examination ratio.
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
Total time 7,197 seconds with 1.27M executions. Has 1.26M full joins and examines 724M rows (12.9:1 ratio). Creates large sorted result sets of 112M rows causing significant memory usage.
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
Total time 4,202 seconds with 5.75M executions. High lock contention with 9.61 seconds total lock time (highest in system). Queries a view frequently without proper indexing.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW DATA 
FROM `contractoffersfull` 
WHERE `networkname` = ? 
ORDER BY 1
Total time 3,994 seconds with 899,815 executions. All executions miss index (SUM_NO_INDEX_USED = 899,813), examines rows inefficiently, and performs 1.09M sort operations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Total time 3,438 seconds across 3.59M executions. All executions use no index (3.59M no index count), has 957K full joins, and high lock time of 7.61 seconds.
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
Total time 2,461 seconds with 104,860 executions. All executions miss index, has 94K full joins, and average execution time of 24ms indicating complex aggregation on view.
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
Total time 2,015 seconds with 899,816 executions. All executions use no index, creates 7.2M sorted rows through 1.1M sort scans, examining 2M rows.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Total time 1,868 seconds with 31,458 executions. Average 59ms per execution with 58K full joins, all executions miss index, examining 5M rows for 251K results (20:1 ratio).
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
Total time 1,526 seconds with 10,486 executions but very slow average time of 146ms. All executions miss index with 2,226 full joins, examining 3.4M rows for only 83K results (41:1 ratio).
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
Total time 1,300 seconds with 2.16M executions. High lock time of 5.85 seconds and returns 21.6M rows, indicating frequent access to a commonly queried lookup table.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `size` 
FROM `model` 
WHERE `size` > ? 
ORDER BY `size`
Total time 1,241 seconds with 1.28M executions. All executions miss index (1.28M no index), creates 1.28M temp tables, and 3.64 seconds total lock time.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Total time 1,145 seconds with 2.43M executions. Examines 82.6M rows returning the same amount (1:1 ratio), with 7.5 seconds total lock time - highest lock percentage at 0.66%.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
Total time 948 seconds with 1.28M executions. All executions miss index (1.28M no index used), sorts 4.5M rows through 1.28M sort scans.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Total time 784 seconds with 82,714 executions. Has 155K full joins examining 63.8M rows (3.74:1 ratio), sorts 17M rows, indicating join order optimization needed.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Total time 545 seconds with 989,490 executions. Examines 38.5M rows but only returns 30.6M (1.26:1 ratio), with 2.09 seconds lock time. Date range filter may need index.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Total time 543 seconds with 899,816 executions. All executions miss index, examines 14.3M rows, sorts 14.3M rows through 899K sort scans.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
Total time 498 seconds with 899,821 executions. Returns 5.39M rows with 1.92 seconds lock time. Simple query on view with high volume.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `contractlength` 
FROM `contractoffersfull` 
WHERE `contractlength` > ? 
ORDER BY `contractlength`
Total time 430 seconds but only 17 executions with extremely high average of 25.27 seconds per execution. Examines 2.77M rows for only 255 results (10,895:1 ratio!) - clear optimization candidate with UNION query.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `l` . `make` , `l` . `model` 
FROM ( 
SELECT `make` AS `make` , NAME AS `model` , ? - `id` AS `counter` 
FROM `popular` 
UNION 
SELECT DISTINCTROW `l` . `make` , `l` . `model` , COUNT (

Inefficient Table Scans & Poor Index Usage

19

Queries examining far more rows than necessary due to missing or unused indexes. These queries have high rows_examined to rows_sent ratios and frequently use full table scans, causing excessive IOPS.

Examines 71.8M rows but returns only 41K results - a staggering 1,734:1 ratio. Total time 423 seconds with 1,632 full joins across 408 executions. Average 1.037 seconds per execution.
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
Examines 22.2M rows for only 9,848 results (2,254:1 ratio). Has 2,462 full joins across 2,462 executions. Total time 20 seconds with correlated subquery causing inefficiency.
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` >
Examines 15.2M rows returning 2.7M (5.63:1 ratio). Sorts 5.4M rows with 3,168 merge passes indicating memory pressure. Total time 37.5 seconds across 1,584 executions, avg 24ms.
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
Examines 14M rows for 146K results (95.69:1 ratio). Total time 55.8 seconds across 2,462 executions. Complex calculation with joins needs better indexing.
Schema: bumdeal
SQL:
SELECT * , `cost` / ( `n` . `map_number` * `packs` ) AS `pernappy` , `n` . `name` AS `nappy` , `r` .
`name` AS `retailer` 
FROM `offers` `o` 
LEFT JOIN `nappy` `n` ON `o` . `nappyid` = `n` . `id` LEFT J
Examines 38.8M rows for only 1.3M results (29.46:1 ratio). Total time 73 seconds with 45,240 executions. UNION ALL subquery causes repeated scans.
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
Examines 35.1M rows for 1.09M results (32.17:1 ratio). Total time 53.6 seconds with 45,241 executions. Similar UNION ALL pattern as previous query.
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
Examines 7.3M rows for 326K results (22.4:1 ratio). Has 90K full joins across 45,197 executions. Total time 123 seconds, needs join optimization.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Examines 8.26M rows for only 1,518 results (5,442:1 ratio). All 46 executions miss index. Total time 49 seconds with average 1.071 seconds per execution. JSON extraction with grouping is expensive.
Schema: ebay
SQL:
SELECT DISTINCTROW CAST ( `JSON_UNQUOTE` ( `brand` ) AS CHARACTER ) AS `brand` , COUNT ( * ) AS
`counter` 
FROM `fashionproducts` 
GROUP BY 1 
HAVING `counter` > ? 
ORDER BY 1
Examines 6.5M rows for 793K results (8.25:1 ratio). Has 7,751 full joins with 2,109 executions missing good index. Sorts 4.1M rows. Total time 84.5 seconds across 5,642 executions.
Schema: broadband
SQL:
SELECT * 
FROM `broadbandchoices` 
LEFT JOIN `rating` ON `broadbandchoices` . `provider_name` = `rating` . `providerName` 
WHERE ? = ? AND ( `offerExpiryDate` IS NULL OR `offerExpiryDate` > `UNIX_TIMESTA
All 41,944 executions miss index. Has 41,944 full joins examining 1.54M rows for 211K results (7.32:1 ratio). Total time 76.5 seconds. UNION query needs optimization.
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
Examines 5.27M rows for 732K results (7.2:1 ratio). All 104,860 executions miss index with 94K full joins. Complex aggregation query on view.
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
Examines 5M rows for 1.5M results (3.32:1 ratio). Has 3,038 executions with no good index used. Sorts 3M rows. Total time 80.8 seconds across 3,723 executions.
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
Examines 19.3M rows for 4M results (4.82:1 ratio). Has 166K full joins across 166,282 executions. Self-join on network table sorts 4M rows. Total time 180 seconds.
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
Examines 91.3M rows for 20.1M results (4.52:1 ratio). Sorts 67.8M rows across 97,217 executions. Total time 119 seconds. Simple join needing index optimization.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
Examines 2M rows for 345K results (5.93:1 ratio). Has 69,510 full joins across 69,510 executions. Total time 68 seconds. Multi-table join needs index optimization.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `simotoppicks` . `id` , `simotoppicks` . `name` 
FROM `simotoppicks` JOIN `simotoppicksims` ON `simotoppicks` . `id` = `simotoppicksims` .
`toppicksid` JOIN `simonlyoffers` ON `simot
Examines 9.45M rows for 2.33M results (4.05:1 ratio). Has 51,929 full joins across 51,931 executions. Total time 120 seconds. Multiple joins need optimization.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `paygsims` . * , `network` . `name` AS `piggybackname` , `retailer` . `name` AS
`retailername` , `retailer` . `name` AS `networkname` , ? AS `contractlength` , `g` . `name` AS `
Examines 153M rows for 93.7M results (1.63:1 ratio). Even with moderate ratio, examines most rows across 97,127 executions. Total time 354 seconds.
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`
Examines 38.5M rows for 30.6M results (1.26:1 ratio). Executed 989,490 times for total 545 seconds. Date range filtering without proper index.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Examines 9.5M rows for 4.7M results (2:1 ratio). Executed 989,489 times sorting 4.7M rows. Total time 359 seconds. Date comparison without optimal index.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )

Memory & Disk I/O Issues

20

Queries creating temporary tables and performing expensive sort operations causing memory exhaustion and disk I/O. These queries create temp tables on disk and use sort merge passes indicating insufficient memory allocation.

Creates 2.42M temp tables with massive 777,839 sort merge passes (indicates severe memory pressure). Sorts 1.98 BILLION rows across 892,363 executions. Total time 55,798 seconds.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Creates 2.57M temp tables with 57 merge passes. Sorts 41.2M rows across 1.28M executions. Total time 10,017 seconds. Derived table with ORDER BY causes temp table creation.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Creates 1.26M temp tables, sorts 112M rows across 2.53M sort scans. Total time 7,197 seconds with 1.27M executions. Complex SELECT list with multiple joins.
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
Creates 1.26M temp tables, sorts 61.2M rows. Total time 9,926 seconds across 1.27M executions. Similar query pattern to previous needing optimization.
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
Creates 1.28M temp tables, sorts 4.56M rows through 1.28M sort scans. Total time 948 seconds. Subquery with DISTINCT and ORDER BY pattern.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Creates 1.28M temp tables, sorts 2.79M rows. Total time 1,241 seconds across 1.28M executions. Same subquery pattern as above.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Creates 1.1M temp tables from sort operations, sorts 7.2M rows through 1.1M sort scans. Total time 2,015 seconds across 899,816 executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Sorts 1.35M rows through 1.09M sort scans. Total time 3,994 seconds with 899,815 executions. Derived table ordering pattern.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Sorts 67.8M rows across 97,217 sort scans. Total time 119 seconds. DISTINCT on join result requires sorting large dataset.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
Sorts 41.2M rows with 57 merge passes (disk sorts). Creates 2.57M temp tables. Total time 10,017 seconds across 1.28M executions.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Creates 82,714 temp tables, sorts 17M rows. Total time 784 seconds. Complex calculation with multiple joins creating temp storage.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Creates 899,815 temp tables, sorts 14.3M rows. Total time 543 seconds. Subquery with ORDER BY on view results.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
Sorts 5.45M rows with 3,168 merge passes indicating disk sorts. Total time 37.5 seconds across 1,584 executions. Large IN/NOT IN clauses.
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
Sorts 4.17M rows through 16,044 sort scans. Total time 84.5 seconds across 5,642 executions. LEFT JOIN with complex WHERE clause.
Schema: broadband
SQL:
SELECT * 
FROM `broadbandchoices` 
LEFT JOIN `rating` ON `broadbandchoices` . `provider_name` = `rating` . `providerName` 
WHERE ? = ? AND ( `offerExpiryDate` IS NULL OR `offerExpiryDate` > `UNIX_TIMESTA
Sorts 3.08M rows through 7,442 sort scans. Total time 80.8 seconds across 3,723 executions. Complex WHERE with NOT IN subquery.
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
Sorts 4M rows through 166,285 sort scans. Total time 180 seconds across 166,282 executions. Self-join requiring sort 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
Sorts 4.77M rows through 989,489 sort scans. Total time 359 seconds. DISTINCT with date comparison requires sorting.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )
Sorts 2.33M rows through 51,931 sort scans. Total time 120 seconds. Derived table with multiple joins and aliases.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `paygsims` . * , `network` . `name` AS `piggybackname` , `retailer` . `name` AS
`retailername` , `retailer` . `name` AS `networkname` , ? AS `contractlength` , `g` . `name` AS `
Sorts 1M rows with 396 merge passes. Total time 5.94 seconds across 396 executions. Calculation with LEFT JOIN creates temporary results.
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
Creates 1,224 temp tables, sorts 390K rows with 68 merge passes. Total time 423 seconds across 408 executions. Derived table with calculations.
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

High Frequency Queries

19

Queries executed with extreme frequency that create cumulative performance impact. Even though individually fast, their high execution count means optimization will provide significant aggregate benefits. These are excellent candidates for caching or materialized views.

Executed 5.75M times with total time 4,202 seconds. Queries a view with ORDER BY, average 0.7ms per execution but high cumulative impact. Highest lock contention at 9.61 seconds total.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW DATA 
FROM `contractoffersfull` 
WHERE `networkname` = ? 
ORDER BY 1
Executed 3.59M times for total 3,438 seconds. All executions miss index with 957K full joins. Average 0.95ms but executed constantly, creating 5.4M sorted rows.
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
Executed 2.43M times reading network configuration. Total time 1,145 seconds. Returns 82.6M rows total. Perfect candidate for application-level caching as network data changes infrequently.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
Executed 2.16M times returning 21.6M total rows. Total time 1,300 seconds. Lookup table query that should be cached. High lock time of 5.85 seconds.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `size` 
FROM `model` 
WHERE `size` > ? 
ORDER BY `size`
Executed 1.28M times with total time 10,017 seconds. Creates 2.57M temp tables. All executions miss index. Simple DISTINCT query on view executed repeatedly.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Executed 1.28M times for total 948 seconds. All executions miss index. Filters and DISTINCT on view, creates 1.28M temp tables. Average 0.7ms but high volume.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Executed 1.28M times for total 1,241 seconds. All executions miss index with 3.64 seconds lock time. Creates 1.28M temp tables for simple DISTINCT query.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Executed 1.27M times examining 724M rows with 1.26M full joins. Total time 7,197 seconds. Complex join query executed constantly, average 5.6ms.
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
Executed 1.27M times examining 728M rows with 1.22M full joins. Total time 9,926 seconds, average 7.8ms. Similar join pattern to previous query.
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
Executed 989,491 times for total 338 seconds. Simple DISTINCT query on reference table returning 143M rows total. Should be cached with TTL. Lock time 2.74 seconds.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blagged`
Executed 989,491 times with total time 545 seconds. Date range filter with NOW() prevents index usage. Should use materialized current notes with timestamp trigger.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Executed 989,490 times for total 359 seconds. Similar NOW() filter pattern. Returns 4.77M rows through 989K sort operations. Cache active expiry dates.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )
Executed 989,489 times for total 260 seconds. Returns 77M rows total. Simple lookup that should be cached, with 2.35 seconds lock time.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blaggedremove`
Executed 892,363 times for massive total time of 55,798 seconds. Complex calculation query with highest individual and cumulative impact. Average 62.5ms per execution.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Executed 899,816 times for total 2,015 seconds. All executions miss index. Simple filter on view executed constantly, creates 1.1M sort operations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Executed 899,816 times for total 543 seconds. All executions miss index. DISTINCT on view with ORDER BY, creates 899K temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
Executed 899,821 times returning 5.39M rows total. Total time 498 seconds. Simple range query on view with 1.92 seconds lock time. Should use indexed materialized values.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `contractlength` 
FROM `contractoffersfull` 
WHERE `contractlength` > ? 
ORDER BY `contractlength`
Executed 899,815 times for total 366 seconds. Examines 4.49M rows with 1.87 seconds lock time. Network lookup query should be cached.
Schema: handsetdeals
SQL:
SELECT `n` . `id` , `n` . `name` 
FROM `network` `n` 
WHERE `n` . `piggyback` = ? AND `n` . `id` <= ? 
ORDER BY `n` . `name`
Executed 899,815 times for total 3,994 seconds. All executions miss index with 1.35M sort operations. Average 4.4ms but high volume impact.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )