Troubleshooting
Why Ignition trend queries slow on a growing TimescaleDB historian
Short answer
The slow query is Ignition's LIMIT 1 seeding lookup for live trends; on TimescaleDB it crawls when the hypertable lacks a usable t_stamp index, not because the database must read all 100 GB. Verify with EXPLAIN ANALYZE, add the right index, and leave the sqlth_partitions flags column alone: one case sped queries from 5 seconds to under 1 but made zoomed Vision graphs choppy.
On this page
- What the one-row query on sqlth_1_data does
- Why a one-row result can still cost seconds
- How TimescaleDB chunk pruning is supposed to skip history
- Diagnose the slow trend with EXPLAIN ANALYZE
- Fix the timestamp index, not the partition metadata
- Why the flags shortcut makes graphs choppy
- The decision for each case
- Questions asked
On an Ignition historian running on TimescaleDB, the query that slows trends down is the one-row seeding lookup Ignition issues beside every live trend request: it returns the first stored sample after the trend window's boundary. When the hypertable has no usable index on t_stamp, the database reads and sorts candidate rows to find that single row, and every trend open pays for it. TimescaleDB already skips whole chunks whose time range cannot match the timestamp condition, so an execution plan that walks the full history signals an index or partitioning problem, not a TimescaleDB limit. Diagnose with EXPLAIN ANALYZE, add the right timestamp index, and confirm the trend still draws the same samples. Do not edit the flags column of the partition table: a reported speedup from that change came with choppy zoomed Vision graphs.
What the one-row query on sqlth_1_data does #
When a Vision trend opens on live data, Ignition's tag historian issues two statements: the main query for the window's samples, and this one-row lookup, visible in the database status view:
SELECT "tagid","intvalue","floatvalue","stringvalue","datevalue","t_stamp","dataintegrity"
FROM sqlth_1_data
WHERE "tagid" IN (?,?) and "t_stamp" > ?
ORDER BY "t_stamp" ASC
LIMIT 1
Read the shape. Two tag IDs arrive as bound parameters, t_stamp must be strictly greater than a supplied timestamp, there is no upper bound on t_stamp, and LIMIT 1 applies to the whole ordered result, not once per tag. The statement returns the first stored sample after that boundary — the seeding value the trend needs at its leading edge. The window query fetches the samples inside the displayed range; this lookup is part of the trend's data, so it cannot be dropped without losing that edge.
The question marks are bound parameters. A literal copy of the statement pasted into a SQL editor is not a reproduction unless your tool binds the same values with the same database types; take the two tag IDs from the historian's tag table (sqlth_te) and note the boundary timestamp exactly as issued.
LIMIT 1 says nothing about cost. The database does whatever work the plan requires before it can name the one row.
Why a one-row result can still cost seconds #
The expensive part is finding the first qualifying row, not returning it. Two plan shapes produce the reported slowdown, and both worsen as history accumulates:
- A tagid-only index: the planner fetches every stored row for the two tags across every chunk after the boundary — the predicate has no upper bound — then sorts them by t_stamp and keeps one. The sort input grows with the tags' full history, which matches trends that decay as the historian grows.
- No usable index at all: the executor scans every chunk whose range satisfies the timestamp predicate, applies the tagid filter row by row, and sorts whatever survives.
Worked example: from row rate to seconds #
The inputs below are example values for a mid-size line, not measurements; your plan is the evidence that counts.
Assume 200 tags averaging one stored row every 5 seconds after Ignition's deadband compression — 40 stored rows plant-wide per second — and a 24 h trend window opened a full day after its boundary. Candidate rows from the boundary to now: 40 rows/s × 86,400 s = 3,456,000 rows. At a representative scan-and-filter rate of 700,000 rows/s, one trend open costs 3,456,000 ÷ 700,000 ≈ 4.9 s — the same order as the 5 seconds reported for this fault. The same rate fills storage quickly: 3,456,000 rows/day × 365 days ≈ 1.26 billion rows, about 100 GB at an example 80 bytes per stored row (1.26 billion × 80 B ≈ 101 GB). With the index described below, the same lookup reads a few index pages and returns in single-digit milliseconds. Hardware moves the scan rate; only the execution plan tells you which side of that divide your historian is on.
How TimescaleDB chunk pruning is supposed to skip history #
A hypertable presents one logical table to SQL while TimescaleDB stores the rows in chunks; by default each chunk holds 7 days unless you changed the chunk interval. The planner excludes chunks whose time ranges cannot satisfy a predicate on the partitioning column: for t_stamp greater than the boundary, every chunk lying entirely before it is skipped without being read. Because the seeding statement has no upper bound, all newer chunks remain candidates, and an index decides how expensive the first-row search inside them is.
That design answers the reported fear directly: TimescaleDB does not scan the entire history for this query when the table is a hypertable on t_stamp and the plan is sound. If your EXPLAIN output lists every chunk, suspect the partitioning first — confirm that sqlth_1_data was created as a hypertable partitioned on t_stamp, using the database's hypertable information views — and only then look at indexes.
Keep Ignition's own partition tables out of this picture. sqlth_partitions maps time ranges to data tables, with end_time stored as a Unix timestamp in milliseconds; against TimescaleDB you should find a single partition row covering the whole history, because pruning happens per chunk inside TimescaleDB, not per Ignition partition. Table names carry the historian profile's prefix: the reported configuration showed sqlth_1_data in the slow query and sqlth_1_partitions edited by hand, so inspect your own schema and match the names rather than assuming.
If you are still choosing a backend rather than repairing one, carry these chunking and indexing expectations into evaluating the Ignition historian with TimescaleDB for your plant.
Diagnose the slow trend with EXPLAIN ANALYZE #
Run the diagnosis against the exact statement, with the exact bound values:
- Open the trend that renders slowly and read the statement and its execution time from the database status view, so you diagnose what Ignition actually sends.
- Collect the bound values: the two tag IDs from sqlth_te and the boundary timestamp, keeping their database types when you substitute them.
- Run EXPLAIN first for the estimated plan; then run EXPLAIN ANALYZE once at a quiet time, with the literals in place of the question marks.
- Read three things from the plan: how many chunk scans appear, whether a sort node feeds the LIMIT, and how many rows the filter removes on the way to the first match.
- Repeat the identical statement after any change. A fix is proven by the same bound values returning in milliseconds with the same rows, not by the trend feeling faster.
EXPLAIN ANALYZE really executes the statement against the production historian, so run it off-peak, once, and never while the line is logging.
Fix the timestamp index, not the partition metadata #
The first index to add is a BRIN index on t_stamp. Historian tables are append-mostly: rows land on disk in timestamp order, so block ranges map cleanly to time ranges, and BRIN stores only a minimum and maximum per range — it stays tiny where a full index on a billion-row table would not. That property is what lets the executor skip past history the boundary timestamp makes irrelevant and stop at the first page that can contain the answer.
BRIN pays only while the physical order holds. Bulk backfills or imported history drop old rows into new pages and break the time-order assumption; in that case, use a b-tree that covers the tag id and t_stamp columns instead, and accept its maintenance cost.
Verify, then accept:
- The plan shows only the chunks the window can touch, with no sort node feeding the LIMIT.
- Rows removed by filter collapse toward zero and execution time lands in milliseconds.
- The returned tagid, t_stamp and dataintegrity values match the pre-change statement exactly, sample for sample.
If the historian keeps growing anyway, attack volume as its own task. Configure pruning of old data partitions before capacity forces your hand. Reducing stored historian data older than six months to ten seconds shrinks every future window query by the same token.
Why the flags shortcut makes graphs choppy #
In the reported case, setting the flags column to 1 in the partition table moved trend queries from 5 seconds to under 1 second — and zoomed Vision graphs turned choppy. Both facts matter together: a change that alters rendering changed which samples the trend retrieves, not only how fast the database answered. The likely mechanism sits at the window edges, where seeding and boundary handling decide what the chart draws, but the exact behavior is not something to discover on a production historian.
The documented reference for sqlth_partitions describes the table's columns — time ranges mapped to tables, end_time in Unix milliseconds, a blocksize — and the flags column deserves the same discipline: confirm its documented meaning for your installed Ignition version through the vendor's documentation or support before editing it by hand. Set it back to whatever Ignition wrote — null in the reported case — and get the speed from the index instead. Then check both acceptance criteria again: query time in the plan, and rendering while zooming.
The decision for each case #
- Plan lists every chunk despite the t_stamp predicate: the table is not behaving as a hypertable on t_stamp. Fix partitioning first — confirm sqlth_1_data is the hypertable and t_stamp the partitioning column — then re-run the plan before adding any index.
- Plan prunes chunks but shows a sort feeding the LIMIT or millions of rows removed by filter: add the BRIN index on t_stamp; if backfills broke physical order, use the b-tree over the tag id and t_stamp columns. Expect the seeding statement in milliseconds and leave the partition metadata untouched.
- Trends are fast only after flags = 1 and zoomed graphs are choppy: restore the value Ignition wrote, index instead, and re-verify query time and rendering as separate acceptance criteria.
- Plan is clean, indexes exist, and trends still slow as history grows: the stored volume is the workload. Prune old partitions, lower the stored resolution of aged data, and size the disk path for the measured row rate.
Questions asked
Can I stop Ignition from issuing the one-row seeding query?
There is no supported switch that removes it. The statement supplies the sample at the trend window's leading edge, so hiding it costs data, not just speed. Make the statement cheap instead: with a usable t_stamp index it reads a few index pages and returns in milliseconds, and the trend loses nothing.
Should I set the flags column to 1 to speed trends up?
Treat it as unverified. In one reported case it cut query time from 5 seconds to under 1 second, and zoomed Vision graphs turned choppy, which shows the flag changed which samples the trend retrieves. Confirm the flag's documented meaning for your installed Ignition version first; on a production historian, fix the index and leave the metadata as Ignition wrote it.
Does TimescaleDB scan the entire historian for this query?
A correct setup should not. The planner excludes chunks whose time ranges cannot satisfy the t_stamp condition, and the default chunk covers 7 days. If your plan lists every chunk, suspect that the table is not a hypertable partitioned on t_stamp, or that the predicate was altered when the query was copied. Read the plan before blaming the database.
Why BRIN instead of a standard index on t_stamp?
BRIN stores the minimum and maximum timestamp per block range instead of an entry per row, so it stays small on a historian with hundreds of millions of rows. It works when rows sit on disk in timestamp order, which is how append-only logging writes them. Bulk backfills break that order; then a b-tree over the tag id and t_stamp columns is the safer choice.
What proves the index fixed the problem?
Re-run the plan with the same bound tag IDs and timestamp. Chunk scans should shrink to the chunks the window touches, the sort feeding the limit should disappear, and rows removed by filter should fall to nearly zero. The returned timestamps and dataintegrity values must match the pre-change results exactly, and zoomed rendering must look the same.