# Partial execution
> Run or price a query up to one CTE, one pipe stage, one subquery, or one statement, straight from the editor gutter. Check what a CTE returns without rewriting the query around it.
Source: https://docs.querylab.io/writing-sql/partial-execution/
**Query 1 · $0.00 | 0.14 ms elapsed, 0 B**
```sql
WITH failed_tests AS (
SELECT vehicle_id, vehicle_snapshot.make, vehicle_snapshot.model,
defects, completed_date
FROM `ace-analytics.warehouse.fact_mot_test`
WHERE completed_date >= '2025-09-01' AND test_result = 'FAILED'
),
«sel:dangerous_defects AS (
SELECT f.vehicle_id, f.make, f.model, d.defect_type, d.parsed.category
FROM failed_tests AS f, UNNEST(f.defects) AS d
WHERE d.is_dangerous = TRUE
)»
SELECT make, model, COUNT(*) AS n
FROM dangerous_defects
GROUP BY make, model
```
WITH failed_tests AS ( ... ), dangerous_defects AS ( SELECT f.vehicle_id,
f.make, f.model, d.defect_type, d.parsed.category FROM failed_tests AS f,
UNNEST(f.defects) AS d WHERE d.is_dangerous = TRUE ) SELECT * FROM
dangerous_defects
Click: Re-estimate • Shift+Click: Run
## Estimating or running from the gutter
A grey diamond appears in the left margin on every line that starts an execution boundary.
| Boundary | Icon sits on |
| -------------------- | ------------------------------------------------------------ |
| CTE | The `name AS (` line of each `WITH` entry |
| Pipe stage | Each `\|>` line of a [pipe query](https://docs.querylab.io/writing-sql/pipe-syntax/) |
| Subquery | The opening line of a subquery in `FROM` or `WHERE` |
| Set-operation branch | Each side of a `UNION` / `INTERSECT` / `EXCEPT` |
| Statement | The first line of each statement in a script |
| The final `SELECT` | The whole query; same as **Run Query** |
- Click the diamond to dry-run the query up to that boundary. The diamond turns into a green `$`; hover it for the bytes and cost.
- Shift-click to run it. Results replace the results panel like any other run, and are subject to the tab's [cost limit](https://docs.querylab.io/writing-sql/cost-limits/).
- Hover the diamond to see the SQL that will be sent, with the other CTE bodies collapsed to `...`.
Editing the query clears the estimates.
## What gets sent
For a CTE, everything up to and including that CTE, followed by `SELECT * FROM `:
```sql
WITH failed_tests AS (
SELECT vehicle_id, vehicle_snapshot.make, vehicle_snapshot.model,
defects, completed_date
FROM `ace-analytics.warehouse.fact_mot_test`
WHERE completed_date >= '2025-09-01' AND test_result = 'FAILED'
)
SELECT * FROM failed_tests
```
What Shift-click on failed_tests runs. The later CTEs and the final SELECT are dropped.
For a pipe stage, the query is cut after that `|>` line. For a subquery, the subquery itself runs as a top-level query. For a statement in a script, that statement alone runs, with any `DECLARE` and `SET` above it prepended so its variables resolve. A `SELECT` that reads a temp table created earlier in the script still needs the whole script, or a [selection](#running-a-selection-instead) that includes the `CREATE`.
Filters from later in the query are pushed into the partial query where they apply (the same **Filter Propagation** switch as the [Insights panel](https://docs.querylab.io/writing-sql/insights-panel/)), so the estimate for a CTE reflects the `WHERE` you wrote on it downstream.
> **A partial run is a real run.** Shift-click on the first CTE of a query that filters in the last one can scan the whole table. Click first; the `$` tells you what Shift-click will cost.
## Running a selection instead
Select any text and press `⌘ Enter` (`Ctrl Enter` on Windows and Linux): only the selection runs. That's the tool for one statement out of a script, or for a CTE body pasted on its own. A tab-level `TABLESAMPLE` directive still applies to the selection. With nothing selected, `⌘ Enter` runs the whole tab.
## Checking a query section by section
Click each diamond top to bottom to see which section carries the bytes, then Shift-click the CTEs in order and check their rows; the first one with wrong output is where the problem is. **Analyze** in the cost view of the [Insights panel](https://docs.querylab.io/writing-sql/insights-panel/) dry-runs every boundary in one click.