Skip to content
Open
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
9 changes: 9 additions & 0 deletions doc/user/content/sql/system-catalog/mz_internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we further clarify "to object IDs" to "to global object IDs" ?


<!-- RELATION_SPEC mz_internal.mz_object_global_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`

Expand Down
34 changes: 26 additions & 8 deletions src/adapter/src/catalog/builtin_table_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Item = BuiltinTableUpdate<&'static BuiltinTable>> + 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,
Expand Down
17 changes: 17 additions & 0 deletions src/catalog/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5867,6 +5867,22 @@ pub static MZ_OBJECT_FULLY_QUALIFIED_NAMES: LazyLock<BuiltinView> = LazyLock::ne
access: vec![PUBLIC_SELECT],
});

pub static MZ_OBJECT_GLOBAL_IDS: LazyLock<BuiltinTable> = 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<BuiltinView> = LazyLock::new(|| BuiltinView {
name: "mz_object_lifetimes",
Expand Down Expand Up @@ -13830,6 +13846,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = 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),
Expand Down
1 change: 1 addition & 0 deletions src/pgrepr-consts/src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/sqllogictest/autogenerated/mz_internal.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/testdrive/catalog.td
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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%'
Expand Down