The Timestamp index accelerates time-based queries by pre-computing and indexing multiple time granularities to optimize filtering and grouping operations.
A timestamp index is a specialized indexing solution that accelerates time-based queries with different time granularities. It’s designed to optimize analytics workflows that involve filtering and grouping by common time dimensions like day, month, or year.
The TIMESTAMP data type in StarTree Cloud stores values as millisecond-precision epoch timestamps (long values). While this high precision is valuable for exact timestamps, it’s often excessive for analytical queries where users typically want to analyze data at coarser time granularities.
Timestamp indexes are particularly valuable for:
dateTrunc()
or dateTimeConvert()
Without a timestamp index, time-based queries require extracting values at query time, applying transformation functions, and then performing filters or group-by operations, which can be computationally expensive for large datasets.
Traditional querying of timestamp data requires time value conversions and transformations to be computed at query time. For example, to group data by month, the system would need to convert each timestamp to its corresponding month for every record in the dataset.
The timestamp index in StarTree Cloud optimizes these operations by:
$${ts_column_name}$${ts_granularity}
.dateTrunc('DAY', timestamp_col)
are automatically rewritten to use the pre-computed columns, dramatically reducing computation overhead.For a timestamp column named event_time
with configured granularities DAY, MONTH, and YEAR:
$event_time$DAY
- containing day-level timestamps$event_time$MONTH
- containing month-level timestamps$event_time$YEAR
- containing year-level timestampsdateTrunc('MONTH', event_time)
, it’s automatically rewritten to use the $event_time$MONTH
column instead of computing this transformation during query execution.dateTrunc('YEAR', event_time) = '2022'
would use the $event_time$YEAR
column’s range index for efficient filtering.To enable a timestamp index on a column in your StarTree Cloud table, add the following configuration to your table definition:
The timestamp index supports the following granularities:
MILLISECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
TIMESTAMP
data type.Mark Needham demos the Timestamp Index