Skip to main content
Performance tips and common mistakes to avoid.

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

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

Percentiles
Cardinality estimates
Unnest outcomes array
Best bid/ask from orderbook
When continuity is RESET, use that row as a fresh starting point. Do not forward-fill from the preceding row.