From 72aa3fbc98dd4dd84506481347e269672e786e3a Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Fri, 14 Nov 2025 15:29:55 +0100 Subject: [PATCH] Add a `mz_object_global_ids` relation Signed-off-by: Moritz Hoffmann --- .../content/sql/system-catalog/mz_internal.md | 9 +++++ .../src/catalog/builtin_table_updates.rs | 34 ++++++++++++++----- src/catalog/src/builtin.rs | 17 ++++++++++ src/pgrepr-consts/src/oid.rs | 1 + .../autogenerated/mz_internal.slt | 7 ++++ test/testdrive/catalog.td | 3 +- 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/doc/user/content/sql/system-catalog/mz_internal.md b/doc/user/content/sql/system-catalog/mz_internal.md index 5ed078ced2322..798ad0ada42a0 100644 --- a/doc/user/content/sql/system-catalog/mz_internal.md +++ b/doc/user/content/sql/system-catalog/mz_internal.md @@ -20,6 +20,15 @@ Backwards-incompatible changes to these objects may be made at any time. reference these objects is not allowed. {{< /warning >}} +## `mz_object_global_ids` + +The `mz_object_global_ids` table maps Materialize catalog item IDs to object IDs. + + +| Field | Type | Meaning | +|--------------|----------|-----------------------------------------------------------------------------------------------------| +| `id` | [`text`] | The ID of the object. Corresponds to [`mz_objects.id`](/sql/system-catalog/mz_catalog/#mz_objects). | +| `global_id` | [`text`] | The global ID of the object. | ## `mz_recent_activity_log` diff --git a/src/adapter/src/catalog/builtin_table_updates.rs b/src/adapter/src/catalog/builtin_table_updates.rs index 102ec11c15199..714b731d87d7c 100644 --- a/src/adapter/src/catalog/builtin_table_updates.rs +++ b/src/adapter/src/catalog/builtin_table_updates.rs @@ -24,19 +24,20 @@ use mz_catalog::builtin::{ MZ_INTERNAL_CLUSTER_REPLICAS, MZ_KAFKA_CONNECTIONS, MZ_KAFKA_SINKS, MZ_KAFKA_SOURCE_TABLES, MZ_KAFKA_SOURCES, MZ_LICENSE_KEYS, MZ_LIST_TYPES, MZ_MAP_TYPES, MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES, MZ_MATERIALIZED_VIEWS, MZ_MYSQL_SOURCE_TABLES, - MZ_NETWORK_POLICIES, MZ_NETWORK_POLICY_RULES, MZ_OBJECT_DEPENDENCIES, MZ_OPERATORS, - MZ_PENDING_CLUSTER_REPLICAS, MZ_POSTGRES_SOURCE_TABLES, MZ_POSTGRES_SOURCES, MZ_PSEUDO_TYPES, - MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES, MZ_SCHEMAS, MZ_SECRETS, - MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES, MZ_SQL_SERVER_SOURCE_TABLES, - MZ_SSH_TUNNEL_CONNECTIONS, MZ_STORAGE_USAGE_BY_SHARD, MZ_SUBSCRIPTIONS, MZ_SYSTEM_PRIVILEGES, - MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS, MZ_WEBHOOKS_SOURCES, + MZ_NETWORK_POLICIES, MZ_NETWORK_POLICY_RULES, MZ_OBJECT_DEPENDENCIES, MZ_OBJECT_GLOBAL_IDS, + MZ_OPERATORS, MZ_PENDING_CLUSTER_REPLICAS, MZ_POSTGRES_SOURCE_TABLES, MZ_POSTGRES_SOURCES, + MZ_PSEUDO_TYPES, MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES, MZ_SCHEMAS, + MZ_SECRETS, MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES, + MZ_SQL_SERVER_SOURCE_TABLES, MZ_SSH_TUNNEL_CONNECTIONS, MZ_STORAGE_USAGE_BY_SHARD, + MZ_SUBSCRIPTIONS, MZ_SYSTEM_PRIVILEGES, MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS, + MZ_WEBHOOKS_SOURCES, }; use mz_catalog::config::AwsPrincipalContext; use mz_catalog::durable::SourceReferences; use mz_catalog::memory::error::{Error, ErrorKind}; use mz_catalog::memory::objects::{ - CatalogItem, ClusterVariant, Connection, ContinualTask, DataSourceDesc, Func, Index, - MaterializedView, Sink, Table, TableDataSource, Type, View, + CatalogEntry, CatalogItem, ClusterVariant, Connection, ContinualTask, DataSourceDesc, Func, + Index, MaterializedView, Sink, Table, TableDataSource, Type, View, }; use mz_controller::clusters::{ ManagedReplicaAvailabilityZones, ManagedReplicaLocation, ReplicaLocation, @@ -900,9 +901,26 @@ impl CatalogState { updates.push(self.pack_history_retention_strategy_update(id, cw, diff)); } + updates.extend(Self::pack_item_global_id_update(entry, diff)); + updates } + fn pack_item_global_id_update( + entry: &CatalogEntry, + diff: Diff, + ) -> impl Iterator> + use<'_> { + let id = entry.id().to_string(); + let global_ids = entry.global_ids(); + global_ids.map(move |global_id| { + BuiltinTableUpdate::row( + &*MZ_OBJECT_GLOBAL_IDS, + Row::pack_slice(&[Datum::String(&id), Datum::String(&global_id.to_string())]), + diff, + ) + }) + } + fn pack_history_retention_strategy_update( &self, id: CatalogItemId, diff --git a/src/catalog/src/builtin.rs b/src/catalog/src/builtin.rs index 2de813e3aa6dd..24cc98254f6b1 100644 --- a/src/catalog/src/builtin.rs +++ b/src/catalog/src/builtin.rs @@ -5867,6 +5867,22 @@ pub static MZ_OBJECT_FULLY_QUALIFIED_NAMES: LazyLock = LazyLock::ne access: vec![PUBLIC_SELECT], }); +pub static MZ_OBJECT_GLOBAL_IDS: LazyLock = LazyLock::new(|| BuiltinTable { + name: "mz_object_global_ids", + schema: MZ_INTERNAL_SCHEMA, + oid: oid::VIEW_MZ_OBJECT_GLOBAL_IDS_OID, + desc: RelationDesc::builder() + .with_column("id", SqlScalarType::String.nullable(false)) + .with_column("global_id", SqlScalarType::String.nullable(false)) + .finish(), + column_comments: BTreeMap::from_iter([ + ("id", "Materialize's unique catalog item ID for the object."), + ("global_id", "A global ID for the object."), + ]), + is_retained_metrics_object: false, + access: vec![PUBLIC_SELECT], +}); + // TODO (SangJunBak): Remove once mz_object_history is released and used in the Console https://github.com/MaterializeInc/console/issues/3342 pub static MZ_OBJECT_LIFETIMES: LazyLock = LazyLock::new(|| BuiltinView { name: "mz_object_lifetimes", @@ -13830,6 +13846,7 @@ pub static BUILTINS_STATIC: LazyLock>> = LazyLock::ne Builtin::View(&MZ_OBJECTS_ID_NAMESPACE_TYPES), Builtin::View(&MZ_OBJECT_HISTORY), Builtin::View(&MZ_OBJECT_LIFETIMES), + Builtin::Table(&MZ_OBJECT_GLOBAL_IDS), Builtin::View(&MZ_ARRANGEMENT_SHARING_PER_WORKER), Builtin::View(&MZ_ARRANGEMENT_SHARING), Builtin::View(&MZ_ARRANGEMENT_SIZES_PER_WORKER), diff --git a/src/pgrepr-consts/src/oid.rs b/src/pgrepr-consts/src/oid.rs index 4d945ade1359e..bd4c3f6189001 100644 --- a/src/pgrepr-consts/src/oid.rs +++ b/src/pgrepr-consts/src/oid.rs @@ -497,6 +497,7 @@ pub const VIEW_MZ_STORAGE_USAGE_OID: u32 = 16771; pub const VIEW_MZ_RELATIONS_OID: u32 = 16772; pub const VIEW_MZ_OBJECT_OID_ALIAS_OID: u32 = 16773; pub const VIEW_MZ_OBJECTS_OID: u32 = 16774; +pub const VIEW_MZ_OBJECT_GLOBAL_IDS_OID: u32 = 17061; pub const VIEW_MZ_OBJECT_FULLY_QUALIFIED_NAMES_OID: u32 = 16775; pub const VIEW_MZ_OBJECT_LIFETIMES_OID: u32 = 16776; pub const VIEW_MZ_DATAFLOWS_PER_WORKER_OID: u32 = 16777; diff --git a/test/sqllogictest/autogenerated/mz_internal.slt b/test/sqllogictest/autogenerated/mz_internal.slt index 700f69f0ce187..3ef4129c0b173 100644 --- a/test/sqllogictest/autogenerated/mz_internal.slt +++ b/test/sqllogictest/autogenerated/mz_internal.slt @@ -29,6 +29,12 @@ CREATE VIEW objects AS statement ok CREATE INDEX objects_idx ON objects(schema, object) +query ITT +SELECT position, name, type FROM objects WHERE schema = 'mz_internal' AND object = 'mz_object_global_ids' ORDER BY position +---- +1 id text +2 global_id text + query ITT SELECT position, name, type FROM objects WHERE schema = 'mz_internal' AND object = 'mz_recent_activity_log' ORDER BY position ---- @@ -729,6 +735,7 @@ mz_notices mz_notices_redacted mz_object_dependencies mz_object_fully_qualified_names +mz_object_global_ids mz_object_history mz_object_lifetimes mz_object_oid_alias diff --git a/test/testdrive/catalog.td b/test/testdrive/catalog.td index 6373beddd2342..db5476e31d2d3 100644 --- a/test/testdrive/catalog.td +++ b/test/testdrive/catalog.td @@ -612,6 +612,7 @@ mz_mysql_source_tables "" mz_network_policies "" mz_network_policy_rules "" mz_object_dependencies "" +mz_object_global_ids "" mz_optimizer_notices "" mz_postgres_sources "" mz_postgres_source_tables "" @@ -804,7 +805,7 @@ test_table "" # `SHOW TABLES` and `mz_tables` should agree. > SELECT COUNT(*) FROM mz_tables WHERE id LIKE 's%' -63 +64 # There is one entry in mz_indexes for each field_number/expression of the index. > SELECT COUNT(id) FROM mz_indexes WHERE id LIKE 's%'