Lab: from JOIN SQL to an execution plan

Run on an isolated v4.2.5 instance. This small fixture validates results and planning entry points, not distributed execution or performance gains.

DROP DATABASE IF EXISTS kernel_plan_518;
CREATE DATABASE kernel_plan_518;
USE kernel_plan_518;
CREATE TABLE customers(id INT PRIMARY KEY, region VARCHAR(10));
CREATE TABLE orders(id INT PRIMARY KEY, customer_id INT, amount DECIMAL(10,2));
CREATE INDEX idx_customer ON orders(customer_id);
INSERT INTO customers VALUES(1,'east'),(2,'west');
INSERT INTO orders VALUES(10,1,10.00),(11,1,20.00),(12,2,5.00);
EXPLAIN SELECT id FROM orders WHERE customer_id=1;
EXPLAIN SELECT id FROM orders FORCE INDEX(idx_customer) WHERE customer_id=1;
SELECT c.region,SUM(o.amount) AS total FROM customers c JOIN orders o ON c.id=o.customer_id GROUP BY c.region ORDER BY c.region;
DROP DATABASE kernel_plan_518;

Expected totals: east=30.00, west=5.00. Save both EXPLAIN outputs and compare scan/index nodes, predicates, joins and output columns. A small-table default plan may legitimately avoid an index; verify FORCE effects from the plan.

Scale orders reproducibly with uniform/skewed distributions. Preserve JOIN results and record statistics freshness, estimated/actual rows, scans and runtime statistics. Execute EXPLAIN ANALYZE separately and compare cold/warm caches instead of attributing changes to timing alone.

The script cleans up its database. See SQL planning.