✔ PASS
Graph & Hierarchy
task_076_Q76_bill_of_materials_recursive_rollup
Scaled: 1M+ Records
Ordered: Yes
Hierarchical Bill of Materials (BOM) Cost Rollup via Recursive CTE
Candidate Latency (1M Rows)
0.76 ms
(1.1x faster than golden)
Golden Latency (1M Rows)
0.83 ms
DuckDB in-memory engine
Underlying Data Volume
4 rows
240 B across 1 table
Evaluated Model
gemini-3.8-flash-low
Gen Latency: 11.3s
✔ Correctness Verified on 1M+ Records
Candidate SQL output matches ground truth golden query across all multiset rows and numeric tolerances (tol=1e-3). Zero data skew or anti-patterns detected on full dataset scale.
1. Analytical Significance & What It Means
Scenario & Frontier TrapBusiness Scenario & Problem
Manufacturing an electric vehicle requires thousands of nested parts (Car -> Battery Pack -> Cell Module -> Lithium Cathode). Calculating unit cost requires rolling up quantities across arbitrary depth levels.
⚡ The Frontier Trap (Why LLMs Fail)
Fixed joins only support fixed depth hierarchies (e.g. 3 levels max). If an assembly has 6 levels, fixed joins miss the lowest-tier parts entirely.
Prompt / User Request Given to Model
Manufacturing an electric vehicle requires thousands of nested parts (Car -> Battery Pack -> Cell Module -> Lithium Cathode). Calculating unit cost requires rolling up quantities across arbitrary depth levels. Execute the required analytical SQL calculation in DuckDB. Expected output columns: child_part, total_qty, depth. Results should be ordered as specified.
2. Underlying Tables, Row Counts & Data Volume
1 Tables (4 rows • 240 B)Production-scale fixtures loaded into the isolated DuckDB sandbox with at least 1,000,000 records per table:
📊 bom_parts
4 rows
240 B Data Volume
parent_part (VARCHAR) child_part (VARCHAR) quantity_needed (INTEGER) unit_cost (DECIMAL(10,2))Data Preview (showing sample rows from 4 total rows):
| # | parent_part | child_part | quantity_needed | unit_cost |
|---|---|---|---|---|
| 1 | EV_CAR | CHASSIS | 1 | 5,000 |
| 2 | EV_CAR | BATTERY_PACK | 1 | 0 |
| 3 | BATTERY_PACK | BATTERY_MODULE | 4 | 0 |
| 4 | BATTERY_MODULE | LITHIUM_CELL | 100 | 15 |
3. Graphical Query Execution Plan & Cost Bottlenecks
Physical Operator Tree (DuckDB 2.0 Profiler)Visual flowchart of the physical execution pipeline. Operators with high relative costs (≥ 20% of query runtime or heavy latency) are visually highlighted:
15.8%
Latency: 0.12 ms
Rows In/Out: 4
Data Vol: 4,192 B
65.2%
Latency: 0.50 ms
Rows In/Out: 4
Data Vol: 96 B
0.1%
Latency: 0.00 ms
Rows In/Out: 2
Data Vol: 48 B
📁 Projections: ['child_part', 'tot...
2.4%
Latency: 0.02 ms
Rows In/Out: 2
Data Vol: 40 B
📁 memory.main.bom_parts
1.2%
Latency: 0.01 ms
Rows In/Out: 2
Data Vol: 4,144 B
📁 Projections: ['child_part', 'tot...
14.0%
Latency: 0.11 ms
Rows In/Out: 2
Data Vol: 4,152 B
0.5%
Latency: 0.00 ms
Rows In/Out: 4
Data Vol: 96 B
0.8%
Latency: 0.01 ms
Rows In/Out: 4
Data Vol: 144 B
📁 memory.main.bom_parts
| Operator | Cost % | Latency | Processed Rows | Data Volume | Details / Table | Status |
|---|---|---|---|---|---|---|
| RECURSIVE_CTE | 65.2% | 0.50 ms | 4 | 0.00 MB | - | Normal |
| ORDER_BY | 15.8% | 0.12 ms | 4 | 0.00 MB | - | Normal |
| HASH_JOIN | 14.0% | 0.11 ms | 2 | 0.00 MB | - | Normal |
| TABLE_SCAN | 2.4% | 0.02 ms | 2 | 0.00 MB | memory.main.bom_parts | Normal |
| PROJECTION | 1.2% | 0.01 ms | 2 | 0.00 MB | Projections: ['child_part', 'total_qty', 'depth' | Normal |
| TABLE_SCAN | 0.8% | 0.01 ms | 4 | 0.00 MB | memory.main.bom_parts | Normal |
| RECURSIVE_CTE_SCAN | 0.5% | 0.00 ms | 4 | 0.00 MB | - | Normal |
| PROJECTION | 0.1% | 0.00 ms | 2 | 0.00 MB | Projections: ['child_part', 'total_qty', 'depth' | Normal |
4. Queries Executed (Candidate vs Golden Ground Truth)
Beautified & Syntax HighlightedWITH RECURSIVE bom_tree AS
(-- Anchor: Top-level components of EV_CAR
SELECT parent_part,
child_part,
quantity_needed AS total_qty,
1 AS depth
FROM bom_parts
WHERE parent_part = 'EV_CAR'
UNION ALL -- Recursive: Multiply quantity down the hierarchy tree
SELECT t.child_part AS parent_part,
b.child_part,
t.total_qty * b.quantity_needed AS total_qty,
t.depth + 1 AS depth
FROM bom_tree t
JOIN bom_parts b ON t.child_part = b.parent_part)
SELECT child_part,
total_qty,
depth
FROM bom_tree
ORDER BY depth,
child_part;
-- Recursively expand BOM tree to compute total quantity of base components
WITH RECURSIVE bom_tree AS
(-- Anchor: Top-level components of EV_CAR
SELECT parent_part,
child_part,
quantity_needed AS total_qty,
1 AS depth
FROM bom_parts
WHERE parent_part = 'EV_CAR'
UNION ALL -- Recursive: Multiply quantity down the hierarchy tree
SELECT t.child_part AS parent_part,
b.child_part,
t.total_qty * b.quantity_needed AS total_qty,
t.depth + 1 AS depth
FROM bom_tree t
JOIN bom_parts b ON t.child_part = b.parent_part)
SELECT child_part,
total_qty,
depth
FROM bom_tree
ORDER BY depth,
child_part;
CREATE TABLE bom_parts (parent_part VARCHAR, child_part VARCHAR, quantity_needed INT, unit_cost decimal(10, 2));
INSERT INTO bom_parts
VALUES ('EV_CAR', 'CHASSIS', 1, 5000.00),
('EV_CAR', 'BATTERY_PACK', 1, 0.00),
('BATTERY_PACK', 'BATTERY_MODULE', 4, 0.00),
('BATTERY_MODULE', 'LITHIUM_CELL', 100, 15.00);
5. Query Results & Expected Ground Truth
Tabular Comparison
Actual Candidate Output
(4 rows × 3 cols)
| # | child_part | total_qty | depth |
|---|---|---|---|
| 1 | BATTERY_PACK | 1 | 1 |
| 2 | CHASSIS | 1 | 1 |
| 3 | BATTERY_MODULE | 4 | 2 |
| 4 | LITHIUM_CELL | 400 | 3 |
Expected Golden Output
(4 rows × 3 cols)
| # | child_part | total_qty | depth |
|---|---|---|---|
| 1 | BATTERY_PACK | 1 | 1 |
| 2 | CHASSIS | 1 | 1 |
| 3 | BATTERY_MODULE | 4 | 2 |
| 4 | LITHIUM_CELL | 400 | 3 |