Filter by ORDER BY Fields
Tables are sorted by their ORDER BY columns. Filtering on these makes queries much faster. markets:ORDER BY (platform, id)
fills: ORDER BY (platform, market_id, timestamp, id)
orderbook_snapshots: ORDER BY (market_id, outcome.id, timestamp, hash, state, continuity, path_index)
Use the leftmost applicable sort-key columns and a time bound whenever possible. Time bounds reduce work even when the time column is not part of the leading sort-key prefix.
Examples
Always Filter markets by market_type
Kalshi combo markets (market_type = 'PARLAY') are over 90% of the markets table. Any query that does not filter market_type reads them all.
JOIN markets loads the whole table into memory before matching; filter it in a subquery first.
Common Mistakes
Always Use LIMIT
Avoid loading millions of rows unintentionally—it’s slow and wastes resources.Don’t Overuse FINAL
FINAL forces immediate deduplication and is significantly slower. Use it only for counts/aggregations where exact results matter.
Select Only What You Need
Working with large datasets
- Filter by date and other sorting-key columns.
- Aggregate in ClickHouse before returning rows.
- Split large raw-data reads into smaller time ranges.
Quick Tips
Percentilescontinuity is RESET, use that row as a fresh starting point. Do not forward-fill from the preceding row.