Skip to content

Commit 72aa3fb

Browse files
committed
Add a mz_object_global_ids relation
Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 2a6748d commit 72aa3fb

File tree

6 files changed

+62
-9
lines changed

6 files changed

+62
-9
lines changed

doc/user/content/sql/system-catalog/mz_internal.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ Backwards-incompatible changes to these objects may be made at any time.
2020
reference these objects is not allowed.
2121
{{< /warning >}}
2222

23+
## `mz_object_global_ids`
24+
25+
The `mz_object_global_ids` table maps Materialize catalog item IDs to object IDs.
26+
27+
<!-- RELATION_SPEC mz_internal.mz_object_global_ids -->
28+
| Field | Type | Meaning |
29+
|--------------|----------|-----------------------------------------------------------------------------------------------------|
30+
| `id` | [`text`] | The ID of the object. Corresponds to [`mz_objects.id`](/sql/system-catalog/mz_catalog/#mz_objects). |
31+
| `global_id` | [`text`] | The global ID of the object. |
2332

2433
## `mz_recent_activity_log`
2534

src/adapter/src/catalog/builtin_table_updates.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ use mz_catalog::builtin::{
2424
MZ_INTERNAL_CLUSTER_REPLICAS, MZ_KAFKA_CONNECTIONS, MZ_KAFKA_SINKS, MZ_KAFKA_SOURCE_TABLES,
2525
MZ_KAFKA_SOURCES, MZ_LICENSE_KEYS, MZ_LIST_TYPES, MZ_MAP_TYPES,
2626
MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES, MZ_MATERIALIZED_VIEWS, MZ_MYSQL_SOURCE_TABLES,
27-
MZ_NETWORK_POLICIES, MZ_NETWORK_POLICY_RULES, MZ_OBJECT_DEPENDENCIES, MZ_OPERATORS,
28-
MZ_PENDING_CLUSTER_REPLICAS, MZ_POSTGRES_SOURCE_TABLES, MZ_POSTGRES_SOURCES, MZ_PSEUDO_TYPES,
29-
MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES, MZ_SCHEMAS, MZ_SECRETS,
30-
MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES, MZ_SQL_SERVER_SOURCE_TABLES,
31-
MZ_SSH_TUNNEL_CONNECTIONS, MZ_STORAGE_USAGE_BY_SHARD, MZ_SUBSCRIPTIONS, MZ_SYSTEM_PRIVILEGES,
32-
MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS, MZ_WEBHOOKS_SOURCES,
27+
MZ_NETWORK_POLICIES, MZ_NETWORK_POLICY_RULES, MZ_OBJECT_DEPENDENCIES, MZ_OBJECT_GLOBAL_IDS,
28+
MZ_OPERATORS, MZ_PENDING_CLUSTER_REPLICAS, MZ_POSTGRES_SOURCE_TABLES, MZ_POSTGRES_SOURCES,
29+
MZ_PSEUDO_TYPES, MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES, MZ_SCHEMAS,
30+
MZ_SECRETS, MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES,
31+
MZ_SQL_SERVER_SOURCE_TABLES, MZ_SSH_TUNNEL_CONNECTIONS, MZ_STORAGE_USAGE_BY_SHARD,
32+
MZ_SUBSCRIPTIONS, MZ_SYSTEM_PRIVILEGES, MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS,
33+
MZ_WEBHOOKS_SOURCES,
3334
};
3435
use mz_catalog::config::AwsPrincipalContext;
3536
use mz_catalog::durable::SourceReferences;
3637
use mz_catalog::memory::error::{Error, ErrorKind};
3738
use mz_catalog::memory::objects::{
38-
CatalogItem, ClusterVariant, Connection, ContinualTask, DataSourceDesc, Func, Index,
39-
MaterializedView, Sink, Table, TableDataSource, Type, View,
39+
CatalogEntry, CatalogItem, ClusterVariant, Connection, ContinualTask, DataSourceDesc, Func,
40+
Index, MaterializedView, Sink, Table, TableDataSource, Type, View,
4041
};
4142
use mz_controller::clusters::{
4243
ManagedReplicaAvailabilityZones, ManagedReplicaLocation, ReplicaLocation,
@@ -900,9 +901,26 @@ impl CatalogState {
900901
updates.push(self.pack_history_retention_strategy_update(id, cw, diff));
901902
}
902903

904+
updates.extend(Self::pack_item_global_id_update(entry, diff));
905+
903906
updates
904907
}
905908

909+
fn pack_item_global_id_update(
910+
entry: &CatalogEntry,
911+
diff: Diff,
912+
) -> impl Iterator<Item = BuiltinTableUpdate<&'static BuiltinTable>> + use<'_> {
913+
let id = entry.id().to_string();
914+
let global_ids = entry.global_ids();
915+
global_ids.map(move |global_id| {
916+
BuiltinTableUpdate::row(
917+
&*MZ_OBJECT_GLOBAL_IDS,
918+
Row::pack_slice(&[Datum::String(&id), Datum::String(&global_id.to_string())]),
919+
diff,
920+
)
921+
})
922+
}
923+
906924
fn pack_history_retention_strategy_update(
907925
&self,
908926
id: CatalogItemId,

src/catalog/src/builtin.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,6 +5867,22 @@ pub static MZ_OBJECT_FULLY_QUALIFIED_NAMES: LazyLock<BuiltinView> = LazyLock::ne
58675867
access: vec![PUBLIC_SELECT],
58685868
});
58695869

5870+
pub static MZ_OBJECT_GLOBAL_IDS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5871+
name: "mz_object_global_ids",
5872+
schema: MZ_INTERNAL_SCHEMA,
5873+
oid: oid::VIEW_MZ_OBJECT_GLOBAL_IDS_OID,
5874+
desc: RelationDesc::builder()
5875+
.with_column("id", SqlScalarType::String.nullable(false))
5876+
.with_column("global_id", SqlScalarType::String.nullable(false))
5877+
.finish(),
5878+
column_comments: BTreeMap::from_iter([
5879+
("id", "Materialize's unique catalog item ID for the object."),
5880+
("global_id", "A global ID for the object."),
5881+
]),
5882+
is_retained_metrics_object: false,
5883+
access: vec![PUBLIC_SELECT],
5884+
});
5885+
58705886
// TODO (SangJunBak): Remove once mz_object_history is released and used in the Console https://github.com/MaterializeInc/console/issues/3342
58715887
pub static MZ_OBJECT_LIFETIMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
58725888
name: "mz_object_lifetimes",
@@ -13830,6 +13846,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
1383013846
Builtin::View(&MZ_OBJECTS_ID_NAMESPACE_TYPES),
1383113847
Builtin::View(&MZ_OBJECT_HISTORY),
1383213848
Builtin::View(&MZ_OBJECT_LIFETIMES),
13849+
Builtin::Table(&MZ_OBJECT_GLOBAL_IDS),
1383313850
Builtin::View(&MZ_ARRANGEMENT_SHARING_PER_WORKER),
1383413851
Builtin::View(&MZ_ARRANGEMENT_SHARING),
1383513852
Builtin::View(&MZ_ARRANGEMENT_SIZES_PER_WORKER),

src/pgrepr-consts/src/oid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ pub const VIEW_MZ_STORAGE_USAGE_OID: u32 = 16771;
497497
pub const VIEW_MZ_RELATIONS_OID: u32 = 16772;
498498
pub const VIEW_MZ_OBJECT_OID_ALIAS_OID: u32 = 16773;
499499
pub const VIEW_MZ_OBJECTS_OID: u32 = 16774;
500+
pub const VIEW_MZ_OBJECT_GLOBAL_IDS_OID: u32 = 17061;
500501
pub const VIEW_MZ_OBJECT_FULLY_QUALIFIED_NAMES_OID: u32 = 16775;
501502
pub const VIEW_MZ_OBJECT_LIFETIMES_OID: u32 = 16776;
502503
pub const VIEW_MZ_DATAFLOWS_PER_WORKER_OID: u32 = 16777;

test/sqllogictest/autogenerated/mz_internal.slt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ CREATE VIEW objects AS
2929
statement ok
3030
CREATE INDEX objects_idx ON objects(schema, object)
3131

32+
query ITT
33+
SELECT position, name, type FROM objects WHERE schema = 'mz_internal' AND object = 'mz_object_global_ids' ORDER BY position
34+
----
35+
1 id text
36+
2 global_id text
37+
3238
query ITT
3339
SELECT position, name, type FROM objects WHERE schema = 'mz_internal' AND object = 'mz_recent_activity_log' ORDER BY position
3440
----
@@ -729,6 +735,7 @@ mz_notices
729735
mz_notices_redacted
730736
mz_object_dependencies
731737
mz_object_fully_qualified_names
738+
mz_object_global_ids
732739
mz_object_history
733740
mz_object_lifetimes
734741
mz_object_oid_alias

test/testdrive/catalog.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ mz_mysql_source_tables ""
612612
mz_network_policies ""
613613
mz_network_policy_rules ""
614614
mz_object_dependencies ""
615+
mz_object_global_ids ""
615616
mz_optimizer_notices ""
616617
mz_postgres_sources ""
617618
mz_postgres_source_tables ""
@@ -804,7 +805,7 @@ test_table ""
804805

805806
# `SHOW TABLES` and `mz_tables` should agree.
806807
> SELECT COUNT(*) FROM mz_tables WHERE id LIKE 's%'
807-
63
808+
64
808809

809810
# There is one entry in mz_indexes for each field_number/expression of the index.
810811
> SELECT COUNT(id) FROM mz_indexes WHERE id LIKE 's%'

0 commit comments

Comments
 (0)