Skip to content

Query the schema as a graph via MATCH on schema_table/schema_rel - #1008

Merged
adsharma merged 2 commits into
mainfrom
schema-as-graph
Sep 23, 2026
Merged

adsharma merged 2 commits into
mainfrom
schema-as-graph

Conversation

@adsharma

@adsharma adsharma commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #1011

Query the schema as a graph instead of only via the :schema CREATE-statement dump.

lbug>  MATCH (t:schema_table) RETURN t.name, t.type ORDER BY t.name;
┌─────────┬────────┐
│ t.name  │ t.type │
│ STRING  │ STRING │
├─────────┼────────┤
│ City    │ NODE   │
│ Follows │ REL    │
│ LivesIn │ REL    │
│ User    │ NODE   │
└─────────┴────────┘
(4 tuples)
(2 columns)
Time: 1.47ms (compiling), 1.02ms (executing)
lbug>  MATCH (s:schema_table)-[r:schema_rel]->(d:schema_table) RETURN s.name, r.name, d.name ORDER BY s.name;
┌────────┬─────────┬────────┐
│ s.name │ r.name  │ d.name │
│ STRING │ STRING  │ STRING │
├────────┼─────────┼────────┤
│ User   │ LivesIn │ City   │
│ User   │ Follows │ User   │
└────────┴─────────┴────────┘
(2 tuples)
(3 columns)
Time: 1.07ms (compiling), 1.36ms (executing)

How it works:

  • New system tables schema_table (node: name PK, id, type) and schema_rel (rel: name, id) mirror the catalog. Prefixed names because bare table is a reserved keyword and MATCH (a:table) is a parse error.
  • Auto-refreshed before MATCH queries via a Connection-layer hook (best-effort; main DB only).
  • Hidden from SHOW_TABLES/:schema/wildcard MATCH/EXPORT (visible with internal catalog enabled for cleanup).

Tests: new test/test_files/schema/schema_graph.test; shell suite 14 passed; e2e ddl/match/comment/issue/schema suites passed.

Adds system tables schema_table (node) and schema_rel (rel) that mirror
the catalog, auto-refreshed before MATCH queries, and hidden from
SHOW_TABLES/:schema/wildcard MATCH/EXPORT.
Adds a multiplicity STRING property to schema_rel, one value per
(src, dst) connection using DDL convention (MANY_MANY, MANY_ONE,
ONE_ONE, ...), snapshotted from the catalog. Migrates pre-existing
schema_rel tables via ALTER TABLE ADD.
@adsharma
adsharma merged commit a0792b9 into main Sep 23, 2026
4 checks passed
@adsharma
adsharma deleted the schema-as-graph branch September 23, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Expose relationship multiplicity in SHOW_CONNECTION

1 participant