Database system tables

To enable internal introspection of the DB state, the user can make queries to special service tables (system views). These tables are accessible from the root of the database tree and use the .sys system path prefix.

Hereinafter, in the descriptions of available fields, the Key column contains the corresponding table’s primary key field index.

Table partitions

  • partition_stats

A system view that provides detailed information about individual partitions of all DB tables. Contains information about instant metrics, such as CPU load or count of in-flight transactions, as well as cumulative counters of a variety of operations on a partition (for example, total number of rows read). Primarily designed for detecting various irregularities in the load on a table partition or in the size of table partition data.

Table structure:

FieldTypeKeyValue
OwnerIdUint640ID of the SchemeShard serving the table
PathIdUint641Path ID in the SchemeShard
PartIdxUint642Partition sequence number
DataSizeUint64Approximate partition size in bytes
RowCountUint64Approximate number of rows
IndexSizeUint64Partition index size in a tablet
CPUCoresDoubleInstant value of load per partition (CPU share)
TabletIdUint64ID of the tablet serving the partition
PathUtf8Full table path
NodeIdUint32ID of the node that the partition is being served on
StartTimeTimestampLast time when the tablet serving the partition was launched
AccessTimeTimestampLast time when data from the partition was read
UpdateTimeTimestampLast time when data was written to the partition
RowReadsUint64Number of point reads since the start of the partition tablet
RowUpdatesUint64Number of rows written since the start
RowDeletesUint64Number of rows deleted since the start
RangeReadsUint64Number of row ranges read since the start
RangeReadRowsUint64Number of rows read in the ranges since the start
InFlightTxCountUint64Number of in-flight transactions
ImmediateTxCompletedUint64Number of one-shard transactions completed since the start
CoordinatedTxCompletedUint64Number of coordinated transactions completed since the start
TxRejectedByOverloadUint64Number of transactions rejected due to overload (since the start)
TxRejectedByOutOfStorageUint64Number of transactions rejected due to lack of storage space (since the start)

Restrictions:

  • Cumulative fields (RowReads, RowUpdates, and so on) store the accumulated values since the last start of the tablet serving the partition

Examples:

Top 5 of most loaded partitions among all DB tables

  1. SELECT
  2. Path,
  3. PartIdx,
  4. CPUCores
  5. FROM `.sys/partition_stats`
  6. ORDER BY CPUCores DESC
  7. LIMIT 5

System views - 图1

List of DB tables with in-flight sizes and loads

  1. SELECT
  2. Path,
  3. COUNT(*) as Partitions,
  4. SUM(RowCount) as Rows,
  5. SUM(DataSize) as Size,
  6. SUM(CPUCores) as CPU
  7. FROM `.sys/partition_stats`
  8. GROUP BY Path

System views - 图2

Top queries

  • top_queries_by_duration_one_minute
  • top_queries_by_duration_one_hour
  • top_queries_by_read_bytes_one_minute
  • top_queries_by_read_bytes_one_hour
  • top_queries_by_cpu_time_one_minute
  • top_queries_by_cpu_time_one_hour

A group of system views for analyzing the flow of user queries. They let you see a time-limited query history divided into intervals. Within a single interval, the top 5 queries by a specific metric are saved. Currently, minute and hour intervals are available, and the top list can be made based on the total query execution time (the slowest), the number of bytes read from the table (the widest), and the total CPU time used (the heaviest).

Different runs of a query with the same text are deduplicated. The top list contains information about a specific run with the maximum value of the corresponding query metric within a single interval.

Fields that provide information about the used CPU time (…CPUTime) are expressed in ms.

Table structure:

FieldTypeKeyValue
IntervalEndTimestamp0Closing time of a minute or hour interval
RankUint321Rank of a top query
RequestUnitsUint64Number of RequestUnits used
QueryTextUtf8Query text
DurationIntervalTotal time of query execution
EndTimeTimestampQuery execution end time
TypeStringQuery type (data, scan, or script)
ReadRowsUint64Number of rows read
ReadBytesUint64Number of bytes read
UpdateRowsUint64Number of rows updated
UpdateBytesUint64Number of bytes updated
DeleteRowsUint64Number of rows deleted
DeleteBytesUint64Number of bytes deleted
PartitionsUint64Number of table partitions used during query execution
UserSIDStringUser security ID
ParametersSizeUint64Size of query parameters in bytes
CompileDurationIntervalQuery compile duration
FromQueryCacheBoolShows whether the cache of prepared queries was used
CPUTimeUint64Total CPU time used to execute the query (ms)
ShardCountUint64Number of shards used during query execution
SumShardCPUTimeUint64Total CPU time used in shards
MinShardCPUTimeUint64Minimum CPU time used in shards
MaxShardCPUTimeUint64Maximum CPU time used in shards
ComputeNodesCountUint64Number of compute nodes used during query execution
SumComputeCPUTimeUint64Total CPU time used in compute nodes
MinComputeCPUTimeUint64Minimum CPU time used in compute nodes
MaxComputeCPUTimeUint64Maximum CPU time used in compute nodes
CompileCPUTimeUint64CPU time used to compile a query
ProcessCPUTimeUint64CPU time used for overall query handling

Restrictions:

  • Query text limit is 4 KB.
  • Tables with minute intervals contain the history for the last 6 hours.
  • Tables with hourly intervals contain the history for the last 2 weeks.

Examples:

Top queries by execution time for the last minute when queries were made

  1. PRAGMA AnsiInForEmptyOrNullableItemsCollections;
  2. $last = (
  3. SELECT
  4. MAX(IntervalEnd)
  5. FROM `.sys/top_queries_by_duration_one_minute`
  6. );
  7. SELECT
  8. IntervalEnd,
  9. Rank,
  10. QueryText,
  11. Duration
  12. FROM `.sys/top_queries_by_duration_one_minute`
  13. WHERE IntervalEnd IN $last

System views - 图3

Queries that read the most bytes, broken down by minute

  1. SELECT
  2. IntervalEnd,
  3. QueryText,
  4. ReadBytes,
  5. ReadRows,
  6. Partitions
  7. FROM `.sys/top_queries_by_read_bytes_one_minute`
  8. WHERE Rank = 1

System views - 图4

Query details

  • query_metrics_one_minute

Detailed information about queries, broken down by minute. Each table row contains information about a set of queries with identical text that were made during one minute. The table fields provide the minimum, maximum, and total values for each query metric tracked. Within the interval, queries are sorted in descending order of the total CPU time used.

Table structure:

FieldTypeKeyValue
IntervalEndTimestamp0Closing time of a minute interval
RankUint321Query rank per interval (by the SumCPUTime field)
QueryTextUtf8Query text
CountUint64Number of query runs
SumDurationIntervalTotal query duration
MinDurationIntervalMinimum query duration
MaxDurationIntervalMaximum query duration
SumCPUTimeUint64Total CPU time used
MinCPUTimeUint64Minimum CPU time used
MaxCPUTimeUint64Maximum CPU time used
SumReadRowsUint64Total number of rows read
MinReadRowsUint64Minimum number of rows read
MaxReadRowsUint64Maximum number of rows read
SumReadBytesUint64Total number of bytes read
MinReadBytesUint64Minimum number of bytes read
MaxReadBytesUint64Maximum number of bytes read
SumUpdateRowsUint64Total number of rows updated
MinUpdateRowsUint64Minimum number of rows updated
MaxUpdateRowsUint64Maximum number of rows updated
SumUpdateBytesUint64Total number of bytes updated
MinUpdateBytesUint64Minimum number of bytes updated
MaxUpdateBytesUint64Maximum number of bytes updated
SumDeleteRowsUint64Total number of rows deleted
MinDeleteRowsUint64Minimum number of rows deleted
MaxDeleteRowsUint64Maximum number of rows deleted
SumRequestUnitsUint64Total number of RequestUnits used
MinRequestUnitsUint64Minimum number of RequestUnits used
MaxRequestUnitsUint64Maximum number of RequestUnits used

Restrictions:

  • Query text limit is 4 KB.
  • The table contains the history for the last 6 hours.
  • Within the interval, information is provided for no more than 256 different queries.
  • Statistics may be incomplete if the database is under heavy load.

Examples:

Top 10 queries for the last 6 hours by the total number of rows updated per minute

  1. SELECT
  2. SumUpdateRows,
  3. Count,
  4. QueryText,
  5. IntervalEnd
  6. FROM `.sys/query_metrics_one_minute`
  7. ORDER BY SumUpdateRows DESC LIMIT 10

System views - 图5

Recent queries that read the most bytes per minute:

  1. SELECT
  2. IntervalEnd,
  3. SumReadBytes,
  4. MinReadBytes,
  5. SumReadBytes / Count as AvgReadBytes,
  6. MaxReadBytes,
  7. QueryText
  8. FROM `.sys/query_metrics_one_minute`
  9. WHERE SumReadBytes > 0
  10. ORDER BY IntervalEnd DESC, SumReadBytes DESC
  11. LIMIT 100

System views - 图6

Notes

Please keep in mind that load caused by accessing system views is more analytical in nature, and therefore making frequent queries to them in large DBs will consume a lot of system resources. A load of about 1-2 rps is quite acceptable.