Joining Time-Series Fact Tables with Dimension Tables in QuestDB
Any time-series system eventually hits this model: a fact table that stores high-rate readings (ticks, sensors, trades) and a dimension table that stores static attributes (device id, instrument, exchange). At query time you want to translate host, symbol, and other keys into human-readable values (device name, instrument, region). Almost every trap lives in how the JOIN is written. This article pins down the correct pattern.
1. What a fact table and a dimension table look like
The fact table is a time-series table with a designated timestamp, written at high rate:
CREATE TABLE trades (
ts timestamp,
symbol symbol index=3,
side symbol,
price double
);
-- ingest (ILP)
-- trades,symbol=EURUSD,side=buy price=1.083 1759603200000000000
The dimension table is not a time-series table — it has no designated timestamp; it is an ordinary reference table:
CREATE TABLE fx_dim (
symbol symbol,
base symbol,
quote symbol,
exchange symbol,
region varchar
);
INSERT INTO fx_dim VALUES
('EURUSD', 'EUR', 'USD', 'EBS', 'EU'),
('EURUSD', 'EUR', 'USD', 'LMAX', 'EU'),
('USDJPY', 'USD', 'JPY', 'EBS', 'APAC');
Key realization: a dimension table is just a regular QuestDB table, and a key-based JOIN needs no timestamps at all. ASOF JOIN is a different thing (two time-series aligned on time) — do not mix the two.
2. Why LEFT JOIN, never INNER, when attaching dimensions
Using INNER JOIN between fact and dimension silently drops data:
-- dangerous: INNER JOIN drops symbols that are missing from fx_dim
SELECT t.ts, t.symbol, t.price, d.exchange, d.region
FROM trades t
JOIN fx_dim d ON (t.symbol = d.symbol)
WHERE t.ts >= ts '2026-10-04T00:00:00Z';
The moment a trade’s symbol (say a newly listed GBPAUD) is not yet in fx_dim, that whole fact row vanishes, with no error. The fact table is the truth; the dimension table is an annotation; a missing annotation must not delete the truth. The correct form:
SELECT t.ts, t.symbol, t.price,
coalesce(d.exchange, 'UNKNOWN') AS exchange,
coalesce(d.region, 'UNKNOWN') AS region
FROM trades t
LEFT JOIN fx_dim d ON (t.symbol = d.symbol)
WHERE t.ts >= ts '2026-10-04T00:00:00Z';
LEFT JOIN keeps every fact row; missing dimensions become UNKNOWN (via coalesce). Aggregations then do not silently lose volume for unlisted instruments.
3. Shaping the dimension table
- Low cardinality, near-static: the dimension table has far fewer rows than the fact table (hundreds to tens of thousands) and changes slowly. If the “dimension” itself changes at high rate, it is really a fact table, not a dimension.
- Key columns should be low-cardinality and indexed:
symbol,host,device_id— use thesymboltype with anindex; QuestDB uses a posting index to speed key matching. The same applies inside the dimension table. - Beware many-to-one dimensions: above,
EURUSDappears twice (EBS and LMAX), so aLEFT JOINfans one trade out into two rows. If the dimension is many-to-one (one instrument, many venues), filter by venue first, or collapse the dimension to one-to-one before joining.
4. Aggregating after the join: reports by human labels
Once joined, reports aggregate by readable dimensions:
SELECT
region,
exchange,
count(*) AS trades,
avg(price) AS avg_price
FROM trades t
LEFT JOIN fx_dim d ON (t.symbol = d.symbol)
SAMPLE BY 1h
FILL(none);
region and exchange come from the dimension table, so aggregation lands on human labels instead of bare symbol. That is the star schema (fact + dimension) inside a time-series database.
5. Where key joins and ASOF joins diverge
- Fact join dimension (this article): keys are equal (
ON (a.symbol = b.symbol)), the dimension has no timestamp — useINNER/LEFT. - Fact join another time-series: two series aligned on timestamp — use
ASOF JOIN(the most recent row not later than the left row) orSPLICE/WINDOW.
QuestDB supports INNER, OUTER (LEFT/RIGHT), CROSS, and the time-series-only ASOF, SPLICE, LT, HORIZON, and WINDOW; FULL JOIN is not yet implemented and is on the roadmap.
Also note: ASOF JOIN assumes both sides are time-ordered; with out-of-order data the result is non-deterministic — out-of-order handling is its own article, see QuestDB out-of-order writes and O3.
6. Pitfall list
INNER JOINto a dimension → fact rows drop silently. UseLEFT JOIN+coalesce.- Many-to-one dimension → duplicate join rows; collapse the dimension first.
- Dimension key not a
symbolwith an index → slow key matching on large tables. - Storing high-rate-changing attributes in the dimension table → it is actually a fact table; the model is wrong.
7. Next steps
- Align two time-series on time (trades × quotes): QuestDB ASOF JOIN guide.
- High-cardinality
symboloptimization: QuestDB SYMBOL type vs VARCHAR.