Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions doc/user/content/sql/system-catalog/mz_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,35 @@ deploying the changes to production.
| `details` | [`text`] | Additional details on why the `hint` was proposed based on the dependencies of the object. |
| `referenced_object_ids` | [`list`] | The IDs of objects referenced by `details`. Corresponds to [mz_objects.id](/sql/system-catalog/mz_catalog/#mz_objects). |

## `mz_inferred_relationships`

The `mz_inferred_relationships` view describes relationships between user
relations that the definitions of views and materialized views imply, without
declared keys. Each row comes from a single view's definition:

- A `join`: the view joins the two columns. The referenced side is a column
that alone keys an index, then a column named `id`, then the side not named
`*_id`. A join that none of these settle is undirected.
- A `key`: the view passes a key through unchanged, as in
`SELECT o.id AS org_id`, so its output column references that key.
- `passthrough`: the view passes any other column through unchanged.

A `passthrough` row is not a relationship. It says the two columns share a
domain, not their data: a view may filter, so its input column can hold
values that its output never shows. [`mz_mcp_relationships`](#mz_mcp_relationships)
follows these rows to derive references across views.

<!-- RELATION_SPEC mz_internal.mz_inferred_relationships -->
| Field | Type | Meaning |
| --------------- | -------------- | -------- |
| `source_id` | [`text`] | The ID of the relation holding the referencing column. Corresponds to [`mz_objects.id`](../mz_catalog/#mz_objects). |
| `source_column` | [`text`] | The referencing column. |
| `target_id` | [`text`] | The ID of the relation holding the referenced column. Corresponds to [`mz_objects.id`](../mz_catalog/#mz_objects). |
| `target_column` | [`text`] | The referenced column. |
| `kind` | [`text`] | `join` when a view joins the two columns, `key` when a view passes the target key through as the source column, and `passthrough` when a view passes any other target column through as the source column, which relates nothing by itself. |
| `is_directed` | [`boolean`] | Whether a key decides which side references the other. When false, the two columns are only known to be joined, and their order is arbitrary. |
| `inferred_from` | [`text array`] | The IDs of the views and materialized views whose definitions imply the relationship. |

## `mz_materialization_dependencies`

The `mz_materialization_dependencies` view describes the dependency structure between each materialization (materialized view, index, or sink) and the sources of its data.
Expand Down Expand Up @@ -905,6 +934,29 @@ subsource or table and the corresponding upstream PostgreSQL table being ingeste
| `schema_name` | [`text`] | The schema of the upstream table being ingested. |
| `table_name` | [`text`] | The name of the upstream table being ingested. |

## `mz_mcp_relationships`

The `mz_mcp_relationships` view lists the relationships between relations
that the current role can read, shaped like an
[ontology table](/transform-data/patterns/ontology/), so agents can look up
how to join two relations without one. It lists the `join` and `key` rows of
[`mz_inferred_relationships`](#mz_inferred_relationships), and `derived`
references: a column that holds the same values as a referencing column,
through a chain of views passing it, references the same key.

The view lists only relations the role holds `SELECT` on, and sessions with
`restrict_to_user_objects` can read it.

<!-- RELATION_SPEC mz_internal.mz_mcp_relationships -->
| Field | Type | Meaning |
| -------------------- | -------------- | -------- |
| `table_name` | [`text`] | Fully qualified name of the relation holding the referencing columns. |
| `columns` | [`text array`] | The referencing columns. |
| `referenced_table` | [`text`] | Fully qualified name of the relation holding the referenced columns. |
| `referenced_columns` | [`text array`] | The referenced columns, paired by position with `columns`. |
| `kind` | [`text`] | `join` when a view joins the columns, `key` when a view passes the referenced key through, and `derived` when the referencing column holds the same values as a column that references the key. |
| `is_directed` | [`boolean`] | Whether a key decides which side references the other. When false, the columns are only known to be joined. |

## `mz_mysql_source_tables`

The `mz_mysql_source_tables` table contains the mapping between each Materialize
Expand Down
2 changes: 1 addition & 1 deletion src/catalog-decode/src/create_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use serde_json::json;
use crate::durable;

/// Parses `sql`, which must contain exactly one statement.
fn parse_single_statement(sql: &str) -> Result<Statement<Raw>, String> {
pub(crate) fn parse_single_statement(sql: &str) -> Result<Statement<Raw>, String> {
let mut stmts = mz_sql_parser::parser::parse_statements(sql)
.map_err(|e| format!("failed to parse create_sql: {e}"))?;
match stmts.len() {
Expand Down
1 change: 1 addition & 0 deletions src/catalog-decode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
pub mod audit_log;
pub mod create_sql;
pub mod durable;
pub mod view_joins;
Loading