Loading...

SQL AI Optimizer - Run #1

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

Perfect! I have successfully analyzed your MySQL performance schema data and submitted 4 comprehensive groups of queries, each containing 20 queries for optimization:

Summary of Submitted Groups:

1. High Total Execution Time (Overall Server Impact)

2. High I/O & Rows Examined (Disk I/O Intensive)

3. Memory & Temporary Table Issues (Memory/Disk Usage)

4. Missing Index & Full Table Scans (Index Optimization)

Key Findings Across All Groups:

  1. View Performance: Many queries use views like contractoffersfull and simfreeoffersfull which cause repeated full scans
  2. DISTINCT + ORDER BY Pattern: Common anti-pattern creating excessive temp tables
  3. NOW() in WHERE Clauses: Prevents index usage on date columns
  4. Complex Subqueries: Nested queries with JOINs preventing index optimization
  5. Missing Composite Indexes: Many queries filtering on (make, name, colour/size) without covering indexes

Each query includes specific metrics (rows examined, execution count, temp tables, etc.) and detailed reasons for optimization to help prioritize your performance improvement efforts.

Run Information

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

Total Queries: 80

Query Groups

High Total Execution Time

20

Queries consuming the most cumulative server time and impacting overall performance. These queries have the highest total execution time and are critical for optimization.

Total execution time of 55,791 seconds (15.5 hours) across 892,277 executions. This single query consumes the most server time overall, examining 611M rows and creating 2.4M temp tables with 777K sort merge passes.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Total execution time of 10,017 seconds with 1.29M executions. Performs full table scans (2.6M scans) on simfreeoffersfull view, examining 41M rows. Missing index on retailername.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Total execution time of 9,925 seconds over 1.27M executions. Examines 728M rows with many full table scans (1.2M), indicating missing join indexes or inefficient join order.
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 execution time of 7,196 seconds with 1.27M executions. Similar pattern to previous query, examining 724M rows with 1.3M full scans and sorting 112M rows.
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 execution time of 4,202 seconds over 5.75M executions. Very high frequency query with poor average performance, likely missing index on networkname column.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW DATA 
FROM `contractoffersfull` 
WHERE `networkname` = ? 
ORDER BY 1
Total execution time of 3,993 seconds with 900K executions. Performs full table scans (900K) and range scans (898K) on filtered data, needs composite index on (make, name, size).
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Total execution time of 3,438 seconds over 3.6M executions. Has 3.6M no-index-used occurrences and 957K full joins, examining 16M rows. Critical index missing on derived table.
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 execution time of 2,460 seconds with 105K executions. Complex query with subquery GROUP BY and multiple joins, performing 105K table scans and examining 5.3M rows.
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 execution time of 2,014 seconds over 900K executions. Performs 900K range scans and table scans, sorting 7.2M rows. Needs index on (make, name, colour).
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Total execution time of 1,868 seconds with 31K executions. Average 59ms per query, examining 5M rows with 59K full joins. Complex multi-table join needs optimization.
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 execution time of 1,526 seconds over 10,485 executions. Very slow average time (146ms), examining 3.5M rows with 21K full table scans. GROUP BY with HAVING needs index.
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 execution time of 1,300 seconds with 2.17M executions. High frequency query with no rows examined (using index), but taking significant total time. Index optimization possible.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `size` 
FROM `model` 
WHERE `size` > ? 
ORDER BY `size`
Total execution time of 1,241 seconds with 1.29M executions. Performs 1.29M table scans, examining 2.8M rows. Needs composite index on (make, name, size).
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Total execution time of 1,145 seconds over 2.43M executions. Simple SELECT but executed frequently (2.43M times), examining 82.7M rows with full table scans. Likely needs result caching.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
Total execution time of 948 seconds with 1.29M executions. Performs 1.29M table scans, examining 4.6M rows and sorting results. Missing composite index.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Total execution time of 784 seconds with 82,709 executions. Multi-table join examining 63.8M rows with 156K full joins, sorting 17M rows. Join order and indexes need optimization.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Total execution time of 545 seconds over 989K executions. Examines 38.6M rows with 989K full scans. WHERE clause with NOW() prevents index usage, needs function-based index or rewrite.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Total execution time of 543 seconds with 900K executions. Examines 14.4M rows with 900K table scans, sorting 14.4M rows. View or materialized table recommended.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
Total execution time of 423 seconds with 408 executions. Very slow average time (1.04 seconds per query), examining 71.8M rows. Complex subquery needs optimization or pre-aggregation.
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
Total execution time of 430 seconds with only 17 executions. Extremely slow average time (25.3 seconds per query), examining 2.8M rows. UNION with complex subqueries needs complete rewrite.
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 (

High I/O & Rows Examined

20

Queries performing excessive table scans and examining massive numbers of rows, causing high disk I/O. These queries indicate missing or unused indexes and inefficient data access patterns.

Single query examining 611,799,803 rows across 892,277 executions (686 rows per execution average). Massive data scanning indicates inefficient query design or missing indexes.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Single query examining 728,203,012 rows with poor rows examined to sent ratio of 11.89:1. Only returns 61M rows but scans 728M, indicating inefficient join predicates.
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
Single query examining 723,928,292 rows with ratio of 12.9:1 examined vs sent. Similar inefficiency to above query, needs join optimization or covering 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
Single query examining 153,054,431 rows over 97,121 executions (1,576 rows per execution). Multiple LEFT JOINs scanning large tables, needs index on join columns.
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`
Simple query examining 143,461,840 rows over 989,398 executions (145 rows each). Full table scan for DISTINCT operation, needs index on id column or query redesign.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blagged`
Single query examining 91,313,938 rows with ratio of 4.52:1, returning 20M rows. Join operation scanning excessive data, needs better join indexes.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
Simple SELECT examining 82,656,788 rows over 2.43M executions. Static reference table scanned repeatedly, should be cached in application or query cache.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
Single query examining 77,172,888 rows over 989,396 executions (78 rows each). DISTINCT on id suggests poor data model or missing index.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blaggedremove`
Single query examining 71,831,858 rows with terrible ratio of 1,734:1 (only returns 41K rows from 71.8M scanned). Subquery needs WHERE clause or better filtering.
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
Single query examining 63,841,530 rows with ratio of 3.74:1 over 82,709 executions. Complex calculated columns with multiple joins needs query rewrite.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Single query examining 40,938,232 rows over 1.29M executions (32 rows each). Subquery with DISTINCT and ORDER BY on view, needs materialized view or index.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Single query examining 38,851,642 rows with ratio of 29.46:1 over 45,236 executions. IN clause with UNION ALL subquery very inefficient, needs rewrite to JOIN.
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
Single query examining 38,586,483 rows over 989,398 executions. NOW() in WHERE clause prevents index usage, needs rewrite or computed column.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Single query examining 35,150,029 rows with ratio of 32.17:1 over 45,236 executions. IN clause with UNION ALL very inefficient, needs JOIN rewrite.
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
Simple query examining 31,757,085 rows over 10,516 executions (3,020 rows each). Full table scan on images table, needs WHERE clause or pagination.
Schema: handsetdeals
SQL:
SELECT `make` , `model` , `colour` , `filename` 
FROM `images`
Single query examining 22,206,886 rows with terrible ratio of 2,254:1 over 2,462 executions. Nested subquery with JOIN needs complete rewrite or denormalization.
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` >
Single query examining 19,321,430 rows with ratio of 4.82:1 over 166,277 executions. Self-join on network table scanning too much data.
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
Single query examining 16,311,748 rows with ratio of 3.02:1 over 3.6M executions. Derived table JOIN causing repeated full scans, needs better query structure.
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
Single query examining 15,247,752 rows with ratio of 5.63:1 over 1,584 executions. Multiple IN/NOT IN clauses causing inefficient scans, needs index optimization.
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
Single query examining 14,395,480 rows over 899,730 executions (16 rows each). Subquery with DISTINCT on view needs materialized result or covering index.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )

Memory & Temporary Table Issues

20

Queries creating excessive temporary tables, performing large sort operations, and using sort merge passes (disk-based sorting). These queries are memory-intensive and spill to disk, causing performance degradation.

Creates 2,423,938 temporary tables and sorts 1,986,404,912 rows with 777,762 sort merge passes (disk-based sorting). Massive memory pressure from sorting and temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
Sorts 112,248,882 rows and creates 1,268,068 temporary tables. Large result set sorting without proper indexes causing memory issues.
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
Sorts 67,815,938 rows across 97,212 executions. DISTINCTROW with JOIN causing repeated large sorts for duplicate elimination.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `network` . `name` , `data` 
FROM `simonlyoffers` JOIN `network` ON `simonlyoffers` . `networkid` = `network` . `id`
Sorts 61,251,908 rows and creates 1,268,066 temporary tables. Large multi-table join result set requiring sorting and temp storage.
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
Sorts 41,268,203 rows with 57 sort merge passes and creates 2,577,373 temporary tables. Subquery with DISTINCT and ORDER BY causing multiple temp table creations.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
Sorts 17,074,817 rows and creates 82,709 temporary tables. Complex calculated columns with multiple joins requiring temp storage for intermediate results.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
Sorts 14,395,480 rows and creates 899,729 temporary tables. Similar pattern to other DISTINCT queries, needs covering index to avoid temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `contractoffersfull` ) `a` 
ORDER BY ( `retailername` )
Sorts 7,207,427 rows and creates 1,005,380 temporary tables across 899,730 executions. Filtered DISTINCT with ORDER BY creating many temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Sorts 5,458,944 rows with 3,168 sort merge passes. Complex WHERE clause with multiple IN/NOT IN causing large intermediate result sets and disk-based sorting.
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 5,403,160 rows and creates 7,197,866 temporary tables. Derived table with DISTINCT creating temp table, then JOIN and ORDER BY creating more.
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
Sorts 4,771,609 rows across 989,398 executions. DISTINCTROW with date comparison and NOW() preventing optimization, causing repeated sorts.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `expirydate` 
FROM `expirydate` 
WHERE `expirydate` > NOW ( )
Sorts 4,563,865 rows and creates 1,288,718 temporary tables. Subquery pattern with filtering, DISTINCT and sorting requiring many temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
Sorts 4,173,142 rows across 5,642 executions. LEFT JOIN with complex WHERE clause creating 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
Sorts 4,007,534 rows across 166,278 executions. Self-join with ORDER BY repeatedly sorting results, needs index on piggyback column.
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 3,084,583 rows across 3,723 executions. Complex WHERE clause with multiple conditions and NOT IN subquery requiring sorting for duplicate removal.
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 2,789,826 rows and creates 1,288,714 temporary tables. Filtered subquery with DISTINCT and ORDER BY pattern, needs composite index to eliminate temp tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Sorts 2,336,725 rows across 51,929 executions. Complex multi-table join with calculated columns requiring sorting, needs result caching or materialized view.
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 1,351,016 rows and creates 959,511 temporary tables across 899,729 executions. Repeated pattern of subquery with DISTINCT requiring temp storage.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Sorts 1,003,860 rows with 396 sort merge passes. LEFT JOIN with calculated column requiring large sort with disk overflow (merge passes indicate this).
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
Sorts 857,297 rows and creates 10,485 temporary tables. Complex query with GROUP BY, HAVING, and DISTINCTROW requiring multiple temp tables for aggregation and deduplication.
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

Missing Index & Full Table Scans

20

Queries not using indexes effectively or performing full table scans. These queries show high values for SUM_NO_INDEX_USED, SUM_NO_GOOD_INDEX_USED, or SUM_SELECT_SCAN, indicating missing or suboptimal indexes.

No index used on 3,598,936 executions. Derived table prevents index usage on JOIN, performing 957,480 full joins and 2,641,454 full scans. Needs query rewrite or index on derived result.
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
No index used on 1,288,714 executions, performing 2,577,430 full table scans. View-based subquery with DISTINCT cannot use indexes, needs materialized view or covering index.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `retailername` 
FROM `simfreeoffersfull` ) `a` 
ORDER BY ( `retailername` )
No index used on 1,288,718 executions, performing 1,288,718 full scans. Needs composite index on (make, name, colour) to eliminate full scans.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
No index used on 1,288,713 executions, performing 1,288,714 full scans. Similar pattern, needs composite index on (make, name, size) for covering index optimization.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `simfreeoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Performs 1,268,068 full table scans and 1,268,068 full joins. Complex multi-table join without proper indexes on join columns, examining 724M rows.
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
Performs 1,226,575 full joins and 41,491 full scans. Similar join pattern to above, needs covering indexes on join tables to avoid full table access.
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
No index used on 899,730 executions, performing 899,730 full scans and 893,221 range scans. Needs composite index on (make, name, colour) for efficient access.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `colour` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? AND `colour` IS NOT NULL ) `a` 
ORDER BY ( `colour` )
No index used on 892,273 executions, performing 2,285,328 full scans and 1,111,433 full range joins. Complex subquery with calculated columns needs index on underlying tables.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT `cof` . * , `ceil` ( ( ( `upfrontcost` + ( `monthlycost` * ? - `cashback` - `IFNULL` ( `g` .
`value` , ? ) ) ) / ? ) * ? ) / ? AS `averagecost12months` , `ceil` ( ( ( `upfrontco
No index used on 899,727 executions, performing 899,730 full scans and 898,455 range scans. Needs composite index on (make, name, size) to convert to index-only scan.
Schema: handsetdeals
SQL:
SELECT * 
FROM ( 
SELECT DISTINCTROW `size` 
FROM `contractoffersfull` 
WHERE `make` = ? AND NAME = ? ) `a` 
ORDER BY ( `size` )
Performs 2,431,100 full table scans on network table. Static reference table accessed frequently without WHERE clause, should use application-level caching.
Schema: handsetdeals
SQL:
SELECT `id` , NAME , `coverage` , `roamingurl` , `roamingurlpayg` , `wificalling` ,
`wificallingpayg` , `wifidetails` , `4gcalling` , `4gcallingpayg` , `4gcallingdetails` 
FROM `network`
Performs 989,394 full table scans. Simple DISTINCT on id column suggests either missing index on id or poorly designed query (id should be unique).
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blagged`
Performs 989,397 full table scans. Same issue as blagged table - DISTINCT on id with no index, examining 77M rows across 989K executions.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` 
FROM `blaggedremove`
Performs 989,398 full table scans. NOW() in WHERE clause prevents index usage on date range columns, needs rewrite to pass date as parameter.
Schema: handsetdeals
SQL:
SELECT DISTINCTROW `id` , `note` 
FROM `note` 
WHERE NOW ( ) BETWEEN START AND FINISH
Performs 639,392 full table scans. NOW() in WHERE prevents index usage, and OR condition on increase fields makes index selection difficult.
Schema: handsetdeals
SQL:
SELECT * 
FROM `priceincreaseshandsets` 
WHERE ( `increase` > ? OR `increasepercentage` > ? ) AND `id` = ? AND NOW ( ) BETWEEN START AND
FINISH
Performs 166,282 full joins and 166,283 full scans. Self-join on network table without proper index on piggyback foreign key column.
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
Performs 166,267 full table scans. Simple query on updated table executed frequently, small table should be cached or needs covering index.
Schema: handsetdeals
SQL:
SELECT `DATE_FORMAT` ( `updated` , ? ) 
FROM `updated`
Performs 155,896 full joins and 82,709 full scans with 165,413 full range joins. Complex multi-table join with calculated columns needs better indexes on join columns.
Schema: handsetdeals
SQL:
SELECT `sof` . * , `network` . `name` AS `networkname` , `network` . `payg` , `retailer` . `name` AS
`retailername` , `monthlycost` * `contractlength` + `upfrontcost` - `cashback` - `IFNULL` ( `g` . `
No index used on 104,850 executions, performing 104,850 full scans with 94,375 full joins. Complex query with GROUP BY subquery and multiple joins needs better 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
Performs 97,122 full range joins and 97,122 full scans. Multiple LEFT JOINs without proper indexes on foreign key columns (countryid, networkid).
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`
No index used on 408 executions. Complex subquery with calculated columns examining 71.8M rows, needs WHERE clause and indexes on filter columns.
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