SARGable Temporal Partition Pruning and Exact Boundary Range
1. Analytical Significance & What It Means
Scenario & Frontier TrapTests SARGable timestamp filtering and strict month boundary conditions, preventing full-scan string functions and end-of-interval leaks.
Models frequently write `BETWEEN '2025-01-01' AND '2025-02-01'`, which is inclusive on both ends and mistakenly captures records occurring exactly at midnight on February 1st (leaking records into the previous month's report). Alternatively, models wrap timestamp columns in non-SARGable scalar functions (like strftime or date_part), defeating column min/max partition pruning in columnar engines.
Analyze `system_logs` to calculate the count of ERROR logs and distinct error messages recorded during the calendar month of January 2025. Requirements: 1. Filter for `severity = 'ERROR'`. 2. Filter strictly for events in January 2025 (from 2025-01-01 00:00:00 up to but strictly excluding 2025-02-01 00:00:00). 3. Keep the timestamp predicate SARGable (using direct range comparisons on `event_timestamp`) so that analytical partitions can be pruned. Required output columns: - error_count (BIGINT or INT) - distinct_error_messages (BIGINT or INT) Only a single summary row is returned.
2. Underlying Tables, Row Counts & Data Volume
1 Tables (1,000,000 rows • 53.4 MiB)Production-scale fixtures loaded into the isolated DuckDB sandbox with at least 1,000,000 records per table:
log_id (BIGINT) event_timestamp (TIMESTAMP) severity (VARCHAR) message (VARCHAR)| # | log_id | event_timestamp | severity | message |
|---|---|---|---|---|
| 1 | 1 | 2024-12-31 23:59:59 | ERROR | Disk almost full |
| 2 | 2 | 2025-01-01 00:00:00 | ERROR | Connection timed out |
| 3 | 3 | 2025-01-15 12:30:00 | INFO | Healthcheck OK |
| 4 | 4 | 2025-01-20 18:00:00 | ERROR | Out of memory |
| 5 | 5 | 2025-01-20 19:00:00 | ERROR | Connection timed out |
| 6 | 6 | 2025-02-01 00:00:00 | ERROR | Network unreachable |
| 7 | 6 | 2026-03-01 09:30:00.000003 | ERROR | Disk almost full |
| 8 | 7 | 2026-03-01 09:30:00.000021 | INFO | Connection timed out |
| 9 | 8 | 2026-03-01 09:30:00.000047 | ERROR | Healthcheck OK |
| 10 | 9 | 2026-03-01 09:30:00.000078 | INFO | Out of memory |
| 11 | 10 | 2026-03-01 09:30:00.000085 | ERROR | Network unreachable |
| 12 | 11 | 2026-03-01 09:30:00.000112 | INFO | Disk almost full |
| 13 | 12 | 2026-03-01 09:30:00.000125 | ERROR | Connection timed out |
| 14 | 13 | 2026-03-01 09:30:00.000143 | INFO | Healthcheck OK |
| 15 | 14 | 2026-03-01 09:30:00.000163 | ERROR | Out of memory |
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:
| Operator | Cost % | Latency | Processed Rows | Data Volume | Details / Table | Status |
|---|---|---|---|---|---|---|
| CTE | 44.6% | 0.20 ms | 0 | 0.00 MB | - | Normal |
| HASH_GROUP_BY | 43.6% | 0.20 ms | 2 | 0.00 MB | - | Normal |
| TABLE_SCAN | 6.8% | 0.03 ms | 3 | 0.00 MB | memory.main.system_logs | Normal |
| CROSS_PRODUCT | 2.8% | 0.01 ms | 1 | 0.00 MB | - | Normal |
| UNGROUPED_AGGREGATE | 1.6% | 0.01 ms | 1 | 0.00 MB | - | Normal |
| UNGROUPED_AGGREGATE | 0.3% | 0.00 ms | 1 | 0.00 MB | - | Normal |
| PROJECTION | 0.1% | 0.00 ms | 3 | 0.00 MB | Projections: message | Normal |
| PROJECTION | 0.1% | 0.00 ms | 1 | 0.00 MB | Projections: ['#1', '#0'] | Normal |
| CTE_SCAN | 0.0% | 0.00 ms | 3 | 0.00 MB | - | Normal |
| CTE_SCAN | 0.0% | 0.00 ms | 3 | 0.00 MB | - | Normal |
4. Queries Executed (Candidate vs Golden Ground Truth)
Beautified & Syntax HighlightedSELECT count(*) AS error_count,
count(DISTINCT message) AS distinct_error_messages
FROM system_logs
WHERE severity = 'ERROR'
AND event_timestamp >= TIMESTAMP '2025-01-01 00:00:00'
AND event_timestamp < TIMESTAMP '2025-02-01 00:00:00';
SELECT count(*) AS error_count,
count(DISTINCT message) AS distinct_error_messages
FROM system_logs
WHERE severity = 'ERROR'
AND event_timestamp >= '2025-01-01 00:00:00'
AND event_timestamp < '2025-02-01 00:00:00';
CREATE TABLE system_logs (log_id BIGINT, event_timestamp TIMESTAMP, severity VARCHAR, message VARCHAR);
INSERT INTO system_logs
VALUES (1, '2024-12-31 23:59:59', 'ERROR', 'Disk almost full'),
(2, '2025-01-01 00:00:00', 'ERROR', 'Connection timed out'),
(3, '2025-01-15 12:30:00', 'INFO', 'Healthcheck OK'),
(4, '2025-01-20 18:00:00', 'ERROR', 'Out of memory'),
(5, '2025-01-20 19:00:00', 'ERROR', 'Connection timed out'),
(6, '2025-02-01 00:00:00', 'ERROR', 'Network unreachable');
5. Query Results & Expected Ground Truth
Tabular Comparison| # | error_count | distinct_error_messages |
|---|---|---|
| 1 | 3 | 2 |
| # | error_count | distinct_error_messages |
|---|---|---|
| 1 | 3 | 2 |