Home / Companies / QuestDB / Blog / Post Details
Content Deep Dive

From 3 Seconds to 38 Milliseconds: Why SAMPLE BY Order Matters

Blog post from QuestDB

Post Details
Company
Date Published
Author
Javier Ramirez
Word Count
1,306
Company Posts That Month
6
Language
English
Hacker News Points
-
Post removed?
No
Summary

The text explores the optimization of SQL queries for calculating realized volatility, a crucial metric for options strategies like gamma scalping, by reorganizing query operations to significantly improve performance. Initially, a query on QuestDB to compute annualized realized volatility from market data ran in 3 seconds, which was reduced to 38 milliseconds by restructuring the order of operations—specifically, by aggregating data with SAMPLE BY before applying window functions. This change reduced the dataset size processed by expensive operations, resulting in an 80x performance improvement. The example underscores the importance of structuring queries to aggregate data before applying window functions, particularly in high-frequency data environments, and demonstrates how a simple adjustment in SQL query design can lead to substantial efficiency gains. The guide also highlights the use of a WINDOW clause for better readability and the employment of mathematical identities to overcome limitations in available functions.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
Kubernetes 1 1,840 308 106 +33%
Real-time 1 6,457 1,307 242 +28%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.