Skip to Content
SQL ReferenceSchema & Query Diagnostics

Schema & Query Diagnostics

Use these commands to inspect table schemas and query execution plans. They are intended for operators, DBAs, and developers tuning SQL against KalamDB tables.

For storage-tier background on plan metrics, see /docs/server/architecture/storage-tiers.

DESCRIBE — table schema

KalamDB supports two DESCRIBE styles. Both answer “what columns does this table have?”, but they use different syntax, authorization, and result shapes.

DESCRIBE TABLE (KalamDB native)

SQL
DESCRIBE TABLE [<namespace>.]<table_name>;DESC TABLE [<namespace>.]<table_name>; -- Schema version historyDESCRIBE TABLE [<namespace>.]<table_name> HISTORY;

Access: authenticated users with an elevated role (DBA or System). Regular User role statements are rejected at execution time.

Returns: rich column metadata from the schema registry:

ColumnDescription
column_nameColumn name
ordinal_position1-based position in the table
column_idParquet field id
data_typeKalam SQL type name (for example TEXT, BIGINT, TIMESTAMP)
is_nullableWhether the column allows NULL
is_primary_keyWhether the column is part of the primary key
column_defaultDefault expression, if any
column_commentColumn comment, if any
schema_versionSchema version when the column was added

Example:

SQL
DESCRIBE TABLE dba.notifications;

DESCRIBE <table> / DESC <table> (DataFusion shorthand)

SQL
DESCRIBE [<namespace>.]<table_name>;DESC [<namespace>.]<table_name>;

Access: DBA or System only (admin meta command).

Behavior: KalamDB rewrites the statement to query information_schema.columns and returns Kalam SQL type names (kdb_data_type) instead of Arrow physical types:

ColumnDescription
column_nameColumn name
data_typeKalam SQL type (kdb_data_type)
is_nullableYES / NO

Unqualified table names resolve against the session’s current namespace (USE NAMESPACE, CLI ns:<name> context, or API namespace_id).

Example:

SQL
USE NAMESPACE dba;DESCRIBE notifications;

CLI shortcut

In the interactive shell, \d <table> and \describe <table> run an information_schema.columns query with Kalam type names — the same columns as the shorthand above, plus namespace, column_default, and position:

SQL
\d dba.notifications\describe notifications

See CLI querying for output formats.


EXPLAIN — query plans

EXPLAIN shows how DataFusion plans a query without executing it (unless ANALYZE is present).

Access: DBA or System only.

Syntax (keyword order matters)

DataFusion expects this order:

SQL
EXPLAIN [ANALYZE] [VERBOSE] [FORMAT <indent|tree|pgjson>] <query>;
KeywordPositionEffect
EXPLAINrequiredStart the diagnostic command
ANALYZEoptional, before VERBOSEExecute the query and attach runtime metrics
VERBOSEoptional, after ANALYZEAdd extra result rows (full metrics, row count, duration) when combined with ANALYZE
FORMAToptionalPlan rendering style (indent default, tree, pgjson)

Common mistake: EXPLAIN VERBOSE ANALYZE is not valid. Use EXPLAIN ANALYZE VERBOSE instead. With the wrong order, the parser treats ANALYZE as a separate statement and fails.

EXPLAIN (plan only)

Returns two rows — logical plan and physical plan — without running the query:

SQL
EXPLAINSELECT id, user_idFROM dba.notificationsWHERE user_id = 'test'LIMIT 3;

Example output columns:

plan_typeplan
logical_planOptimized logical plan tree
physical_planPhysical operators (FilterExec, GlobalLimitExec, DeferredBatchExec, …)

EXPLAIN ANALYZE (plan + runtime metrics)

Executes the query, discards result rows to the client, and returns an annotated physical plan with per-operator metrics:

SQL
EXPLAIN ANALYZESELECT id, user_id, _deletedFROM dba.notificationsWHERE user_id = 'test'LIMIT 3;

Returns one primary row:

plan_typeplan
Plan with MetricsPhysical plan tree with timing and counter metrics

On USER and SHARED tables, KalamDB enables scan diagnostics for EXPLAIN ANALYZE. Look for DeferredBatchExec nodes and metrics such as:

MetricMeaning
hot_rows_scannedRows read from the hot tier (RocksDB)
cold_rows_scannedRows read from cold Parquet files
cold_files_totalCold files considered by manifest pruning
cold_files_skippedCold files skipped by pruning
cold_files_scannedCold files actually read
cold_file_visited{file=…}Individual Parquet files touched (up to 16 recorded)

Plan text also includes static scan context on deferred MVCC sources, for example: storage_tiers=[hot=rocksdb,cold=parquet], mvcc=true.

EXPLAIN ANALYZE VERBOSE (full metrics + summary)

Adds extra rows after the annotated plan:

SQL
EXPLAIN ANALYZE VERBOSESELECT id, user_id, _deletedFROM dba.notificationsWHERE user_id = 'test'LIMIT 3;
plan_typeplan
Plan with MetricsAnnotated plan with standard metrics
Plan with Full MetricsPlan with all available metric detail
Output RowsRows produced by the query
DurationTotal execution time

Reading plans for KalamDB tables

Typical physical plans on application tables include:

  • DeferredBatchExec — deferred MVCC scan (hot RocksDB + cold Parquet merge)
  • FilterExec — predicate evaluation (pushdown where possible)
  • ProjectionExec — column selection
  • GlobalLimitExec / LocalLimitExecLIMIT handling
  • CooperativeExec — stream table scans

Use plain EXPLAIN to compare logical vs physical shape without execution cost. Use EXPLAIN ANALYZE when you need to see whether filters hit the hot tier, how many cold files were scanned, and operator timings.


CLI output tips

In default table format, the CLI renders plan_type / plan result sets specially:

  • Multi-line plan text is expanded across table rows (continuation lines leave plan_type blank)
  • The plan column uses the full terminal width instead of the generic 32-character cap

For machine-readable output, use JSON:

BASH
kalam --json -c "EXPLAIN ANALYZE SELECT 1;"

Or in the interactive shell:

SQL
\format jsonEXPLAIN ANALYZE VERBOSE SELECT id FROM dba.notifications LIMIT 3;
Last updated on