Skip to content

SQL Scope

Use SQL to query the lot you opened in Analyze. You can inspect selected dies, summarize tests, or compare recorded results with your what-if limits. Queries do not change the data or push selections and limits back into Analyze.

  1. Open a lot in Analyze and check its snapshot. Brush dies or set what-if limits if needed.
  2. Open SQL and check the scope summary above the editor.
  3. Choose Scope Overview, then Run or press Ctrl+Enter.
SELECT * FROM current_scope;

current_scope reports the lot, snapshot, selection state and die count, selected test/return, wafer focus, and number of scenario limits. With no Analyze scope, it is empty. Changing Analyze context does not rerun an old result: check the scope and choose Run again.

Execution requires editor access. See Roles And Access. For Python and pandas, use Notebook Execution.

The current_scope_* helpers follow the attached Analyze snapshot. Their selection rules are:

Attached context Rows in the scoped die and test helpers
No Analyze scope None, not every lot in the account.
Selection inactive All attempts in the attached lot.
Selection active, with dies Attempts matching those wafer/X/Y identities.
Selection active, with no dies None, not a fallback to the full lot.

The SQL schema also exposes portable views: lots, wafers, die_results, final_die_results, test_results, final_test_results, tests, and bins. Those views do not inherit the Analyze selection, historical snapshot, or scenario. Use the scoped helpers for that context, rather than joining it to an unpinned portable view by lot name.

In portable views, lot_key is the stable lot identity and lot_id is its display name. The final_* views use the latest device attempt, not the account’s first-pass policy. wafers contains reported wafer-summary counts; it is not a substitute for counting detail rows. X/Y can be deterministic surrogates when the source lacks coordinates, so SQL identities alone do not establish physical wafer geometry.

Table or view Contents
current_scope Context summary; zero or one row.
current_scope_selected_dies Selected identities: wafer_number, x, y. Empty when selection is inactive.
current_scope_die Die-attempt rows for the attached lot and selection, including bins, recorded pass, site, test time, and part ID.
current_scope_limits Scenario limits: test_number, return_index, test_name, lsl, usl.
current_scope_test_results All tests and returns in the attached die scope, with recorded and scenario-derived values.
current_scope_active_test_results The same results narrowed to the selected test and return; all scoped tests if no test is selected.

Wafer focus is metadata, not an automatic filter on these helpers. To query the active test and explicitly honor the focused wafer:

SELECT tr.*
FROM current_scope_active_test_results AS tr
CROSS JOIN current_scope AS s
WHERE s.selected_wafer_number IS NULL
OR tr.wafer_number = s.selected_wafer_number
ORDER BY tr.wafer_number, tr.test_number, tr.return_index, tr.y, tr.x
LIMIT 200;

Use both test_number and return_index as test identity. PTR/FTR rows have a null return index; MPR rows may have several returns for one test number. This query includes null results in attempt_rows, but excludes them from measured_rows and the mean:

SELECT
test_number,
return_index,
test_name,
unit,
COUNT(*) AS attempt_rows,
COUNT(result) AS measured_rows,
AVG(result) AS mean_result,
COUNT(*) FILTER (WHERE scope_pass IS TRUE) AS scope_pass_rows,
COUNT(*) FILTER (WHERE scope_pass IS FALSE) AS scope_fail_rows,
COUNT(*) FILTER (WHERE scope_pass IS NULL) AS unknown_verdict_rows
FROM current_scope_test_results
GROUP BY test_number, return_index, test_name, unit
ORDER BY test_number, return_index, test_name, unit;

The three verdict counts sum to attempt_rows, not necessarily measured_rows. A row without a measurement can still carry a recorded verdict.

SELECT * FROM current_scope_limits
ORDER BY test_number, return_index;

In scoped test results, raw_pass preserves the recorded test verdict. scope_pass checks the result against inclusive scope_low_limit and scope_high_limit, even without a scenario; a null result retains raw_pass. A recorded failure can therefore be in range. Do not call every difference a rescued die or a lot-yield change.

has_scope_override and scope_limit_source identify scenario rows. In this SQL helper, a null override bound falls back to the result’s original bound; it does not remove that bound. These helpers do not apply the notebook runtime’s account-spec override layer. For authoritative scenario impact, use Review impact.

SQL accepts one read-only SELECT or EXPLAIN statement, including supported CTEs. Writes and filesystem, network, export, and system helpers are blocked. It is not an unrestricted DuckDB shell.

The editor starts with 200 rows per page and remembers your page-size choice. Next and Previous request another page; they do not load the whole result into the browser. The API defaults to 1,000 rows if limit is omitted and caps each page at 100,000 rows, not the total query result. Your SQL’s own LIMIT restricts the query before pagination and the total-row count.

Use an ORDER BY with enough keys to distinguish rows when paging. Each page reruns the query with the current scope, rather than using a frozen cursor. Raw-attempt helpers omit attempt indices, so tied attempts do not have a guaranteed page order. Use an aggregate for stable scoped summaries. Clicking a result-table column sorts only the loaded page, not the full query result.

The query wait times out after 30 seconds, but counting all matching rows can still be expensive even for a small page. Narrow the query after a timeout; do not treat the error as confirmation that all server work stopped immediately. EXPLAIN returns the plan rather than paginating the query’s data rows.