Inspect the workload

v3.2.0

See what queries run, how each one reached its rows, how much id space is left, and what the optimizers would do.

In this article

KDBS records how the workload reaches its data and shows it through a set of read-only commands. Use SHOW ACCESS to see which access shapes run, ANALYZE to see how one query ran, SHOW PATTERNS for repeated queries, SHOW BUDGET for id space, SHOW META for instance counters, and SHOW RELAYOUT and SHOW CABIN_OPTIMIZER for what the optimizers see. None of these commands change data or results.

Every SHOW command is a SELECT over one system view, sys.<name>, and replies with a header row and one row per item. You can also query the view directly with SELECT, which lets you pick columns, filter with WHERE, sort with ORDER BY and page with LIMIT and OFFSET. Aggregates and joins over a system view are refused.

All output on this page was produced on the current engine with the sample table passengers(id, name, member, joined_on).

Before you begin

  • With auth = scram, every command on this page needs only the readonly role.
  • Access recording is on by default (access_statistics = on). If it is off, SHOW ACCESS records no new shapes.
  • Run some traffic first. These examples ran each of these queries three times:
SELECT * FROM passengers WHERE id = 2;
SELECT name, member FROM passengers WHERE name = 'Park Jiho';

Step 1: See the access shapes with SHOW ACCESS

SHOW ACCESS lists one row per access shape: the kind of access, the table, and the columns it was keyed or filtered on. It never records values, so WHERE name = 'Park Jiho' and WHERE name = 'Kim Minjun' are one shape.

kdbs> SHOW ACCESS;
rel_oid,rel_name,kind,columns,column_mask,uses,last_seen
4002,accounts,Lookup,id,1,3,1407462378808049
4006,items,Lookup,id,1,4,1407462378808780
4020,airlines,Lookup,id,1,3,1407462387375241
4030,flights,Lookup,id,1,3,1407462393667951
4025,passengers,Lookup,id,1,11,1407462429758620
4025,passengers,FilterScan,name,2,3,1407462429908737

The accounts, items, airlines and flights lines, and eight of the eleven passengers lookups, are foreign-key checks that ran when the sample purchases, flights and tickets rows were loaded.

KindMeaning
LookupA primary-key equality.
ProbeA primary-key probe from a join.
RangeA primary-key range walk.
FilterScanA scan that filters on a non-key column.
ScanA scan with no filter.

A FilterScan with many uses on one column is the signal to consider a secondary index or a Cabin on that column. See CREATE INDEX, DROP INDEX and Cabins.

The data lives in the system relation sys.access_stats, which SELECT reads like a table:

kdbs> SELECT rel_name, kind, columns, uses FROM sys.access_stats WHERE rel_name = 'passengers';
  rel_name        kind  columns  uses
----------  ----------  -------  ----
passengers      Lookup       id    11
passengers  FilterScan     name     3

Step 2: See how one query ran with ANALYZE

Put ANALYZE in front of a SELECT. The query runs normally, and the reply reports what each step did.

kdbs> ANALYZE SELECT name, member FROM passengers WHERE name = 'Park Jiho';
analyze rows=1 class=JoinSelect steps=1 examined=8 pages=1 opens=1 pattern_id=0x1c46798b201cf19f fetch_id=0xd233d3fa77d83084
class=JoinSelect steps=1 hoisted=0
step 0 FilterScan passengers
  filter 0:0.1 = 'Park Jiho'
project name=0:0.1, member=0:0.2
step 0 FilterScan passengers opens=1 examined=8 matched=1 sel=12% pages=1

Read examined against rows: here 8 rows were read to return 1. A primary-key lookup reads only what it returns:

kdbs> ANALYZE SELECT * FROM passengers WHERE id = 2;
analyze rows=1 class=PointSelect steps=1 examined=1 pages=1 opens=1 pattern_id=0x40a5b5e4e01959eb fetch_id=0x9b8e7707127bd8d4
class=PointSelect steps=1 hoisted=0
step 0 Lookup passengers key=2
  filter 0:0.0 = 2
project * (4 column(s) of step 0)
step 0 Lookup passengers opens=1 examined=1 matched=1 sel=100% pages=1 replays=1

replays=1 means the step was served from a Waystone trail recorded by an earlier run. A sort shows as a sort line and sorted= in the header:

kdbs> ANALYZE SELECT name FROM passengers ORDER BY joined_on;
analyze rows=8 class=JoinSelect steps=1 examined=8 pages=1 opens=1 sorted=8 pattern_id=0x77611b1a5c4ad282 fetch_id=0x9e653719ef863c1e
class=JoinSelect steps=1 hoisted=0
step 0 Scan passengers
project name=0:0.1
sort 0:0.3 asc
step 0 Scan passengers opens=1 examined=8 matched=8 sel=100% pages=1

ANALYZE works only on SELECT. Wrapping a write is refused with ERR expected a SELECT statement. See ANALYZE.

Step 3: See repeated queries with SHOW PATTERNS

A pattern is a query’s shape with its values left out. The engine registers a pattern from traffic and may record a Waystone trail for it, so a repeated lookup can skip the search. You cannot declare a pattern yourself.

kdbs> SHOW PATTERNS;
oid,fetch_id,fingerprint_version,stmt_class,origin,pinned,use_count,last_seen,waystone_root,dir_depth
1,11209027394830325972,2,1,auto,0,0,0,157,1

Match a row to a query by fetch_id. Integers in system views are unsigned and print in decimal, while ANALYZE prints fetch_id in hex: 11209027394830325972 is 0x9b8e7707127bd8d4, the id = 2 lookup above. In this run only the primary-key lookup was registered, not the filter scan. use_count and last_seen read 0 by design: running a pattern writes its trail, not its row.

The same data is readable with SELECT:

kdbs> SELECT fetch_id, stmt_class, use_count, waystone_root FROM sys.patterns;
            fetch_id  stmt_class  use_count  waystone_root
--------------------  ----------  ---------  -------------
11209027394830325972           1          0            157

An aggregate over a system view is refused:

kdbs> SELECT COUNT(*) FROM sys.patterns;
ERR aggregation over a catalog view (sys.patterns) is not supported; a view's rows do not come from a step chain

See Waystone trails.

Step 4: Check id space with SHOW BUDGET

Every table has a 48-bit id space, [1, 281474976710655]. SHOW BUDGET shows how much each table has used, system tables included. budget_used_ppm is the share used in parts per million, and budget_warning and budget_exhausted are 1 for a table past the warning level or with no ids left.

kdbs> SHOW BUDGET;
oid,name,next_id,ids_issued,ids_remaining,budget_used_ppm,budget_warning,budget_exhausted
100,types,1,0,281474976710655,0,0,0
...
4020,airlines,4,3,281474976710652,0,0,0
4025,passengers,9,8,281474976710647,0,0,0
4030,flights,5,4,281474976710651,0,0,0
4039,tickets,10,9,281474976710646,0,0,0

The budget is measured from the table’s high-water mark, not its row count. A table fed sparse, large keys uses up its space with fewer rows. DESCRIBE <table> shows the same numbers for one table as next_id, ids_issued, ids_remaining and budget_used.

Step 5: Read instance counters with SHOW META

SHOW META returns one row per field, as section,field,value. The sections include volume, cabin_optimizer, cabins, allocation, pool, undo, wal, sched, checkpoint, recovery, backup, lock_waits and contention. An excerpt:

kdbs> SHOW META;
section,field,value
volume,version,28
volume,wal_topology,single
...
allocation,pages_allocated,43
allocation,pages_freed,0
...
pool,pool_hits,902
pool,pool_misses,42
...
wal,wal_durable_lsn,49648
wal,wal_mean_group_batch,1.000
...

Read one section with SELECT field, value FROM sys.meta WHERE section = 'pool'. WHERE on sys.meta takes AND-joined comparisons; OR, NOT, IN lists and LIKE over a system view are refused.

Fields worth watching:

FieldTells you
pool_hits, pool_misses, pool_resident, pool_budgetBuffer pool use against buffer_pool_frames.
wal_mean_group_batchCommits per log sync. 1.000 means every commit paid for its own sync.
wal_durable_lsnThe end of the durable log. Note it before an operation you may want to undo; see Back up and restore.
wal_stoppedPresent, with value 1, after a failed log write has stopped all writes.
pages_allocated, pages_freed, pages_reused, reclaim_pendingPage reclaim after DROP TABLE. The data file never shrinks.
recovery_*What the last mount’s recovery did.
contention_*Waits between cores, summed over every core.

On an instance with several cores, read the WAL fields on core 0, which owns the log.

Lock waits and statement costs

Two more system views record what the workload cost:

  • sys.lock_waits: one row for every lock wait that parked, written when the wait ends, with the core, the time waited, the lock unit and mode, the waiting and holding transactions, and the outcome.
  • sys.statement_stats: one row per statement shape and kind, with calls, refused, total_us, max_us, first and last seen, and the shape’s text.
kdbs> SELECT * FROM sys.lock_waits;
seq  core  started  waited_us  unit  mode  rel_oid  key  waiter_trx  holder_trx  outcome
---  ----  -------  ---------  ----  ----  -------  ---  ----------  ----------  -------

An empty result means no wait parked. The lock_waits and statement_stats sections of SHOW META count rows the views overwrote or dropped.

Step 6: See what the optimizers would do

SHOW RELAYOUT

The physical optimizer runs in shadow mode by default: it plans and reports, and moves nothing. SHOW RELAYOUT weighs the access shapes per table. SHOW RELAYOUT <table> reports one table.

kdbs> SHOW RELAYOUT passengers;
name,clustered,shapes,walk_weight_q8,survey_pages,survey_live,survey_delete_marked,survey_tuples_per_page,plan,blocked_on,surveyed,predicted_pages_saved,predicted_benefit,measured_pages_saved
passengers,btree,3,1280,NULL,NULL,NULL,NULL,none,btree-outside-v1-mover-scope,NULL,NULL,NULL,NULL
  • shapes counts the table’s access shapes (SHOW ACCESS lists them). walk_weight_q8 is a decayed weight in fixed point: 256 is a weight of 1.0. Weights halve after decay_half_life seconds (default 600) without use.
  • plan is none and blocked_on is btree-outside-v1-mover-scope: no relayout plan exists for a B+ tree table in this version. It is not a health check.
  • With physical_optimizer = off, the command is refused: ERR sys.relayout has no plans to report: the physical optimizer is off (physical_optimizer=off) (byte 5).

Not built yet: a mover. No relayout plan is ever carried out. See Physical optimizer.

SHOW CABIN_OPTIMIZER

The Cabin optimizer can create and drop Cabins on its own for columns declared CABIN AUTO. It is off by default.

kdbs> SHOW CABIN_OPTIMIZER;
rel_oid,rel_name,column,state,cabin_id,pages,streak,benefit_q16,cost_q16,hint_fail_pct,coverage_miss_pct,last_action,reason,epoch

There is one row per Cabin the optimizer manages, with its state (CANDIDATE, BUILDING, ACTIVE or DECAYING) and the scores behind its last decision; with nothing managed, only the header comes back. The optimizer’s switch and its counters of actions carried out are in the cabin_optimizer section of SHOW META. Turn it on with the server key cabin_optimizer = on, or at runtime with SET CABIN_OPTIMIZER ON (needs the admin role).

Verify

  • SHOW ACCESS lists the shapes of the queries you ran.
  • The fetch_id that ANALYZE prints for a repeated lookup appears in SHOW PATTERNS.

Next steps