✖ SHAPE_MISMATCH
Warehouse & Statistical
task_120_market_basket_lift_smoothing
Scaled: 1M+ Records
Ordered: Yes
Association Rule Lift Matrix with Directional Pair Evaluation
Candidate Latency (1M Rows)
112.74 ms
(1.2x faster than golden)
Golden Latency (1M Rows)
134.47 ms
DuckDB in-memory engine
Underlying Data Volume
1,000,000 rows
22.9 MiB across 1 table
Evaluated Model
gemini-3.8-flash-low
Gen Latency: 5.4s
⚠️ Failure Analysis (SHAPE_MISMATCH)
Reason: Shape mismatch: Expected 4 rows x 5 cols, got 8 rows x 5 cols
- Expected Shape: 4 rows × 5 cols | Actual: 8 rows × 5 cols
- Row Inflation: 8 vs 4 (likely missing filter, cross-product or Cartesian explosion)
1. Analytical Significance & What It Means
Scenario & Frontier TrapBusiness Scenario & Problem
Calculates market basket association rule Lift for directional product pairs (A -> B), correctly eliminating self-pairs and evaluating directional confidence.
⚡ The Frontier Trap (Why LLMs Fail)
Naive models omit self-pair elimination (producing trivial rules like Bread -> Bread with 100% confidence), fail to normalize by total baskets, or confuse raw co-occurrence counts with statistical Lift.
Prompt / User Request Given to Model
Compute Support, Confidence, and Lift for directional association rules (Item A -> Item B): - Support(A -> B) = Count(Transactions containing both A and B) / Total Transactions - Confidence(A -> B) = Count(Transactions containing both A and B) / Count(Transactions containing A) - Lift(A -> B) = Confidence(A -> B) / (Count(Transactions containing B) / Total Transactions) Ensure self-pairs (A -> A) are excluded. Required output columns: - item_a (VARCHAR) - item_b (VARCHAR) - support (DOUBLE) - confidence (DOUBLE) - lift (DOUBLE) Order by lift DESC, item_a ASC, item_b ASC.
2. Underlying Tables, Row Counts & Data Volume
1 Tables (1,000,000 rows • 22.9 MiB)Production-scale fixtures loaded into the isolated DuckDB sandbox with at least 1,000,000 records per table:
📊 market_baskets
1,000,000 rows
22.9 MiB Data Volume
basket_id (INTEGER) item_name (VARCHAR)Data Preview (showing sample rows from 1,000,000 total rows):
| # | basket_id | item_name |
|---|---|---|
| 1 | 1 | Bread |
| 2 | 1 | Butter |
| 3 | 1 | Milk |
| 4 | 2 | Bread |
| 5 | 2 | Butter |
| 6 | 3 | Bread |
| 7 | 3 | Milk |
| 8 | 4 | Beer |
| 9 | 4 | Diapers |
| 10 | 4 | Bread |
| 11 | 5 | Butter |
| 12 | 6 | Milk |
| 13 | 7 | Beer |
| 14 | 8 | Diapers |
| 15 | 9 | Bread |
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:
6.4%
Latency: 20.77 ms
Rows In/Out: 0
Data Vol: 0 B
0.4%
Latency: 1.21 ms
Rows In/Out: 1,000,000
Data Vol: 19.07 MB
📁 Projections: ['#0', '__internal_...
🔥 36.0% Cost
Latency: 116.17 ms
Rows In/Out: 1,000,000
Data Vol: 11.44 MB
0.0%
Latency: 0.09 ms
Rows In/Out: 1,000,000
Data Vol: 11.44 MB
📁 Projections: ['basket_id', 'item...
1.0%
Latency: 3.31 ms
Rows In/Out: 1,000,000
Data Vol: 11.44 MB
📁 Projections: ['#0', '__internal_...
3.8%
Latency: 12.21 ms
Rows In/Out: 1,000,000
Data Vol: 19.07 MB
📁 memory.main.market_baskets
0.0%
Latency: 0.03 ms
Rows In/Out: 0
Data Vol: 0 B
0.0%
Latency: 0.00 ms
Rows In/Out: 5
Data Vol: 120 B
📁 Projections: ['item_name', 'item...
0.0%
Latency: 0.01 ms
Rows In/Out: 5
Data Vol: 120 B
📁 Projections: ['__internal_decomp...
2.7%
Latency: 8.75 ms
Rows In/Out: 5
Data Vol: 80 B
0.0%
Latency: 0.08 ms
Rows In/Out: 1,000,000
Data Vol: 7.63 MB
📁 Projections: item_name
1.0%
Latency: 3.15 ms
Rows In/Out: 1,000,000
Data Vol: 7.63 MB
📁 Projections: __internal_compress...
0.0%
Latency: 0.03 ms
Rows In/Out: 1,000,000
Data Vol: 19.07 MB
0.0%
Latency: 0.00 ms
Rows In/Out: 12
Data Vol: 672 B
📁 Projections: ['__internal_decomp...
0.0%
Latency: 0.13 ms
Rows In/Out: 12
Data Vol: 480 B
0.0%
Latency: 0.01 ms
Rows In/Out: 12
Data Vol: 480 B
📁 Projections: ['__internal_compre...
0.0%
Latency: 0.00 ms
Rows In/Out: 12
Data Vol: 672 B
📁 Projections: ['item_a', 'item_b'...
0.0%
Latency: 0.00 ms
Rows In/Out: 12
Data Vol: 768 B
📁 Projections: ['item_a', 'item_b'...
0.0%
Latency: 0.10 ms
Rows In/Out: 12
Data Vol: 768 B
0.0%
Latency: 0.09 ms
Rows In/Out: 12
Data Vol: 672 B
0.0%
Latency: 0.05 ms
Rows In/Out: 12
Data Vol: 576 B
0.0%
Latency: 0.00 ms
Rows In/Out: 12
Data Vol: 480 B
📁 Projections: ['item_a', 'item_b'...
0.0%
Latency: 0.01 ms
Rows In/Out: 12
Data Vol: 480 B
📁 Projections: ['__internal_decomp...
0.2%
Latency: 0.68 ms
Rows In/Out: 12
Data Vol: 288 B
0.0%
Latency: 0.00 ms
Rows In/Out: 16
Data Vol: 256 B
📁 Projections: ['item_name', 'item...
0.0%
Latency: 0.01 ms
Rows In/Out: 16
Data Vol: 256 B
📁 Projections: ['__internal_compre...
🔥 27.3% Cost
Latency: 88.29 ms
Rows In/Out: 16
Data Vol: 512 B
0.2%
Latency: 0.80 ms
Rows In/Out: 1,000,000
Data Vol: 19.07 MB
0.3%
Latency: 0.83 ms
Rows In/Out: 1,000,000
Data Vol: 19.07 MB
0.0%
Latency: 0.00 ms
Rows In/Out: 1
Data Vol: 8 B
📁 Projections: total_baskets
0.0%
Latency: 0.06 ms
Rows In/Out: 1
Data Vol: 8 B
🔥 20.2% Cost
Latency: 65.33 ms
Rows In/Out: 999,994
Data Vol: 3.81 MB
0.0%
Latency: 0.09 ms
Rows In/Out: 1,000,000
Data Vol: 3.81 MB
📁 Projections: basket_id
0.2%
Latency: 0.72 ms
Rows In/Out: 1,000,000
Data Vol: 3.81 MB
📁 memory.main.market_baskets
0.0%
Latency: 0.01 ms
Rows In/Out: 5
Data Vol: 120 B
0.0%
Latency: 0.00 ms
Rows In/Out: 5
Data Vol: 120 B
| Operator | Cost % | Latency | Processed Rows | Data Volume | Details / Table | Status |
|---|---|---|---|---|---|---|
| HASH_GROUP_BY | 36.0% | 116.17 ms | 1,000,000 | 11.44 MB | - | 🔥 BOTTLENECK |
| HASH_JOIN | 27.3% | 88.29 ms | 16 | 0.00 MB | - | 🔥 BOTTLENECK |
| HASH_GROUP_BY | 20.2% | 65.33 ms | 999,994 | 3.81 MB | - | 🔥 BOTTLENECK |
| CTE | 6.4% | 20.77 ms | 0 | 0.00 MB | - | Normal |
| TABLE_SCAN | 3.8% | 12.21 ms | 1,000,000 | 19.07 MB | memory.main.market_baskets | Normal |
| HASH_GROUP_BY | 2.7% | 8.75 ms | 5 | 0.00 MB | - | Normal |
| PROJECTION | 1.0% | 3.31 ms | 1,000,000 | 11.44 MB | Projections: ['#0', '__internal_compress_string_ | Normal |
| PROJECTION | 1.0% | 3.15 ms | 1,000,000 | 7.63 MB | Projections: __internal_compress_string_ubigint( | Normal |
| PROJECTION | 0.4% | 1.21 ms | 1,000,000 | 19.07 MB | Projections: ['#0', '__internal_decompress_strin | Normal |
| CTE_SCAN | 0.3% | 0.83 ms | 1,000,000 | 19.07 MB | - | Normal |
| CTE_SCAN | 0.2% | 0.80 ms | 1,000,000 | 19.07 MB | - | Normal |
| TABLE_SCAN | 0.2% | 0.72 ms | 1,000,000 | 3.81 MB | memory.main.market_baskets | Normal |
| HASH_GROUP_BY | 0.2% | 0.68 ms | 12 | 0.00 MB | - | Normal |
| ORDER_BY | 0.0% | 0.13 ms | 12 | 0.00 MB | - | Normal |
| HASH_JOIN | 0.0% | 0.10 ms | 12 | 0.00 MB | - | Normal |
| HASH_JOIN | 0.0% | 0.09 ms | 12 | 0.00 MB | - | Normal |
| PROJECTION | 0.0% | 0.09 ms | 1,000,000 | 3.81 MB | Projections: basket_id | Normal |
| PROJECTION | 0.0% | 0.09 ms | 1,000,000 | 11.44 MB | Projections: ['basket_id', 'item_name'] | Normal |
| PROJECTION | 0.0% | 0.08 ms | 1,000,000 | 7.63 MB | Projections: item_name | Normal |
| UNGROUPED_AGGREGATE | 0.0% | 0.06 ms | 1 | 0.00 MB | - | Normal |
| CROSS_PRODUCT | 0.0% | 0.05 ms | 12 | 0.00 MB | - | Normal |
| CTE | 0.0% | 0.03 ms | 0 | 0.00 MB | - | Normal |
| CTE_SCAN | 0.0% | 0.03 ms | 1,000,000 | 19.07 MB | - | Normal |
| PROJECTION | 0.0% | 0.01 ms | 16 | 0.00 MB | Projections: ['__internal_compress_string_ubigin | Normal |
| PROJECTION | 0.0% | 0.01 ms | 12 | 0.00 MB | Projections: ['__internal_compress_string_ubigin | Normal |
| PROJECTION | 0.0% | 0.01 ms | 12 | 0.00 MB | Projections: ['__internal_decompress_string(#0)' | Normal |
| PROJECTION | 0.0% | 0.01 ms | 5 | 0.00 MB | Projections: ['__internal_decompress_string(#0)' | Normal |
| CTE_SCAN | 0.0% | 0.01 ms | 5 | 0.00 MB | - | Normal |
| CTE_SCAN | 0.0% | 0.00 ms | 5 | 0.00 MB | - | Normal |
| PROJECTION | 0.0% | 0.00 ms | 12 | 0.00 MB | Projections: ['item_a', 'item_b', 'pair_count'] | Normal |
| PROJECTION | 0.0% | 0.00 ms | 12 | 0.00 MB | Projections: ['item_a', 'item_b', 'pair_count', | Normal |
| PROJECTION | 0.0% | 0.00 ms | 5 | 0.00 MB | Projections: ['item_name', 'item_count'] | Normal |
| PROJECTION | 0.0% | 0.00 ms | 12 | 0.00 MB | Projections: ['item_a', 'item_b', 'support', 'co | Normal |
| PROJECTION | 0.0% | 0.00 ms | 1 | 0.00 MB | Projections: total_baskets | Normal |
| PROJECTION | 0.0% | 0.00 ms | 16 | 0.00 MB | Projections: ['item_name', 'item_name'] | Normal |
| PROJECTION | 0.0% | 0.00 ms | 12 | 0.00 MB | Projections: ['__internal_decompress_string(#0)' | Normal |
4. Queries Executed (Candidate vs Golden Ground Truth)
Beautified & Syntax HighlightedWITH basket_summary AS
(SELECT count(DISTINCT basket_id)::DOUBLE AS total_baskets
FROM market_baskets),
distinct_basket_items AS
(SELECT DISTINCT basket_id,
item_name
FROM market_baskets),
item_counts AS
(SELECT item_name,
count(basket_id)::DOUBLE AS item_count
FROM distinct_basket_items
GROUP BY item_name),
pair_counts AS
(SELECT a.item_name AS item_a,
b.item_name AS item_b,
count(a.basket_id)::DOUBLE AS pair_count
FROM distinct_basket_items a
JOIN distinct_basket_items b ON a.basket_id = b.basket_id
AND a.item_name != b.item_name
GROUP BY a.item_name,
b.item_name)
SELECT p.item_a,
p.item_b,
p.pair_count / bs.total_baskets AS support,
p.pair_count / ca.item_count AS confidence,
(p.pair_count / ca.item_count) / (cb.item_count / bs.total_baskets) AS lift
FROM pair_counts p
CROSS JOIN basket_summary bs
JOIN item_counts ca ON p.item_a = ca.item_name
JOIN item_counts cb ON p.item_b = cb.item_name
ORDER BY lift DESC,
p.item_a ASC,
p.item_b ASC;
WITH total_orders AS
(SELECT count(DISTINCT basket_id) AS total_baskets
FROM market_baskets),
item_frequencies AS
(SELECT item_name,
count(DISTINCT basket_id) AS item_baskets
FROM market_baskets
GROUP BY item_name),
pair_occurrences AS
(SELECT a.item_name AS item_a,
b.item_name AS item_b,
count(DISTINCT a.basket_id) AS pair_baskets
FROM market_baskets a
JOIN market_baskets b ON a.basket_id = b.basket_id
AND a.item_name != b.item_name
GROUP BY a.item_name,
b.item_name)
SELECT p.item_a,
p.item_b,
round(p.pair_baskets * 1.0 / t.total_baskets, 4) AS support,
round(p.pair_baskets * 1.0 / fa.item_baskets, 4) AS confidence,
round((p.pair_baskets * 1.0 * t.total_baskets) / (fa.item_baskets * fb.item_baskets), 4) AS lift
FROM pair_occurrences p
JOIN item_frequencies fa ON p.item_a = fa.item_name
JOIN item_frequencies fb ON p.item_b = fb.item_name
CROSS JOIN total_orders t
WHERE p.pair_baskets >= 2
ORDER BY lift DESC,
p.item_a ASC,
p.item_b ASC;
CREATE TABLE market_baskets (basket_id INT, item_name VARCHAR);
INSERT INTO market_baskets
VALUES (1, 'Bread'),
(1, 'Butter'),
(1, 'Milk'),
(2, 'Bread'),
(2, 'Butter'),
(3, 'Bread'),
(3, 'Milk'),
(4, 'Beer'),
(4, 'Diapers');
5. Query Results & Expected Ground Truth
Tabular Comparison
Actual Candidate Output
(12 rows × 5 cols)
| # | item_a | item_b | support | confidence | lift |
|---|---|---|---|---|---|
| 1 | Bread | Butter | 0 | 0 | 0 |
| 2 | Bread | Milk | 0 | 0 | 0 |
| 3 | Butter | Bread | 0 | 0 | 0 |
| 4 | Milk | Bread | 0 | 0 | 0 |
| 5 | Beer | Diapers | 0 | 0 | 0 |
| 6 | Diapers | Beer | 0 | 0 | 0 |
| 7 | Butter | Milk | 0 | 0 | 0 |
| 8 | Milk | Butter | 0 | 0 | 0 |
| 9 | Beer | Bread | 0 | 0 | 0 |
| 10 | Bread | Beer | 0 | 0 | 0 |
| 11 | Bread | Diapers | 0 | 0 | 0 |
| 12 | Diapers | Bread | 0 | 0 | 0 |
Expected Golden Output
(4 rows × 5 cols)
| # | item_a | item_b | support | confidence | lift |
|---|---|---|---|---|---|
| 1 | Bread | Butter | 0 | 0 | 0 |
| 2 | Bread | Milk | 0 | 0 | 0 |
| 3 | Butter | Bread | 0 | 0 | 0 |
| 4 | Milk | Bread | 0 | 0 | 0 |