DOTTY

Step through a SQL query and see each intermediate result

Dotty turns a SQL script into a dataflow, with one box for each step of the query. Run it one step at a time and open any box to read the rows it holds.

1. Load your script

On the Dotty home screen, choose Load and pick a .sql file. The script opens in the Import SQL window, where you can edit it before it is loaded.

A script can bring its own data. Its CREATE TABLE and INSERT statements become datasets, and the query reads from them. This is the script used on this page:

CREATE TABLE customers (customer_id INTEGER, name VARCHAR(40), region VARCHAR(20));
INSERT INTO customers VALUES
  (1, 'Ava Brooks', 'North'),
  (2, 'Ben Okafor', 'South'),
  (3, 'Chen Wei', 'East'),
  (4, 'Dana Ruiz', 'North'),
  (5, 'Eli Novak', 'West'),
  (6, 'Fatima Haddad', 'East');

CREATE TABLE orders (order_id INTEGER, customer_id INTEGER, amount NUMERIC(10,2), status VARCHAR(12));
INSERT INTO orders VALUES
  (101, 1, 120.00, 'completed'),
  (102, 2, 75.50, 'completed'),
  (103, 3, 210.00, 'cancelled'),
  (104, 1, 42.25, 'completed'),
  (105, 4, 99.99, 'completed'),
  (106, 5, 310.00, 'pending'),
  (107, 6, 64.00, 'completed'),
  (108, 3, 18.75, 'completed'),
  (109, 2, 150.00, 'completed'),
  (110, 6, 89.10, 'cancelled');

SELECT c.region, COUNT(*) AS order_count, SUM(o.amount) AS revenue
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
WHERE o.status = 'completed'
GROUP BY c.region
ORDER BY revenue DESC;
The Import SQL window with the script in it, and Cancel and Import buttons.

2. Check what Dotty found

Choose Import. The summary lists the tables the script reads, its joins, and the clauses in the query. Choose Create Dataflow.

The SQL Import Summary: the tables customers and orders, an inner join, and counts of the selected columns, WHERE conditions and GROUP BY columns.

3. Step through the query

The query is now on the canvas. The two tables are on the left, followed by a join, an aggregate and a sort. The WHERE condition became part of the join, so the join matches completed orders only.

Choose Step Forward to move the run on by one step. The numbers on each box show how many records have reached it so far. Step Backward takes the run back a step.

The dataflow paused after six steps: orders and customers feed Join_1, then Aggregate_1, then Sort_1.
Six steps in: the join has matched 4 orders, and the aggregate has 2 regions so far.

4. Read the rows

Click a dot on the edge of a box to see the records that have passed through that point. The sort's output holds the answer to the query: one row per region, largest revenue first.

You can do the same at any box while the run is paused, so you can read the join's rows before they are grouped.

The completed run with the sort's output open: North 3 orders 262.24, South 2 orders 225.50, East 2 orders 82.75.

Try it

The Revenue by Region example is the same kind of query, with the filter as its own step.

Open the Revenue by Region example

Next: Trace a result row back to its source rows, to see which orders make up North's 262.24.