1use std::collections::BTreeMap;
13use std::sync::LazyLock;
14
15use mz_pgrepr::oid;
16use mz_repr::namespaces::MZ_CATALOG_SCHEMA;
17use mz_repr::{RelationDesc, SemanticType, SqlScalarType};
18use mz_sql::catalog::{
19 CatalogType, CatalogTypeDetails, CatalogTypePgMetadata, NameReference, ObjectType,
20};
21use mz_sql::rbac;
22use mz_sql::session::user::MZ_SYSTEM_ROLE_ID;
23use mz_storage_client::controller::IntrospectionType;
24
25use super::{
26 BuiltinIndex, BuiltinMaterializedView, BuiltinSource, BuiltinTable, BuiltinType, BuiltinView,
27 Cardinality, LinkProperties, Ontology, OntologyLink, PUBLIC_SELECT,
28};
29
30pub const TYPE_LIST: BuiltinType<NameReference> = BuiltinType {
31 name: "list",
32 schema: MZ_CATALOG_SCHEMA,
33 oid: mz_pgrepr::oid::TYPE_LIST_OID,
34 details: CatalogTypeDetails {
35 typ: CatalogType::Pseudo,
36 array_id: None,
37 pg_metadata: None,
38 },
39};
40
41pub const TYPE_MAP: BuiltinType<NameReference> = BuiltinType {
42 name: "map",
43 schema: MZ_CATALOG_SCHEMA,
44 oid: mz_pgrepr::oid::TYPE_MAP_OID,
45 details: CatalogTypeDetails {
46 typ: CatalogType::Pseudo,
47 array_id: None,
48 pg_metadata: None,
49 },
50};
51
52pub const TYPE_ANYCOMPATIBLELIST: BuiltinType<NameReference> = BuiltinType {
53 name: "anycompatiblelist",
54 schema: MZ_CATALOG_SCHEMA,
55 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLELIST_OID,
56 details: CatalogTypeDetails {
57 typ: CatalogType::Pseudo,
58 array_id: None,
59 pg_metadata: None,
60 },
61};
62
63pub const TYPE_ANYCOMPATIBLEMAP: BuiltinType<NameReference> = BuiltinType {
64 name: "anycompatiblemap",
65 schema: MZ_CATALOG_SCHEMA,
66 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLEMAP_OID,
67 details: CatalogTypeDetails {
68 typ: CatalogType::Pseudo,
69 array_id: None,
70 pg_metadata: None,
71 },
72};
73
74pub const TYPE_UINT2: BuiltinType<NameReference> = BuiltinType {
75 name: "uint2",
76 schema: MZ_CATALOG_SCHEMA,
77 oid: mz_pgrepr::oid::TYPE_UINT2_OID,
78 details: CatalogTypeDetails {
79 typ: CatalogType::UInt16,
80 array_id: None,
81 pg_metadata: None,
82 },
83};
84
85pub const TYPE_UINT2_ARRAY: BuiltinType<NameReference> = BuiltinType {
86 name: "_uint2",
87 schema: MZ_CATALOG_SCHEMA,
88 oid: mz_pgrepr::oid::TYPE_UINT2_ARRAY_OID,
89 details: CatalogTypeDetails {
90 typ: CatalogType::Array {
91 element_reference: TYPE_UINT2.name,
92 },
93 array_id: None,
94 pg_metadata: None,
95 },
96};
97
98pub const TYPE_UINT4: BuiltinType<NameReference> = BuiltinType {
99 name: "uint4",
100 schema: MZ_CATALOG_SCHEMA,
101 oid: mz_pgrepr::oid::TYPE_UINT4_OID,
102 details: CatalogTypeDetails {
103 typ: CatalogType::UInt32,
104 array_id: None,
105 pg_metadata: None,
106 },
107};
108
109pub const TYPE_UINT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
110 name: "_uint4",
111 schema: MZ_CATALOG_SCHEMA,
112 oid: mz_pgrepr::oid::TYPE_UINT4_ARRAY_OID,
113 details: CatalogTypeDetails {
114 typ: CatalogType::Array {
115 element_reference: TYPE_UINT4.name,
116 },
117 array_id: None,
118 pg_metadata: None,
119 },
120};
121
122pub const TYPE_UINT8: BuiltinType<NameReference> = BuiltinType {
123 name: "uint8",
124 schema: MZ_CATALOG_SCHEMA,
125 oid: mz_pgrepr::oid::TYPE_UINT8_OID,
126 details: CatalogTypeDetails {
127 typ: CatalogType::UInt64,
128 array_id: None,
129 pg_metadata: None,
130 },
131};
132
133pub const TYPE_UINT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
134 name: "_uint8",
135 schema: MZ_CATALOG_SCHEMA,
136 oid: mz_pgrepr::oid::TYPE_UINT8_ARRAY_OID,
137 details: CatalogTypeDetails {
138 typ: CatalogType::Array {
139 element_reference: TYPE_UINT8.name,
140 },
141 array_id: None,
142 pg_metadata: None,
143 },
144};
145
146pub const TYPE_MZ_TIMESTAMP: BuiltinType<NameReference> = BuiltinType {
147 name: "mz_timestamp",
148 schema: MZ_CATALOG_SCHEMA,
149 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_OID,
150 details: CatalogTypeDetails {
151 typ: CatalogType::MzTimestamp,
152 array_id: None,
153 pg_metadata: None,
154 },
155};
156
157pub const TYPE_MZ_TIMESTAMP_ARRAY: BuiltinType<NameReference> = BuiltinType {
158 name: "_mz_timestamp",
159 schema: MZ_CATALOG_SCHEMA,
160 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_ARRAY_OID,
161 details: CatalogTypeDetails {
162 typ: CatalogType::Array {
163 element_reference: TYPE_MZ_TIMESTAMP.name,
164 },
165 array_id: None,
166 pg_metadata: None,
167 },
168};
169
170pub const TYPE_MZ_ACL_ITEM: BuiltinType<NameReference> = BuiltinType {
171 name: "mz_aclitem",
172 schema: MZ_CATALOG_SCHEMA,
173 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_OID,
174 details: CatalogTypeDetails {
175 typ: CatalogType::MzAclItem,
176 array_id: None,
177 pg_metadata: None,
178 },
179};
180
181pub const TYPE_MZ_ACL_ITEM_ARRAY: BuiltinType<NameReference> = BuiltinType {
182 name: "_mz_aclitem",
183 schema: MZ_CATALOG_SCHEMA,
184 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_ARRAY_OID,
185 details: CatalogTypeDetails {
186 typ: CatalogType::Array {
187 element_reference: TYPE_MZ_ACL_ITEM.name,
188 },
189 array_id: None,
190 pg_metadata: Some(CatalogTypePgMetadata {
191 typinput_oid: 750,
192 typreceive_oid: 2400,
193 }),
194 },
195};
196
197pub static MZ_ICEBERG_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
198 name: "mz_iceberg_sinks",
199 schema: MZ_CATALOG_SCHEMA,
200 oid: oid::TABLE_MZ_ICEBERG_SINKS_OID,
201 desc: RelationDesc::builder()
202 .with_column("id", SqlScalarType::String.nullable(false))
203 .with_column("namespace", SqlScalarType::String.nullable(false))
204 .with_column("table", SqlScalarType::String.nullable(false))
205 .finish(),
206 column_comments: BTreeMap::from_iter([
207 ("id", "The ID of the sink."),
208 (
209 "namespace",
210 "The namespace of the Iceberg table into which the sink is writing.",
211 ),
212 ("table", "The Iceberg table into which the sink is writing."),
213 ]),
214 is_retained_metrics_object: false,
215 access: vec![PUBLIC_SELECT],
216 ontology: Some(Ontology {
217 entity_name: "iceberg_sink",
218 description: "Iceberg-specific sink configuration (namespace, table)",
219 links: &const {
220 [OntologyLink {
221 name: "details_of",
222 target: "sink",
223 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
224 }]
225 },
226 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
227 }),
228});
229
230pub static MZ_KAFKA_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
231 name: "mz_kafka_sinks",
232 schema: MZ_CATALOG_SCHEMA,
233 oid: oid::TABLE_MZ_KAFKA_SINKS_OID,
234 desc: RelationDesc::builder()
235 .with_column("id", SqlScalarType::String.nullable(false))
236 .with_column("topic", SqlScalarType::String.nullable(false))
237 .with_key(vec![0])
238 .finish(),
239 column_comments: BTreeMap::from_iter([
240 ("id", "The ID of the sink."),
241 (
242 "topic",
243 "The name of the Kafka topic into which the sink is writing.",
244 ),
245 ]),
246 is_retained_metrics_object: false,
247 access: vec![PUBLIC_SELECT],
248 ontology: Some(Ontology {
249 entity_name: "kafka_sink",
250 description: "Kafka-specific sink configuration (topic)",
251 links: &const {
252 [OntologyLink {
253 name: "details_of",
254 target: "sink",
255 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
256 }]
257 },
258 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
259 }),
260});
261pub static MZ_KAFKA_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
262 name: "mz_kafka_connections",
263 schema: MZ_CATALOG_SCHEMA,
264 oid: oid::TABLE_MZ_KAFKA_CONNECTIONS_OID,
265 desc: RelationDesc::builder()
266 .with_column("id", SqlScalarType::String.nullable(false))
267 .with_column(
268 "brokers",
269 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
270 )
271 .with_column("sink_progress_topic", SqlScalarType::String.nullable(false))
272 .finish(),
273 column_comments: BTreeMap::from_iter([
274 ("id", "The ID of the connection."),
275 (
276 "brokers",
277 "The addresses of the Kafka brokers to connect to.",
278 ),
279 (
280 "sink_progress_topic",
281 "The name of the Kafka topic where any sinks associated with this connection will track their progress information and other metadata. The contents of this topic are unspecified.",
282 ),
283 ]),
284 is_retained_metrics_object: false,
285 access: vec![PUBLIC_SELECT],
286 ontology: Some(Ontology {
287 entity_name: "kafka_connection",
288 description: "Kafka-specific connection configuration (brokers, progress topic)",
289 links: &const {
290 [OntologyLink {
291 name: "details_of",
292 target: "connection",
293 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
294 }]
295 },
296 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
297 }),
298});
299pub static MZ_KAFKA_SOURCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
300 name: "mz_kafka_sources",
301 schema: MZ_CATALOG_SCHEMA,
302 oid: oid::TABLE_MZ_KAFKA_SOURCES_OID,
303 desc: RelationDesc::builder()
304 .with_column("id", SqlScalarType::String.nullable(false))
305 .with_column("group_id_prefix", SqlScalarType::String.nullable(false))
306 .with_column("topic", SqlScalarType::String.nullable(false))
307 .finish(),
308 column_comments: BTreeMap::from_iter([
309 (
310 "id",
311 "The ID of the Kafka source. Corresponds to `mz_catalog.mz_sources.id`.",
312 ),
313 (
314 "group_id_prefix",
315 "The value of the `GROUP ID PREFIX` connection option.",
316 ),
317 (
318 "topic",
319 "The name of the Kafka topic the source is reading from.",
320 ),
321 ]),
322 is_retained_metrics_object: false,
323 access: vec![PUBLIC_SELECT],
324 ontology: Some(Ontology {
325 entity_name: "kafka_source",
326 description: "Kafka-specific source configuration (topic, group ID)",
327 links: &const {
328 [OntologyLink {
329 name: "details_of",
330 target: "source",
331 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
332 }]
333 },
334 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
335 }),
336});
337
338pub static MZ_DATABASES: LazyLock<BuiltinMaterializedView> =
339 LazyLock::new(|| BuiltinMaterializedView {
340 name: "mz_databases",
341 schema: MZ_CATALOG_SCHEMA,
342 oid: oid::MV_MZ_DATABASES_OID,
343 desc: RelationDesc::builder()
344 .with_column("id", SqlScalarType::String.nullable(false))
345 .with_column("oid", SqlScalarType::Oid.nullable(false))
346 .with_column("name", SqlScalarType::String.nullable(false))
347 .with_column("owner_id", SqlScalarType::String.nullable(false))
348 .with_column(
349 "privileges",
350 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
351 )
352 .with_key(vec![0])
353 .with_key(vec![1])
354 .finish(),
355 column_comments: BTreeMap::from_iter([
356 ("id", "Materialize's unique ID for the database."),
357 ("oid", "A PostgreSQL-compatible OID for the database."),
358 ("name", "The name of the database."),
359 (
360 "owner_id",
361 "The role ID of the owner of the database. Corresponds to `mz_roles.id`.",
362 ),
363 ("privileges", "The privileges belonging to the database."),
364 ]),
365 sql: "
366IN CLUSTER mz_catalog_server
367WITH (
368 ASSERT NOT NULL id,
369 ASSERT NOT NULL oid,
370 ASSERT NOT NULL name,
371 ASSERT NOT NULL owner_id,
372 ASSERT NOT NULL privileges
373) AS
374SELECT
375 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
376 (data->'value'->>'oid')::oid AS oid,
377 data->'value'->>'name' AS name,
378 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
379 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
380FROM mz_internal.mz_catalog_raw
381WHERE data->>'kind' = 'Database'",
382 is_retained_metrics_object: false,
383 access: vec![PUBLIC_SELECT],
384 ontology: Some(Ontology {
385 entity_name: "database",
386 description: "A top-level namespace that contains schemas",
387 links: &const {
388 [OntologyLink {
389 name: "owned_by",
390 target: "role",
391 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
392 }]
393 },
394 column_semantic_types: &const {
395 [
396 ("id", SemanticType::DatabaseId),
397 ("oid", SemanticType::OID),
398 ("owner_id", SemanticType::RoleId),
399 ]
400 },
401 }),
402 });
403
404pub static MZ_SCHEMAS: LazyLock<BuiltinMaterializedView> =
405 LazyLock::new(|| BuiltinMaterializedView {
406 name: "mz_schemas",
407 schema: MZ_CATALOG_SCHEMA,
408 oid: oid::MV_MZ_SCHEMAS_OID,
409 desc: RelationDesc::builder()
410 .with_column("id", SqlScalarType::String.nullable(false))
411 .with_column("oid", SqlScalarType::Oid.nullable(false))
412 .with_column("database_id", SqlScalarType::String.nullable(true))
413 .with_column("name", SqlScalarType::String.nullable(false))
414 .with_column("owner_id", SqlScalarType::String.nullable(false))
415 .with_column(
416 "privileges",
417 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
418 )
419 .with_key(vec![0])
420 .with_key(vec![1])
421 .finish(),
422 column_comments: BTreeMap::from_iter([
423 ("id", "Materialize's unique ID for the schema."),
424 ("oid", "A PostgreSQL-compatible oid for the schema."),
425 (
426 "database_id",
427 "The ID of the database containing the schema. Corresponds to `mz_databases.id`.",
428 ),
429 ("name", "The name of the schema."),
430 (
431 "owner_id",
432 "The role ID of the owner of the schema. Corresponds to `mz_roles.id`.",
433 ),
434 ("privileges", "The privileges belonging to the schema."),
435 ]),
436 sql: "
437IN CLUSTER mz_catalog_server
438WITH (
439 ASSERT NOT NULL id,
440 ASSERT NOT NULL oid,
441 ASSERT NOT NULL name,
442 ASSERT NOT NULL owner_id,
443 ASSERT NOT NULL privileges
444) AS
445SELECT
446 mz_internal.parse_catalog_id(data->'key'->'id') AS id,
447 (data->'value'->>'oid')::oid AS oid,
448 CASE WHEN data->'value'->'database_id' != 'null'
449 THEN mz_internal.parse_catalog_id(data->'value'->'database_id')
450 END AS database_id,
451 data->'value'->>'name' AS name,
452 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
453 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
454FROM mz_internal.mz_catalog_raw
455WHERE data->>'kind' = 'Schema'",
456 is_retained_metrics_object: false,
457 access: vec![PUBLIC_SELECT],
458 ontology: Some(Ontology {
459 entity_name: "schema",
460 description: "A namespace within a database that contains objects",
461 links: &const {
462 [
463 OntologyLink {
464 name: "in_database",
465 target: "database",
466 properties: LinkProperties::fk_nullable(
467 "database_id",
468 "id",
469 Cardinality::ManyToOne,
470 ),
471 },
472 OntologyLink {
473 name: "owned_by",
474 target: "role",
475 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
476 },
477 ]
478 },
479 column_semantic_types: &const {
480 [
481 ("id", SemanticType::SchemaId),
482 ("oid", SemanticType::OID),
483 ("database_id", SemanticType::DatabaseId),
484 ("owner_id", SemanticType::RoleId),
485 ]
486 },
487 }),
488 });
489
490pub static MZ_COLUMNS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
491 name: "mz_columns",
492 schema: MZ_CATALOG_SCHEMA,
493 oid: oid::TABLE_MZ_COLUMNS_OID,
494 desc: RelationDesc::builder()
495 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("name", SqlScalarType::String.nullable(false))
497 .with_column("position", SqlScalarType::UInt64.nullable(false))
498 .with_column("nullable", SqlScalarType::Bool.nullable(false))
499 .with_column("type", SqlScalarType::String.nullable(false))
500 .with_column("default", SqlScalarType::String.nullable(true))
501 .with_column("type_oid", SqlScalarType::Oid.nullable(false))
502 .with_column("type_mod", SqlScalarType::Int32.nullable(false))
503 .finish(),
504 column_comments: BTreeMap::from_iter([
505 (
506 "id",
507 "The unique ID of the table, source, or view containing the column.",
508 ),
509 ("name", "The name of the column."),
510 (
511 "position",
512 "The 1-indexed position of the column in its containing table, source, or view.",
513 ),
514 ("nullable", "Can the column contain a `NULL` value?"),
515 ("type", "The data type of the column."),
516 ("default", "The default expression of the column."),
517 (
518 "type_oid",
519 "The OID of the type of the column (references `mz_types`).",
520 ),
521 ("type_mod", "The packed type identifier of the column."),
522 ]),
523 is_retained_metrics_object: false,
524 access: vec![PUBLIC_SELECT],
525 ontology: Some(Ontology {
526 entity_name: "column",
527 description: "A column of a relation, with its name, position, type, and nullability",
528 links: &const {
529 [OntologyLink {
530 name: "belongs_to_relation",
531 target: "object",
532 properties: LinkProperties::ForeignKey {
533 source_column: "id",
534 target_column: "id",
535 cardinality: Cardinality::ManyToOne,
536 source_id_type: None,
537 requires_mapping: None,
538 nullable: false,
539 note: Some("id in mz_columns is the relation ID, not a unique column ID"),
540 extra_key_columns: None,
541 },
542 }]
543 },
544 column_semantic_types: &const {
545 [
546 ("id", SemanticType::CatalogItemId),
547 ("type_oid", SemanticType::OID),
548 ]
549 },
550 }),
551});
552pub static MZ_INDEXES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
553 name: "mz_indexes",
554 schema: MZ_CATALOG_SCHEMA,
555 oid: oid::TABLE_MZ_INDEXES_OID,
556 desc: RelationDesc::builder()
557 .with_column("id", SqlScalarType::String.nullable(false))
558 .with_column("oid", SqlScalarType::Oid.nullable(false))
559 .with_column("name", SqlScalarType::String.nullable(false))
560 .with_column("on_id", SqlScalarType::String.nullable(false))
561 .with_column("cluster_id", SqlScalarType::String.nullable(false))
562 .with_column("owner_id", SqlScalarType::String.nullable(false))
563 .with_column("create_sql", SqlScalarType::String.nullable(false))
564 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
565 .with_key(vec![0])
566 .with_key(vec![1])
567 .finish(),
568 column_comments: BTreeMap::from_iter([
569 ("id", "Materialize's unique ID for the index."),
570 ("oid", "A PostgreSQL-compatible OID for the index."),
571 ("name", "The name of the index."),
572 (
573 "on_id",
574 "The ID of the relation on which the index is built.",
575 ),
576 (
577 "cluster_id",
578 "The ID of the cluster in which the index is built.",
579 ),
580 (
581 "owner_id",
582 "The role ID of the owner of the index. Corresponds to `mz_roles.id`.",
583 ),
584 ("create_sql", "The `CREATE` SQL statement for the index."),
585 (
586 "redacted_create_sql",
587 "The redacted `CREATE` SQL statement for the index.",
588 ),
589 ]),
590 is_retained_metrics_object: false,
591 access: vec![PUBLIC_SELECT],
592 ontology: Some(Ontology {
593 entity_name: "index",
594 description: "An in-memory index on a relation for fast lookups",
595 links: &const {
596 [
597 OntologyLink {
598 name: "owned_by",
599 target: "role",
600 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
601 },
602 OntologyLink {
603 name: "runs_on_cluster",
604 target: "cluster",
605 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
606 },
607 OntologyLink {
608 name: "indexes_relation",
609 target: "relation",
610 properties: LinkProperties::fk("on_id", "id", Cardinality::ManyToOne),
611 },
612 ]
613 },
614 column_semantic_types: &const {
615 [
616 ("id", SemanticType::CatalogItemId),
617 ("oid", SemanticType::OID),
618 ("on_id", SemanticType::CatalogItemId),
619 ("cluster_id", SemanticType::ClusterId),
620 ("owner_id", SemanticType::RoleId),
621 ("create_sql", SemanticType::SqlDefinition),
622 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
623 ]
624 },
625 }),
626});
627pub static MZ_INDEX_COLUMNS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
628 name: "mz_index_columns",
629 schema: MZ_CATALOG_SCHEMA,
630 oid: oid::TABLE_MZ_INDEX_COLUMNS_OID,
631 desc: RelationDesc::builder()
632 .with_column("index_id", SqlScalarType::String.nullable(false))
633 .with_column("index_position", SqlScalarType::UInt64.nullable(false))
634 .with_column("on_position", SqlScalarType::UInt64.nullable(true))
635 .with_column("on_expression", SqlScalarType::String.nullable(true))
636 .with_column("nullable", SqlScalarType::Bool.nullable(false))
637 .finish(),
638 column_comments: BTreeMap::from_iter([
639 (
640 "index_id",
641 "The ID of the index which contains this column. Corresponds to `mz_indexes.id`.",
642 ),
643 (
644 "index_position",
645 "The 1-indexed position of this column within the index. (The order of columns in an index does not necessarily match the order of columns in the relation on which the index is built.)",
646 ),
647 (
648 "on_position",
649 "If not `NULL`, specifies the 1-indexed position of a column in the relation on which this index is built that determines the value of this index column.",
650 ),
651 (
652 "on_expression",
653 "If not `NULL`, specifies a SQL expression that is evaluated to compute the value of this index column. The expression may contain references to any of the columns of the relation.",
654 ),
655 (
656 "nullable",
657 "Can this column of the index evaluate to `NULL`?",
658 ),
659 ]),
660 is_retained_metrics_object: false,
661 access: vec![PUBLIC_SELECT],
662 ontology: Some(Ontology {
663 entity_name: "index_column",
664 description: "A column or expression in an index, with its position",
665 links: &const {
666 [OntologyLink {
667 name: "belongs_to_index",
668 target: "index",
669 properties: LinkProperties::fk("index_id", "id", Cardinality::ManyToOne),
670 }]
671 },
672 column_semantic_types: &[("index_id", SemanticType::CatalogItemId)],
673 }),
674});
675pub static MZ_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
676 name: "mz_tables",
677 schema: MZ_CATALOG_SCHEMA,
678 oid: oid::TABLE_MZ_TABLES_OID,
679 desc: RelationDesc::builder()
680 .with_column("id", SqlScalarType::String.nullable(false))
681 .with_column("oid", SqlScalarType::Oid.nullable(false))
682 .with_column("schema_id", SqlScalarType::String.nullable(false))
683 .with_column("name", SqlScalarType::String.nullable(false))
684 .with_column("owner_id", SqlScalarType::String.nullable(false))
685 .with_column(
686 "privileges",
687 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
688 )
689 .with_column("create_sql", SqlScalarType::String.nullable(true))
690 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
691 .with_column("source_id", SqlScalarType::String.nullable(true))
692 .with_key(vec![0])
693 .with_key(vec![1])
694 .finish(),
695 column_comments: BTreeMap::from_iter([
696 ("id", "Materialize's unique ID for the table."),
697 ("oid", "A PostgreSQL-compatible OID for the table."),
698 (
699 "schema_id",
700 "The ID of the schema to which the table belongs. Corresponds to `mz_schemas.id`.",
701 ),
702 ("name", "The name of the table."),
703 (
704 "owner_id",
705 "The role ID of the owner of the table. Corresponds to `mz_roles.id`.",
706 ),
707 ("privileges", "The privileges belonging to the table."),
708 ("create_sql", "The `CREATE` SQL statement for the table."),
709 (
710 "redacted_create_sql",
711 "The redacted `CREATE` SQL statement for the table.",
712 ),
713 (
714 "source_id",
715 "The ID of the source associated with the table, if any. Corresponds to `mz_sources.id`.",
716 ),
717 ]),
718 is_retained_metrics_object: true,
719 access: vec![PUBLIC_SELECT],
720 ontology: Some(Ontology {
721 entity_name: "table",
722 description: "A user-writable table that can be inserted into and updated",
723 links: &const {
724 [
725 OntologyLink {
726 name: "in_schema",
727 target: "schema",
728 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
729 },
730 OntologyLink {
731 name: "owned_by",
732 target: "role",
733 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
734 },
735 OntologyLink {
736 name: "created_by_source",
737 target: "source",
738 properties: LinkProperties::fk_nullable(
739 "source_id",
740 "id",
741 Cardinality::ManyToOne,
742 ),
743 },
744 ]
745 },
746 column_semantic_types: &const {
747 [
748 ("id", SemanticType::CatalogItemId),
749 ("oid", SemanticType::OID),
750 ("schema_id", SemanticType::SchemaId),
751 ("owner_id", SemanticType::RoleId),
752 ("create_sql", SemanticType::SqlDefinition),
753 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
754 ("source_id", SemanticType::CatalogItemId),
755 ]
756 },
757 }),
758});
759
760pub static MZ_CONNECTIONS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
761 BuiltinMaterializedView {
762 name: "mz_connections",
763 schema: MZ_CATALOG_SCHEMA,
764 oid: oid::MV_MZ_CONNECTIONS_OID,
765 desc: RelationDesc::builder()
766 .with_column("id", SqlScalarType::String.nullable(false))
767 .with_column("oid", SqlScalarType::Oid.nullable(false))
768 .with_column("schema_id", SqlScalarType::String.nullable(false))
769 .with_column("name", SqlScalarType::String.nullable(false))
770 .with_column("type", SqlScalarType::String.nullable(false))
771 .with_column("owner_id", SqlScalarType::String.nullable(false))
772 .with_column(
773 "privileges",
774 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
775 )
776 .with_column("create_sql", SqlScalarType::String.nullable(false))
777 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
778 .with_key(vec![0])
779 .with_key(vec![1])
780 .finish(),
781 column_comments: BTreeMap::from_iter([
782 ("id", "The unique ID of the connection."),
783 ("oid", "A PostgreSQL-compatible OID for the connection."),
784 (
785 "schema_id",
786 "The ID of the schema to which the connection belongs. Corresponds to `mz_schemas.id`.",
787 ),
788 ("name", "The name of the connection."),
789 (
790 "type",
791 "The type of the connection: `confluent-schema-registry`, `kafka`, `postgres`, or `ssh-tunnel`.",
792 ),
793 (
794 "owner_id",
795 "The role ID of the owner of the connection. Corresponds to `mz_roles.id`.",
796 ),
797 ("privileges", "The privileges belonging to the connection."),
798 (
799 "create_sql",
800 "The `CREATE` SQL statement for the connection.",
801 ),
802 (
803 "redacted_create_sql",
804 "The redacted `CREATE` SQL statement for the connection.",
805 ),
806 ]),
807 sql: "
808IN CLUSTER mz_catalog_server
809WITH (
810 ASSERT NOT NULL id,
811 ASSERT NOT NULL oid,
812 ASSERT NOT NULL schema_id,
813 ASSERT NOT NULL name,
814 ASSERT NOT NULL type,
815 ASSERT NOT NULL owner_id,
816 ASSERT NOT NULL privileges,
817 ASSERT NOT NULL create_sql,
818 ASSERT NOT NULL redacted_create_sql
819) AS
820SELECT
821 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
822 (data->'value'->>'oid')::oid AS oid,
823 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
824 data->'value'->>'name' AS name,
825 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'connection_type' AS type,
826 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
827 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
828 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
829 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
830FROM mz_internal.mz_catalog_raw
831WHERE
832 data->>'kind' = 'Item' AND
833 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'connection'",
834 is_retained_metrics_object: false,
835 access: vec![PUBLIC_SELECT],
836 ontology: Some(Ontology {
837 entity_name: "connection",
838 description: "A reusable connection configuration to an external system",
839 links: &const { [
840 OntologyLink {
841 name: "in_schema",
842 target: "schema",
843 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
844 },
845 OntologyLink {
846 name: "owned_by",
847 target: "role",
848 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
849 },
850 ] },
851 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("type", SemanticType::ConnectionType), ("owner_id", SemanticType::RoleId), ("create_sql", SemanticType::SqlDefinition), ("redacted_create_sql", SemanticType::RedactedSqlDefinition)]},
852 }),
853 }
854});
855
856pub static MZ_SSH_TUNNEL_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
857 name: "mz_ssh_tunnel_connections",
858 schema: MZ_CATALOG_SCHEMA,
859 oid: oid::TABLE_MZ_SSH_TUNNEL_CONNECTIONS_OID,
860 desc: RelationDesc::builder()
861 .with_column("id", SqlScalarType::String.nullable(false))
862 .with_column("public_key_1", SqlScalarType::String.nullable(false))
863 .with_column("public_key_2", SqlScalarType::String.nullable(false))
864 .finish(),
865 column_comments: BTreeMap::from_iter([
866 ("id", "The ID of the connection."),
867 (
868 "public_key_1",
869 "The first public key associated with the SSH tunnel.",
870 ),
871 (
872 "public_key_2",
873 "The second public key associated with the SSH tunnel.",
874 ),
875 ]),
876 is_retained_metrics_object: false,
877 access: vec![PUBLIC_SELECT],
878 ontology: Some(Ontology {
879 entity_name: "ssh_tunnel_connection",
880 description: "SSH tunnel connection with public keys",
881 links: &const {
882 [OntologyLink {
883 name: "details_of",
884 target: "connection",
885 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
886 }]
887 },
888 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
889 }),
890});
891pub static MZ_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| {
894 BuiltinTable {
895 name: "mz_sinks",
896 schema: MZ_CATALOG_SCHEMA,
897 oid: oid::TABLE_MZ_SINKS_OID,
898 desc: RelationDesc::builder()
899 .with_column("id", SqlScalarType::String.nullable(false))
900 .with_column("oid", SqlScalarType::Oid.nullable(false))
901 .with_column("schema_id", SqlScalarType::String.nullable(false))
902 .with_column("name", SqlScalarType::String.nullable(false))
903 .with_column("type", SqlScalarType::String.nullable(false))
904 .with_column("connection_id", SqlScalarType::String.nullable(true))
905 .with_column("size", SqlScalarType::String.nullable(true))
906 .with_column("envelope_type", SqlScalarType::String.nullable(true))
907 .with_column("format", SqlScalarType::String.nullable(true))
910 .with_column("key_format", SqlScalarType::String.nullable(true))
911 .with_column("value_format", SqlScalarType::String.nullable(true))
912 .with_column("cluster_id", SqlScalarType::String.nullable(false))
913 .with_column("owner_id", SqlScalarType::String.nullable(false))
914 .with_column("create_sql", SqlScalarType::String.nullable(false))
915 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
916 .with_key(vec![0])
917 .with_key(vec![1])
918 .finish(),
919 column_comments: BTreeMap::from_iter([
920 ("id", "Materialize's unique ID for the sink."),
921 ("oid", "A PostgreSQL-compatible OID for the sink."),
922 (
923 "schema_id",
924 "The ID of the schema to which the sink belongs. Corresponds to `mz_schemas.id`.",
925 ),
926 ("name", "The name of the sink."),
927 ("type", "The type of the sink: `kafka`."),
928 (
929 "connection_id",
930 "The ID of the connection associated with the sink, if any. Corresponds to `mz_connections.id`.",
931 ),
932 ("size", "The size of the sink."),
933 (
934 "envelope_type",
935 "The envelope of the sink: `upsert`, or `debezium`.",
936 ),
937 (
938 "format",
939 "*Deprecated* The format of the Kafka messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
940 ),
941 (
942 "key_format",
943 "The format of the Kafka message key for messages produced by the sink: `avro`, `json`, `bytes`, `text`, or `NULL`.",
944 ),
945 (
946 "value_format",
947 "The format of the Kafka message value for messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
948 ),
949 (
950 "cluster_id",
951 "The ID of the cluster maintaining the sink. Corresponds to `mz_clusters.id`.",
952 ),
953 (
954 "owner_id",
955 "The role ID of the owner of the sink. Corresponds to `mz_roles.id`.",
956 ),
957 ("create_sql", "The `CREATE` SQL statement for the sink."),
958 (
959 "redacted_create_sql",
960 "The redacted `CREATE` SQL statement for the sink.",
961 ),
962 ]),
963 is_retained_metrics_object: true,
964 access: vec![PUBLIC_SELECT],
965 ontology: Some(Ontology {
966 entity_name: "sink",
967 description: "An export of data from Materialize to an external system",
968 links: &const {
969 [
970 OntologyLink {
971 name: "in_schema",
972 target: "schema",
973 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
974 },
975 OntologyLink {
976 name: "owned_by",
977 target: "role",
978 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
979 },
980 OntologyLink {
981 name: "runs_on_cluster",
982 target: "cluster",
983 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
984 },
985 OntologyLink {
986 name: "uses_connection",
987 target: "connection",
988 properties: LinkProperties::fk_nullable(
989 "connection_id",
990 "id",
991 Cardinality::ManyToOne,
992 ),
993 },
994 ]
995 },
996 column_semantic_types: &const {
997 [
998 ("id", SemanticType::CatalogItemId),
999 ("oid", SemanticType::OID),
1000 ("schema_id", SemanticType::SchemaId),
1001 ("connection_id", SemanticType::CatalogItemId),
1002 ("cluster_id", SemanticType::ClusterId),
1003 ("owner_id", SemanticType::RoleId),
1004 ("create_sql", SemanticType::SqlDefinition),
1005 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1006 ]
1007 },
1008 }),
1009 }
1010});
1011pub static MZ_VIEWS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1012 name: "mz_views",
1013 schema: MZ_CATALOG_SCHEMA,
1014 oid: oid::TABLE_MZ_VIEWS_OID,
1015 desc: RelationDesc::builder()
1016 .with_column("id", SqlScalarType::String.nullable(false))
1017 .with_column("oid", SqlScalarType::Oid.nullable(false))
1018 .with_column("schema_id", SqlScalarType::String.nullable(false))
1019 .with_column("name", SqlScalarType::String.nullable(false))
1020 .with_column("definition", SqlScalarType::String.nullable(false))
1021 .with_column("owner_id", SqlScalarType::String.nullable(false))
1022 .with_column(
1023 "privileges",
1024 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1025 )
1026 .with_column("create_sql", SqlScalarType::String.nullable(false))
1027 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1028 .with_key(vec![0])
1029 .with_key(vec![1])
1030 .finish(),
1031 column_comments: BTreeMap::from_iter([
1032 ("id", "Materialize's unique ID for the view."),
1033 ("oid", "A PostgreSQL-compatible OID for the view."),
1034 (
1035 "schema_id",
1036 "The ID of the schema to which the view belongs. Corresponds to `mz_schemas.id`.",
1037 ),
1038 ("name", "The name of the view."),
1039 ("definition", "The view definition (a `SELECT` query)."),
1040 (
1041 "owner_id",
1042 "The role ID of the owner of the view. Corresponds to `mz_roles.id`.",
1043 ),
1044 ("privileges", "The privileges belonging to the view."),
1045 ("create_sql", "The `CREATE` SQL statement for the view."),
1046 (
1047 "redacted_create_sql",
1048 "The redacted `CREATE` SQL statement for the view.",
1049 ),
1050 ]),
1051 is_retained_metrics_object: false,
1052 access: vec![PUBLIC_SELECT],
1053 ontology: Some(Ontology {
1054 entity_name: "view",
1055 description: "A non-materialized view defined by a SQL query",
1056 links: &const {
1057 [
1058 OntologyLink {
1059 name: "in_schema",
1060 target: "schema",
1061 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1062 },
1063 OntologyLink {
1064 name: "owned_by",
1065 target: "role",
1066 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1067 },
1068 ]
1069 },
1070 column_semantic_types: &const {
1071 [
1072 ("id", SemanticType::CatalogItemId),
1073 ("oid", SemanticType::OID),
1074 ("schema_id", SemanticType::SchemaId),
1075 ("definition", SemanticType::SqlDefinition),
1076 ("owner_id", SemanticType::RoleId),
1077 ("create_sql", SemanticType::SqlDefinition),
1078 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1079 ]
1080 },
1081 }),
1082});
1083
1084pub static MZ_MATERIALIZED_VIEWS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1085 BuiltinMaterializedView {
1086 name: "mz_materialized_views",
1087 schema: MZ_CATALOG_SCHEMA,
1088 oid: oid::MV_MZ_MATERIALIZED_VIEWS_OID,
1089 desc: RelationDesc::builder()
1090 .with_column("id", SqlScalarType::String.nullable(false))
1091 .with_column("oid", SqlScalarType::Oid.nullable(false))
1092 .with_column("schema_id", SqlScalarType::String.nullable(false))
1093 .with_column("name", SqlScalarType::String.nullable(false))
1094 .with_column("cluster_id", SqlScalarType::String.nullable(false))
1095 .with_column("definition", SqlScalarType::String.nullable(false))
1096 .with_column("owner_id", SqlScalarType::String.nullable(false))
1097 .with_column(
1098 "privileges",
1099 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1100 )
1101 .with_column("create_sql", SqlScalarType::String.nullable(false))
1102 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
1103 .with_key(vec![0])
1104 .with_key(vec![1])
1105 .finish(),
1106 column_comments: BTreeMap::from_iter([
1107 ("id", "Materialize's unique ID for the materialized view."),
1108 (
1109 "oid",
1110 "A PostgreSQL-compatible OID for the materialized view.",
1111 ),
1112 (
1113 "schema_id",
1114 "The ID of the schema to which the materialized view belongs. Corresponds to `mz_schemas.id`.",
1115 ),
1116 ("name", "The name of the materialized view."),
1117 (
1118 "cluster_id",
1119 "The ID of the cluster maintaining the materialized view. Corresponds to `mz_clusters.id`.",
1120 ),
1121 (
1122 "definition",
1123 "The materialized view definition (a `SELECT` query).",
1124 ),
1125 (
1126 "owner_id",
1127 "The role ID of the owner of the materialized view. Corresponds to `mz_roles.id`.",
1128 ),
1129 (
1130 "privileges",
1131 "The privileges belonging to the materialized view.",
1132 ),
1133 (
1134 "create_sql",
1135 "The `CREATE` SQL statement for the materialized view.",
1136 ),
1137 (
1138 "redacted_create_sql",
1139 "The redacted `CREATE` SQL statement for the materialized view.",
1140 ),
1141 ]),
1142 sql: Box::leak(format!("
1143IN CLUSTER mz_catalog_server
1144WITH (
1145 ASSERT NOT NULL id,
1146 ASSERT NOT NULL oid,
1147 ASSERT NOT NULL schema_id,
1148 ASSERT NOT NULL name,
1149 ASSERT NOT NULL cluster_id,
1150 ASSERT NOT NULL definition,
1151 ASSERT NOT NULL owner_id,
1152 ASSERT NOT NULL privileges,
1153 ASSERT NOT NULL create_sql,
1154 ASSERT NOT NULL redacted_create_sql
1155) AS
1156WITH
1157 user_mvs AS (
1158 SELECT
1159 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1160 (data->'value'->>'oid')::oid AS oid,
1161 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
1162 data->'value'->>'name' AS name,
1163 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'cluster_id' AS cluster_id,
1164 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'definition' AS definition,
1165 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1166 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges,
1167 data->'value'->'definition'->'V1'->>'create_sql' AS create_sql,
1168 mz_internal.redact_sql(data->'value'->'definition'->'V1'->>'create_sql') AS redacted_create_sql
1169 FROM mz_internal.mz_catalog_raw
1170 WHERE
1171 data->>'kind' = 'Item' AND
1172 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'materialized-view'
1173 ),
1174 builtin_mappings AS (
1175 SELECT
1176 data->'key'->>'schema_name' AS schema_name,
1177 data->'key'->>'object_name' AS name,
1178 's' || (data->'value'->>'catalog_id') AS id
1179 FROM mz_internal.mz_catalog_raw
1180 WHERE
1181 data->>'kind' = 'GidMapping' AND
1182 data->'key'->>'object_type' = '5'
1183 ),
1184 builtin_mvs AS (
1185 SELECT
1186 m.id,
1187 mv.oid,
1188 s.id AS schema_id,
1189 mv.name,
1190 c.id AS cluster_id,
1191 mv.definition,
1192 '{MZ_SYSTEM_ROLE_ID}' AS owner_id,
1193 mv.privileges,
1194 mv.create_sql,
1195 mz_internal.redact_sql(mv.create_sql) AS redacted_create_sql
1196 FROM mz_internal.mz_builtin_materialized_views mv
1197 JOIN builtin_mappings m USING (schema_name, name)
1198 JOIN mz_schemas s ON s.name = mv.schema_name
1199 JOIN mz_clusters c ON c.name = mv.cluster_name
1200 WHERE s.database_id IS NULL
1201 )
1202SELECT * FROM user_mvs
1203UNION ALL
1204SELECT * FROM builtin_mvs").into_boxed_str()),
1205 is_retained_metrics_object: false,
1206 access: vec![PUBLIC_SELECT],
1207 ontology: Some(Ontology {
1208 entity_name: "mv",
1209 description: "A materialized view maintained incrementally on a cluster",
1210 links: &const { [
1211 OntologyLink { name: "in_schema", target: "schema", properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne) },
1212 OntologyLink { name: "owned_by", target: "role", properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne) },
1213 OntologyLink { name: "runs_on_cluster", target: "cluster", properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne) },
1214 ] },
1215 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("cluster_id", SemanticType::ClusterId), ("definition", SemanticType::SqlDefinition), ("owner_id", SemanticType::RoleId), ("create_sql", SemanticType::SqlDefinition), ("redacted_create_sql", SemanticType::RedactedSqlDefinition)]},
1216 }),
1217 }
1218});
1219pub static MZ_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1220 name: "mz_types",
1221 schema: MZ_CATALOG_SCHEMA,
1222 oid: oid::TABLE_MZ_TYPES_OID,
1223 desc: RelationDesc::builder()
1224 .with_column("id", SqlScalarType::String.nullable(false))
1225 .with_column("oid", SqlScalarType::Oid.nullable(false))
1226 .with_column("schema_id", SqlScalarType::String.nullable(false))
1227 .with_column("name", SqlScalarType::String.nullable(false))
1228 .with_column("category", SqlScalarType::String.nullable(false))
1229 .with_column("owner_id", SqlScalarType::String.nullable(false))
1230 .with_column(
1231 "privileges",
1232 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1233 )
1234 .with_column("create_sql", SqlScalarType::String.nullable(true))
1235 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
1236 .with_key(vec![0])
1237 .with_key(vec![1])
1238 .finish(),
1239 column_comments: BTreeMap::from_iter([
1240 ("id", "Materialize's unique ID for the type."),
1241 ("oid", "A PostgreSQL-compatible OID for the type."),
1242 (
1243 "schema_id",
1244 "The ID of the schema to which the type belongs. Corresponds to `mz_schemas.id`.",
1245 ),
1246 ("name", "The name of the type."),
1247 ("category", "The category of the type."),
1248 (
1249 "owner_id",
1250 "The role ID of the owner of the type. Corresponds to `mz_roles.id`.",
1251 ),
1252 ("privileges", "The privileges belonging to the type."),
1253 ("create_sql", "The `CREATE` SQL statement for the type."),
1254 (
1255 "redacted_create_sql",
1256 "The redacted `CREATE` SQL statement for the type.",
1257 ),
1258 ]),
1259 is_retained_metrics_object: false,
1260 access: vec![PUBLIC_SELECT],
1261 ontology: Some(Ontology {
1262 entity_name: "type",
1263 description: "A named data type (base, array, list, map, or pseudo)",
1264 links: &const {
1265 [
1266 OntologyLink {
1267 name: "in_schema",
1268 target: "schema",
1269 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1270 },
1271 OntologyLink {
1272 name: "owned_by",
1273 target: "role",
1274 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1275 },
1276 ]
1277 },
1278 column_semantic_types: &const {
1279 [
1280 ("id", SemanticType::CatalogItemId),
1281 ("oid", SemanticType::OID),
1282 ("schema_id", SemanticType::SchemaId),
1283 ("owner_id", SemanticType::RoleId),
1284 ("create_sql", SemanticType::SqlDefinition),
1285 ("redacted_create_sql", SemanticType::RedactedSqlDefinition),
1286 ]
1287 },
1288 }),
1289});
1290pub static MZ_ARRAY_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1291 name: "mz_array_types",
1292 schema: MZ_CATALOG_SCHEMA,
1293 oid: oid::TABLE_MZ_ARRAY_TYPES_OID,
1294 desc: RelationDesc::builder()
1295 .with_column("id", SqlScalarType::String.nullable(false))
1296 .with_column("element_id", SqlScalarType::String.nullable(false))
1297 .finish(),
1298 column_comments: BTreeMap::from_iter([
1299 ("id", "The ID of the array type."),
1300 ("element_id", "The ID of the array's element type."),
1301 ]),
1302 is_retained_metrics_object: false,
1303 access: vec![PUBLIC_SELECT],
1304 ontology: Some(Ontology {
1305 entity_name: "array_type",
1306 description: "An array type with its element type",
1307 links: &const {
1308 [
1309 OntologyLink {
1310 name: "detail_of",
1311 target: "type",
1312 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
1313 },
1314 OntologyLink {
1315 name: "has_element_type",
1316 target: "type",
1317 properties: LinkProperties::fk("element_id", "id", Cardinality::ManyToOne),
1318 },
1319 ]
1320 },
1321 column_semantic_types: &const {
1322 [
1323 ("id", SemanticType::CatalogItemId),
1324 ("element_id", SemanticType::CatalogItemId),
1325 ]
1326 },
1327 }),
1328});
1329pub static MZ_BASE_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1330 name: "mz_base_types",
1331 schema: MZ_CATALOG_SCHEMA,
1332 oid: oid::TABLE_MZ_BASE_TYPES_OID,
1333 desc: RelationDesc::builder()
1334 .with_column("id", SqlScalarType::String.nullable(false))
1335 .finish(),
1336 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
1337 is_retained_metrics_object: false,
1338 access: vec![PUBLIC_SELECT],
1339 ontology: Some(Ontology {
1340 entity_name: "base_type",
1341 description: "A primitive/base data type",
1342 links: &const { [] },
1343 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
1344 }),
1345});
1346pub static MZ_LIST_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1347 name: "mz_list_types",
1348 schema: MZ_CATALOG_SCHEMA,
1349 oid: oid::TABLE_MZ_LIST_TYPES_OID,
1350 desc: RelationDesc::builder()
1351 .with_column("id", SqlScalarType::String.nullable(false))
1352 .with_column("element_id", SqlScalarType::String.nullable(false))
1353 .with_column(
1354 "element_modifiers",
1355 SqlScalarType::List {
1356 element_type: Box::new(SqlScalarType::Int64),
1357 custom_id: None,
1358 }
1359 .nullable(true),
1360 )
1361 .finish(),
1362 column_comments: BTreeMap::from_iter([
1363 ("id", "The ID of the list type."),
1364 ("element_id", "The IID of the list's element type."),
1365 (
1366 "element_modifiers",
1367 "The element type modifiers, or `NULL` if none.",
1368 ),
1369 ]),
1370 is_retained_metrics_object: false,
1371 access: vec![PUBLIC_SELECT],
1372 ontology: Some(Ontology {
1373 entity_name: "list_type",
1374 description: "A list type with its element type",
1375 links: &const {
1376 [
1377 OntologyLink {
1378 name: "detail_of",
1379 target: "type",
1380 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
1381 },
1382 OntologyLink {
1383 name: "has_element_type",
1384 target: "type",
1385 properties: LinkProperties::fk("element_id", "id", Cardinality::ManyToOne),
1386 },
1387 ]
1388 },
1389 column_semantic_types: &const {
1390 [
1391 ("id", SemanticType::CatalogItemId),
1392 ("element_id", SemanticType::CatalogItemId),
1393 ]
1394 },
1395 }),
1396});
1397pub static MZ_MAP_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1398 name: "mz_map_types",
1399 schema: MZ_CATALOG_SCHEMA,
1400 oid: oid::TABLE_MZ_MAP_TYPES_OID,
1401 desc: RelationDesc::builder()
1402 .with_column("id", SqlScalarType::String.nullable(false))
1403 .with_column("key_id", SqlScalarType::String.nullable(false))
1404 .with_column("value_id", SqlScalarType::String.nullable(false))
1405 .with_column(
1406 "key_modifiers",
1407 SqlScalarType::List {
1408 element_type: Box::new(SqlScalarType::Int64),
1409 custom_id: None,
1410 }
1411 .nullable(true),
1412 )
1413 .with_column(
1414 "value_modifiers",
1415 SqlScalarType::List {
1416 element_type: Box::new(SqlScalarType::Int64),
1417 custom_id: None,
1418 }
1419 .nullable(true),
1420 )
1421 .finish(),
1422 column_comments: BTreeMap::from_iter([
1423 ("id", "The ID of the map type."),
1424 ("key_id", "The ID of the map's key type."),
1425 ("value_id", "The ID of the map's value type."),
1426 (
1427 "key_modifiers",
1428 "The key type modifiers, or `NULL` if none.",
1429 ),
1430 (
1431 "value_modifiers",
1432 "The value type modifiers, or `NULL` if none.",
1433 ),
1434 ]),
1435 is_retained_metrics_object: false,
1436 access: vec![PUBLIC_SELECT],
1437 ontology: Some(Ontology {
1438 entity_name: "map_type",
1439 description: "A map type with its key and value types",
1440 links: &const {
1441 [
1442 OntologyLink {
1443 name: "detail_of",
1444 target: "type",
1445 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
1446 },
1447 OntologyLink {
1448 name: "has_key_type",
1449 target: "type",
1450 properties: LinkProperties::fk("key_id", "id", Cardinality::ManyToOne),
1451 },
1452 OntologyLink {
1453 name: "has_value_type",
1454 target: "type",
1455 properties: LinkProperties::fk("value_id", "id", Cardinality::ManyToOne),
1456 },
1457 ]
1458 },
1459 column_semantic_types: &const {
1460 [
1461 ("id", SemanticType::CatalogItemId),
1462 ("key_id", SemanticType::CatalogItemId),
1463 ("value_id", SemanticType::CatalogItemId),
1464 ]
1465 },
1466 }),
1467});
1468pub static MZ_ROLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1469 name: "mz_roles",
1470 schema: MZ_CATALOG_SCHEMA,
1471 oid: oid::TABLE_MZ_ROLES_OID,
1472 desc: RelationDesc::builder()
1473 .with_column("id", SqlScalarType::String.nullable(false))
1474 .with_column("oid", SqlScalarType::Oid.nullable(false))
1475 .with_column("name", SqlScalarType::String.nullable(false))
1476 .with_column("inherit", SqlScalarType::Bool.nullable(false))
1477 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(true))
1478 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
1479 .with_key(vec![0])
1480 .with_key(vec![1])
1481 .finish(),
1482 column_comments: BTreeMap::from_iter([
1483 ("id", "Materialize's unique ID for the role."),
1484 ("oid", "A PostgreSQL-compatible OID for the role."),
1485 ("name", "The name of the role."),
1486 (
1487 "inherit",
1488 "Indicates whether the role has inheritance of privileges.",
1489 ),
1490 ("rolcanlogin", "Indicates whether the role can log in."),
1491 ("rolsuper", "Indicates whether the role is a superuser."),
1492 ]),
1493 is_retained_metrics_object: false,
1494 access: vec![PUBLIC_SELECT],
1495 ontology: Some(Ontology {
1496 entity_name: "role",
1497 description: "A user or role for authentication and access control",
1498 links: &const { [] },
1499 column_semantic_types: &const { [("id", SemanticType::RoleId), ("oid", SemanticType::OID)] },
1500 }),
1501});
1502
1503pub static MZ_ROLE_MEMBERS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1504 BuiltinMaterializedView {
1505 name: "mz_role_members",
1506 schema: MZ_CATALOG_SCHEMA,
1507 oid: oid::MV_MZ_ROLE_MEMBERS_OID,
1508 desc: RelationDesc::builder()
1509 .with_column("role_id", SqlScalarType::String.nullable(false))
1510 .with_column("member", SqlScalarType::String.nullable(false))
1511 .with_column("grantor", SqlScalarType::String.nullable(false))
1512 .finish(),
1513 column_comments: BTreeMap::from_iter([
1514 (
1515 "role_id",
1516 "The ID of the role the `member` is a member of. Corresponds to `mz_roles.id`.",
1517 ),
1518 (
1519 "member",
1520 "The ID of the role that is a member of `role_id`. Corresponds to `mz_roles.id`.",
1521 ),
1522 (
1523 "grantor",
1524 "The ID of the role that granted membership of `member` to `role_id`. Corresponds to `mz_roles.id`.",
1525 ),
1526 ]),
1527 sql: "
1528IN CLUSTER mz_catalog_server
1529WITH (
1530 ASSERT NOT NULL role_id,
1531 ASSERT NOT NULL member,
1532 ASSERT NOT NULL grantor
1533) AS
1534SELECT
1535 mz_internal.parse_catalog_id(entry->'key') AS role_id,
1536 mz_internal.parse_catalog_id(data->'key'->'id') AS member,
1537 mz_internal.parse_catalog_id(entry->'value') AS grantor
1538FROM
1539 mz_internal.mz_catalog_raw,
1540 jsonb_array_elements(data->'value'->'membership'->'map') AS entry
1541WHERE data->>'kind' = 'Role'",
1542 is_retained_metrics_object: false,
1543 access: vec![PUBLIC_SELECT],
1544 ontology: Some(Ontology {
1545 entity_name: "role_membership",
1546 description: "A membership grant: one role is a member of another role",
1547 links: &const {
1548 [
1549 OntologyLink {
1550 name: "group_role",
1551 target: "role",
1552 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
1553 },
1554 OntologyLink {
1555 name: "member_role",
1556 target: "role",
1557 properties: LinkProperties::fk("member", "id", Cardinality::ManyToOne),
1558 },
1559 OntologyLink {
1560 name: "granted_by",
1561 target: "role",
1562 properties: LinkProperties::fk("grantor", "id", Cardinality::ManyToOne),
1563 },
1564 ]
1565 },
1566 column_semantic_types: &const {
1567 [
1568 ("role_id", SemanticType::RoleId),
1569 ("member", SemanticType::RoleId),
1570 ("grantor", SemanticType::RoleId),
1571 ]
1572 },
1573 }),
1574 }
1575});
1576
1577pub static MZ_ROLE_PARAMETERS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1578 name: "mz_role_parameters",
1579 schema: MZ_CATALOG_SCHEMA,
1580 oid: oid::TABLE_MZ_ROLE_PARAMETERS_OID,
1581 desc: RelationDesc::builder()
1582 .with_column("role_id", SqlScalarType::String.nullable(false))
1583 .with_column("parameter_name", SqlScalarType::String.nullable(false))
1584 .with_column("parameter_value", SqlScalarType::String.nullable(false))
1585 .finish(),
1586 column_comments: BTreeMap::from_iter([
1587 (
1588 "role_id",
1589 "The ID of the role whose configuration parameter default is set. Corresponds to `mz_roles.id`.",
1590 ),
1591 (
1592 "parameter_name",
1593 "The configuration parameter name. One of the supported configuration parameters.",
1594 ),
1595 (
1596 "parameter_value",
1597 "The default value of the parameter for the given role. Can be either a single value, or a comma-separated list of values for configuration parameters that accept a list.",
1598 ),
1599 ]),
1600 is_retained_metrics_object: false,
1601 access: vec![PUBLIC_SELECT],
1602 ontology: Some(Ontology {
1603 entity_name: "role_parameter",
1604 description: "A session parameter default set for a role",
1605 links: &const {
1606 [OntologyLink {
1607 name: "default_parameter_setting_of",
1608 target: "role",
1609 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
1610 }]
1611 },
1612 column_semantic_types: &[("role_id", SemanticType::RoleId)],
1613 }),
1614});
1615pub static MZ_ROLE_AUTH: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1616 name: "mz_role_auth",
1617 schema: MZ_CATALOG_SCHEMA,
1618 oid: oid::TABLE_MZ_ROLE_AUTH_OID,
1619 desc: RelationDesc::builder()
1620 .with_column("role_id", SqlScalarType::String.nullable(false))
1621 .with_column("role_oid", SqlScalarType::Oid.nullable(false))
1622 .with_column("password_hash", SqlScalarType::String.nullable(true))
1623 .with_column(
1624 "updated_at",
1625 SqlScalarType::TimestampTz { precision: None }.nullable(false),
1626 )
1627 .finish(),
1628 column_comments: BTreeMap::from_iter([
1629 (
1630 "role_id",
1631 "The ID of the role. Corresponds to `mz_roles.id`.",
1632 ),
1633 ("role_oid", "A PostgreSQL-compatible OID for the role."),
1634 (
1635 "password_hash",
1636 "The hashed password for the role, if any. Uses the `SCRAM-SHA-256` algorithm.",
1637 ),
1638 (
1639 "updated_at",
1640 "The time at which the password was last updated.",
1641 ),
1642 ]),
1643 is_retained_metrics_object: false,
1644 access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
1645 ontology: None,
1646});
1647pub static MZ_PSEUDO_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1648 name: "mz_pseudo_types",
1649 schema: MZ_CATALOG_SCHEMA,
1650 oid: oid::TABLE_MZ_PSEUDO_TYPES_OID,
1651 desc: RelationDesc::builder()
1652 .with_column("id", SqlScalarType::String.nullable(false))
1653 .finish(),
1654 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
1655 is_retained_metrics_object: false,
1656 access: vec![PUBLIC_SELECT],
1657 ontology: Some(Ontology {
1658 entity_name: "pseudo_type",
1659 description: "A pseudo-type used in function signatures",
1660 links: &const { [] },
1661 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
1662 }),
1663});
1664pub static MZ_FUNCTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| {
1665 BuiltinTable {
1666 name: "mz_functions",
1667 schema: MZ_CATALOG_SCHEMA,
1668 oid: oid::TABLE_MZ_FUNCTIONS_OID,
1669 desc: RelationDesc::builder()
1670 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("oid", SqlScalarType::Oid.nullable(false))
1672 .with_column("schema_id", SqlScalarType::String.nullable(false))
1673 .with_column("name", SqlScalarType::String.nullable(false))
1674 .with_column(
1675 "argument_type_ids",
1676 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
1677 )
1678 .with_column(
1679 "variadic_argument_type_id",
1680 SqlScalarType::String.nullable(true),
1681 )
1682 .with_column("return_type_id", SqlScalarType::String.nullable(true))
1683 .with_column("returns_set", SqlScalarType::Bool.nullable(false))
1684 .with_column("owner_id", SqlScalarType::String.nullable(false))
1685 .finish(),
1686 column_comments: BTreeMap::from_iter([
1687 ("id", "Materialize's unique ID for the function."),
1688 ("oid", "A PostgreSQL-compatible OID for the function."),
1689 (
1690 "schema_id",
1691 "The ID of the schema to which the function belongs. Corresponds to `mz_schemas.id`.",
1692 ),
1693 ("name", "The name of the function."),
1694 (
1695 "argument_type_ids",
1696 "The ID of each argument's type. Each entry refers to `mz_types.id`.",
1697 ),
1698 (
1699 "variadic_argument_type_id",
1700 "The ID of the variadic argument's type, or `NULL` if the function does not have a variadic argument. Refers to `mz_types.id`.",
1701 ),
1702 (
1703 "return_type_id",
1704 "The returned value's type, or `NULL` if the function does not return a value. Refers to `mz_types.id`. Note that for table functions with > 1 column, this type corresponds to [`record`].",
1705 ),
1706 (
1707 "returns_set",
1708 "Whether the function returns a set, i.e. the function is a table function.",
1709 ),
1710 (
1711 "owner_id",
1712 "The role ID of the owner of the function. Corresponds to `mz_roles.id`.",
1713 ),
1714 ]),
1715 is_retained_metrics_object: false,
1716 access: vec![PUBLIC_SELECT],
1717 ontology: Some(Ontology {
1718 entity_name: "function",
1719 description: "A built-in or user-defined function",
1720 links: &const {
1721 [
1722 OntologyLink {
1723 name: "in_schema",
1724 target: "schema",
1725 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1726 },
1727 OntologyLink {
1728 name: "owned_by",
1729 target: "role",
1730 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1731 },
1732 OntologyLink {
1733 name: "returns_type",
1734 target: "type",
1735 properties: LinkProperties::fk_nullable(
1736 "return_type_id",
1737 "id",
1738 Cardinality::ManyToOne,
1739 ),
1740 },
1741 OntologyLink {
1742 name: "has_variadic_arg_type",
1743 target: "type",
1744 properties: LinkProperties::fk_nullable(
1745 "variadic_argument_type_id",
1746 "id",
1747 Cardinality::ManyToOne,
1748 ),
1749 },
1750 ]
1751 },
1752 column_semantic_types: &const {
1753 [
1754 ("id", SemanticType::CatalogItemId),
1755 ("oid", SemanticType::OID),
1756 ("schema_id", SemanticType::SchemaId),
1757 ("variadic_argument_type_id", SemanticType::CatalogItemId),
1758 ("return_type_id", SemanticType::CatalogItemId),
1759 ("owner_id", SemanticType::RoleId),
1760 ]
1761 },
1762 }),
1763 }
1764});
1765pub static MZ_OPERATORS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1766 name: "mz_operators",
1767 schema: MZ_CATALOG_SCHEMA,
1768 oid: oid::TABLE_MZ_OPERATORS_OID,
1769 desc: RelationDesc::builder()
1770 .with_column("oid", SqlScalarType::Oid.nullable(false))
1771 .with_column("name", SqlScalarType::String.nullable(false))
1772 .with_column(
1773 "argument_type_ids",
1774 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
1775 )
1776 .with_column("return_type_id", SqlScalarType::String.nullable(true))
1777 .finish(),
1778 column_comments: BTreeMap::new(),
1779 is_retained_metrics_object: false,
1780 access: vec![PUBLIC_SELECT],
1781 ontology: Some(Ontology {
1782 entity_name: "operator",
1783 description: "A built-in SQL operator",
1784 links: &const {
1785 [OntologyLink {
1786 name: "returns_type",
1787 target: "type",
1788 properties: LinkProperties::fk_nullable(
1789 "return_type_id",
1790 "id",
1791 Cardinality::ManyToOne,
1792 ),
1793 }]
1794 },
1795 column_semantic_types: &const {
1796 [
1797 ("oid", SemanticType::OID),
1798 ("return_type_id", SemanticType::CatalogItemId),
1799 ]
1800 },
1801 }),
1802});
1803
1804pub static MZ_CLUSTERS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1805 name: "mz_clusters",
1806 schema: MZ_CATALOG_SCHEMA,
1807 oid: oid::TABLE_MZ_CLUSTERS_OID,
1808 desc: RelationDesc::builder()
1809 .with_column("id", SqlScalarType::String.nullable(false))
1810 .with_column("name", SqlScalarType::String.nullable(false))
1811 .with_column("owner_id", SqlScalarType::String.nullable(false))
1812 .with_column(
1813 "privileges",
1814 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1815 )
1816 .with_column("managed", SqlScalarType::Bool.nullable(false))
1817 .with_column("size", SqlScalarType::String.nullable(true))
1818 .with_column("replication_factor", SqlScalarType::UInt32.nullable(true))
1819 .with_column("disk", SqlScalarType::Bool.nullable(true))
1820 .with_column(
1821 "availability_zones",
1822 SqlScalarType::List {
1823 element_type: Box::new(SqlScalarType::String),
1824 custom_id: None,
1825 }
1826 .nullable(true),
1827 )
1828 .with_column(
1829 "introspection_debugging",
1830 SqlScalarType::Bool.nullable(true),
1831 )
1832 .with_column(
1833 "introspection_interval",
1834 SqlScalarType::Interval.nullable(true),
1835 )
1836 .with_key(vec![0])
1837 .finish(),
1838 column_comments: BTreeMap::from_iter([
1839 ("id", "Materialize's unique ID for the cluster."),
1840 ("name", "The name of the cluster."),
1841 (
1842 "owner_id",
1843 "The role ID of the owner of the cluster. Corresponds to `mz_roles.id`.",
1844 ),
1845 ("privileges", "The privileges belonging to the cluster."),
1846 (
1847 "managed",
1848 "Whether the cluster is a managed cluster with automatically managed replicas.",
1849 ),
1850 (
1851 "size",
1852 "If the cluster is managed, the desired size of the cluster's replicas. `NULL` for unmanaged clusters.",
1853 ),
1854 (
1855 "replication_factor",
1856 "If the cluster is managed, the desired number of replicas of the cluster. `NULL` for unmanaged clusters.",
1857 ),
1858 (
1859 "disk",
1860 "**Unstable** If the cluster is managed, `true` if the replicas have the `DISK` option . `NULL` for unmanaged clusters.",
1861 ),
1862 (
1863 "availability_zones",
1864 "**Unstable** If the cluster is managed, the list of availability zones specified in `AVAILABILITY ZONES`. `NULL` for unmanaged clusters.",
1865 ),
1866 (
1867 "introspection_debugging",
1868 "Whether introspection of the gathering of the introspection data is enabled.",
1869 ),
1870 (
1871 "introspection_interval",
1872 "The interval at which to collect introspection data.",
1873 ),
1874 ]),
1875 is_retained_metrics_object: false,
1876 access: vec![PUBLIC_SELECT],
1877 ontology: Some(Ontology {
1878 entity_name: "cluster",
1879 description: "A compute cluster that runs dataflows for sources, sinks, MVs, and indexes",
1880 links: &const {
1881 [
1882 OntologyLink {
1883 name: "owned_by",
1884 target: "role",
1885 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1886 },
1887 OntologyLink {
1888 name: "has_size",
1889 target: "replica_size",
1890 properties: LinkProperties::fk_nullable("size", "size", Cardinality::ManyToOne),
1891 },
1892 ]
1893 },
1894 column_semantic_types: &const {
1895 [
1896 ("id", SemanticType::ClusterId),
1897 ("owner_id", SemanticType::RoleId),
1898 ]
1899 },
1900 }),
1901});
1902
1903pub static MZ_SECRETS: LazyLock<BuiltinMaterializedView> = LazyLock::new(|| {
1904 BuiltinMaterializedView {
1905 name: "mz_secrets",
1906 schema: MZ_CATALOG_SCHEMA,
1907 oid: oid::MV_MZ_SECRETS_OID,
1908 desc: RelationDesc::builder()
1909 .with_column("id", SqlScalarType::String.nullable(false))
1910 .with_column("oid", SqlScalarType::Oid.nullable(false))
1911 .with_column("schema_id", SqlScalarType::String.nullable(false))
1912 .with_column("name", SqlScalarType::String.nullable(false))
1913 .with_column("owner_id", SqlScalarType::String.nullable(false))
1914 .with_column(
1915 "privileges",
1916 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
1917 )
1918 .finish(),
1919 column_comments: BTreeMap::from_iter([
1920 ("id", "The unique ID of the secret."),
1921 ("oid", "A PostgreSQL-compatible oid for the secret."),
1922 (
1923 "schema_id",
1924 "The ID of the schema to which the secret belongs. Corresponds to `mz_schemas.id`.",
1925 ),
1926 ("name", "The name of the secret."),
1927 (
1928 "owner_id",
1929 "The role ID of the owner of the secret. Corresponds to `mz_roles.id`.",
1930 ),
1931 ("privileges", "The privileges belonging to the secret."),
1932 ]),
1933 sql: "
1934IN CLUSTER mz_catalog_server
1935WITH (
1936 ASSERT NOT NULL id,
1937 ASSERT NOT NULL oid,
1938 ASSERT NOT NULL schema_id,
1939 ASSERT NOT NULL name,
1940 ASSERT NOT NULL owner_id,
1941 ASSERT NOT NULL privileges
1942) AS
1943SELECT
1944 mz_internal.parse_catalog_id(data->'key'->'gid') AS id,
1945 (data->'value'->>'oid')::oid AS oid,
1946 mz_internal.parse_catalog_id(data->'value'->'schema_id') AS schema_id,
1947 data->'value'->>'name' AS name,
1948 mz_internal.parse_catalog_id(data->'value'->'owner_id') AS owner_id,
1949 mz_internal.parse_catalog_privileges(data->'value'->'privileges') AS privileges
1950FROM mz_internal.mz_catalog_raw
1951WHERE
1952 data->>'kind' = 'Item' AND
1953 mz_internal.parse_catalog_create_sql(data->'value'->'definition'->'V1'->>'create_sql')->>'type' = 'secret'",
1954 is_retained_metrics_object: false,
1955 access: vec![PUBLIC_SELECT],
1956 ontology: Some(Ontology {
1957 entity_name: "secret",
1958 description: "A user-defined secret containing sensitive configuration (e.g., credentials)",
1959 links: &const { [
1960 OntologyLink {
1961 name: "in_schema",
1962 target: "schema",
1963 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
1964 },
1965 OntologyLink {
1966 name: "owned_by",
1967 target: "role",
1968 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
1969 },
1970 ] },
1971 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("owner_id", SemanticType::RoleId)]},
1972 }),
1973 }
1974});
1975
1976pub static MZ_CLUSTER_REPLICAS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
1977 name: "mz_cluster_replicas",
1978 schema: MZ_CATALOG_SCHEMA,
1979 oid: oid::TABLE_MZ_CLUSTER_REPLICAS_OID,
1980 desc: RelationDesc::builder()
1981 .with_column("id", SqlScalarType::String.nullable(false))
1982 .with_column("name", SqlScalarType::String.nullable(false))
1983 .with_column("cluster_id", SqlScalarType::String.nullable(false))
1984 .with_column("size", SqlScalarType::String.nullable(true))
1985 .with_column("availability_zone", SqlScalarType::String.nullable(true))
1988 .with_column("owner_id", SqlScalarType::String.nullable(false))
1989 .with_column("disk", SqlScalarType::Bool.nullable(true))
1990 .finish(),
1991 column_comments: BTreeMap::from_iter([
1992 ("id", "Materialize's unique ID for the cluster replica."),
1993 ("name", "The name of the cluster replica."),
1994 (
1995 "cluster_id",
1996 "The ID of the cluster to which the replica belongs. Corresponds to `mz_clusters.id`.",
1997 ),
1998 (
1999 "size",
2000 "The cluster replica's size, selected during creation.",
2001 ),
2002 (
2003 "availability_zone",
2004 "The availability zone in which the cluster is running.",
2005 ),
2006 (
2007 "owner_id",
2008 "The role ID of the owner of the cluster replica. Corresponds to `mz_roles.id`.",
2009 ),
2010 ("disk", "If the replica has a local disk."),
2011 ]),
2012 is_retained_metrics_object: true,
2013 access: vec![PUBLIC_SELECT],
2014 ontology: Some(Ontology {
2015 entity_name: "replica",
2016 description: "A physical replica of a cluster providing fault tolerance",
2017 links: &const {
2018 [
2019 OntologyLink {
2020 name: "owned_by",
2021 target: "role",
2022 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2023 },
2024 OntologyLink {
2025 name: "belongs_to_cluster",
2026 target: "cluster",
2027 properties: LinkProperties::fk("cluster_id", "id", Cardinality::ManyToOne),
2028 },
2029 OntologyLink {
2030 name: "has_size",
2031 target: "replica_size",
2032 properties: LinkProperties::fk_nullable("size", "size", Cardinality::ManyToOne),
2033 },
2034 ]
2035 },
2036 column_semantic_types: &const {
2037 [
2038 ("id", SemanticType::ReplicaId),
2039 ("cluster_id", SemanticType::ClusterId),
2040 ("owner_id", SemanticType::RoleId),
2041 ]
2042 },
2043 }),
2044});
2045
2046pub static MZ_CLUSTER_REPLICA_SIZES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2047 name: "mz_cluster_replica_sizes",
2048 schema: MZ_CATALOG_SCHEMA,
2049 oid: oid::TABLE_MZ_CLUSTER_REPLICA_SIZES_OID,
2050 desc: RelationDesc::builder()
2051 .with_column("size", SqlScalarType::String.nullable(false))
2052 .with_column("processes", SqlScalarType::UInt64.nullable(false))
2053 .with_column("workers", SqlScalarType::UInt64.nullable(false))
2054 .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(false))
2055 .with_column("memory_bytes", SqlScalarType::UInt64.nullable(false))
2056 .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
2057 .with_column(
2058 "credits_per_hour",
2059 SqlScalarType::Numeric { max_scale: None }.nullable(false),
2060 )
2061 .finish(),
2062 column_comments: BTreeMap::from_iter([
2063 ("size", "The human-readable replica size."),
2064 ("processes", "The number of processes in the replica."),
2065 (
2066 "workers",
2067 "The number of Timely Dataflow workers per process.",
2068 ),
2069 (
2070 "cpu_nano_cores",
2071 "The CPU allocation per process, in billionths of a vCPU core.",
2072 ),
2073 (
2074 "memory_bytes",
2075 "The RAM allocation per process, in billionths of a vCPU core.",
2076 ),
2077 ("disk_bytes", "The disk allocation per process."),
2078 (
2079 "credits_per_hour",
2080 "The number of compute credits consumed per hour.",
2081 ),
2082 ]),
2083 is_retained_metrics_object: true,
2084 access: vec![PUBLIC_SELECT],
2085 ontology: Some(Ontology {
2086 entity_name: "replica_size",
2087 description: "Available cluster replica sizes with CPU, memory, and credit cost",
2088 links: &const { [] },
2089 column_semantic_types: &const {
2090 [
2091 ("memory_bytes", SemanticType::ByteCount),
2092 ("disk_bytes", SemanticType::ByteCount),
2093 ("credits_per_hour", SemanticType::CreditRate),
2094 ]
2095 },
2096 }),
2097});
2098
2099pub static MZ_AUDIT_EVENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2100 name: "mz_audit_events",
2101 schema: MZ_CATALOG_SCHEMA,
2102 oid: oid::TABLE_MZ_AUDIT_EVENTS_OID,
2103 desc: RelationDesc::builder()
2104 .with_column("id", SqlScalarType::UInt64.nullable(false))
2105 .with_column("event_type", SqlScalarType::String.nullable(false))
2106 .with_column("object_type", SqlScalarType::String.nullable(false))
2107 .with_column("details", SqlScalarType::Jsonb.nullable(false))
2108 .with_column("user", SqlScalarType::String.nullable(true))
2109 .with_column(
2110 "occurred_at",
2111 SqlScalarType::TimestampTz { precision: None }.nullable(false),
2112 )
2113 .with_key(vec![0])
2114 .finish(),
2115 column_comments: BTreeMap::from_iter([
2116 (
2117 "id",
2118 "Materialize's unique, monotonically increasing ID for the event.",
2119 ),
2120 (
2121 "event_type",
2122 "The type of the event: `create`, `drop`, or `alter`.",
2123 ),
2124 (
2125 "object_type",
2126 "The type of the affected object: `cluster`, `cluster-replica`, `connection`, `database`, `function`, `index`, `materialized-view`, `role`, `schema`, `secret`, `sink`, `source`, `table`, `type`, or `view`.",
2127 ),
2128 (
2129 "details",
2130 "Additional details about the event. The shape of the details varies based on `event_type` and `object_type`.",
2131 ),
2132 (
2133 "user",
2134 "The user who triggered the event, or `NULL` if triggered by the system.",
2135 ),
2136 (
2137 "occurred_at",
2138 "The time at which the event occurred. Guaranteed to be in order of event creation. Events created in the same transaction will have identical values.",
2139 ),
2140 ]),
2141 is_retained_metrics_object: false,
2142 access: vec![PUBLIC_SELECT],
2143 ontology: Some(Ontology {
2144 entity_name: "audit_event",
2145 description: "An audit log entry recording a DDL operation",
2146 links: &const { [] },
2147 column_semantic_types: &const {
2148 [
2149 ("object_type", SemanticType::ObjectType),
2150 ("occurred_at", SemanticType::WallclockTimestamp),
2151 ]
2152 },
2153 }),
2154});
2155
2156pub static MZ_EGRESS_IPS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2157 name: "mz_egress_ips",
2158 schema: MZ_CATALOG_SCHEMA,
2159 oid: oid::TABLE_MZ_EGRESS_IPS_OID,
2160 desc: RelationDesc::builder()
2161 .with_column("egress_ip", SqlScalarType::String.nullable(false))
2162 .with_column("prefix_length", SqlScalarType::Int32.nullable(false))
2163 .with_column("cidr", SqlScalarType::String.nullable(false))
2164 .finish(),
2165 column_comments: BTreeMap::from_iter([
2166 ("egress_ip", "The start of the range of IP addresses."),
2167 (
2168 "prefix_length",
2169 "The number of leading bits in the CIDR netmask.",
2170 ),
2171 ("cidr", "The CIDR representation."),
2172 ]),
2173 is_retained_metrics_object: false,
2174 access: vec![PUBLIC_SELECT],
2175 ontology: Some(Ontology {
2176 entity_name: "egress_ip",
2177 description: "IP addresses used for outbound connections from Materialize",
2178 links: &const { [] },
2179 column_semantic_types: &[],
2180 }),
2181});
2182
2183pub static MZ_AWS_PRIVATELINK_CONNECTIONS: LazyLock<BuiltinTable> =
2184 LazyLock::new(|| BuiltinTable {
2185 name: "mz_aws_privatelink_connections",
2186 schema: MZ_CATALOG_SCHEMA,
2187 oid: oid::TABLE_MZ_AWS_PRIVATELINK_CONNECTIONS_OID,
2188 desc: RelationDesc::builder()
2189 .with_column("id", SqlScalarType::String.nullable(false))
2190 .with_column("principal", SqlScalarType::String.nullable(false))
2191 .finish(),
2192 column_comments: BTreeMap::from_iter([
2193 ("id", "The ID of the connection."),
2194 (
2195 "principal",
2196 "The AWS Principal that Materialize will use to connect to the VPC endpoint.",
2197 ),
2198 ]),
2199 is_retained_metrics_object: false,
2200 access: vec![PUBLIC_SELECT],
2201 ontology: Some(Ontology {
2202 entity_name: "aws_privatelink_connection",
2203 description: "AWS PrivateLink connection configuration",
2204 links: &const {
2205 [OntologyLink {
2206 name: "details_of",
2207 target: "connection",
2208 properties: LinkProperties::fk("id", "id", Cardinality::OneToOne),
2209 }]
2210 },
2211 column_semantic_types: &[("id", SemanticType::CatalogItemId)],
2212 }),
2213 });
2214
2215pub static MZ_CLUSTER_REPLICA_FRONTIERS: LazyLock<BuiltinSource> =
2216 LazyLock::new(|| BuiltinSource {
2217 name: "mz_cluster_replica_frontiers",
2218 schema: MZ_CATALOG_SCHEMA,
2219 oid: oid::SOURCE_MZ_CLUSTER_REPLICA_FRONTIERS_OID,
2220 data_source: IntrospectionType::ReplicaFrontiers.into(),
2221 desc: RelationDesc::builder()
2222 .with_column("object_id", SqlScalarType::String.nullable(false))
2223 .with_column("replica_id", SqlScalarType::String.nullable(false))
2224 .with_column("write_frontier", SqlScalarType::MzTimestamp.nullable(true))
2225 .finish(),
2226 column_comments: BTreeMap::from_iter([
2227 (
2228 "object_id",
2229 "The ID of the source, sink, index, materialized view, or subscription.",
2230 ),
2231 ("replica_id", "The ID of a cluster replica."),
2232 (
2233 "write_frontier",
2234 "The next timestamp at which the output may change.",
2235 ),
2236 ]),
2237 is_retained_metrics_object: false,
2238 access: vec![PUBLIC_SELECT],
2239 ontology: None,
2240 });
2241
2242pub static MZ_CLUSTER_REPLICA_FRONTIERS_IND: LazyLock<BuiltinIndex> =
2243 LazyLock::new(|| BuiltinIndex {
2244 name: "mz_cluster_replica_frontiers_ind",
2245 schema: MZ_CATALOG_SCHEMA,
2246 oid: oid::INDEX_MZ_CLUSTER_REPLICA_FRONTIERS_IND_OID,
2247 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_cluster_replica_frontiers (object_id)",
2248 is_retained_metrics_object: false,
2249 });
2250
2251pub static MZ_DEFAULT_PRIVILEGES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2252 name: "mz_default_privileges",
2253 schema: MZ_CATALOG_SCHEMA,
2254 oid: oid::TABLE_MZ_DEFAULT_PRIVILEGES_OID,
2255 desc: RelationDesc::builder()
2256 .with_column("role_id", SqlScalarType::String.nullable(false))
2257 .with_column("database_id", SqlScalarType::String.nullable(true))
2258 .with_column("schema_id", SqlScalarType::String.nullable(true))
2259 .with_column("object_type", SqlScalarType::String.nullable(false))
2260 .with_column("grantee", SqlScalarType::String.nullable(false))
2261 .with_column("privileges", SqlScalarType::String.nullable(false))
2262 .finish(),
2263 column_comments: BTreeMap::from_iter([
2264 (
2265 "role_id",
2266 "Privileges described in this row will be granted on objects created by `role_id`. The role ID `p` stands for the `PUBLIC` pseudo-role and applies to all roles.",
2267 ),
2268 (
2269 "database_id",
2270 "Privileges described in this row will be granted only on objects in the database identified by `database_id` if non-null.",
2271 ),
2272 (
2273 "schema_id",
2274 "Privileges described in this row will be granted only on objects in the schema identified by `schema_id` if non-null.",
2275 ),
2276 (
2277 "object_type",
2278 "Privileges described in this row will be granted only on objects of type `object_type`.",
2279 ),
2280 (
2281 "grantee",
2282 "Privileges described in this row will be granted to `grantee`. The role ID `p` stands for the `PUBLIC` pseudo-role and applies to all roles.",
2283 ),
2284 ("privileges", "The set of privileges that will be granted."),
2285 ]),
2286 is_retained_metrics_object: false,
2287 access: vec![PUBLIC_SELECT],
2288 ontology: Some(Ontology {
2289 entity_name: "default_privilege",
2290 description: "A default privilege rule applied to newly created objects",
2291 links: &const {
2292 [
2293 OntologyLink {
2294 name: "default_priv_for_role",
2295 target: "role",
2296 properties: LinkProperties::fk("role_id", "id", Cardinality::ManyToOne),
2297 },
2298 OntologyLink {
2299 name: "default_priv_in_database",
2300 target: "database",
2301 properties: LinkProperties::fk_nullable(
2302 "database_id",
2303 "id",
2304 Cardinality::ManyToOne,
2305 ),
2306 },
2307 OntologyLink {
2308 name: "default_priv_in_schema",
2309 target: "schema",
2310 properties: LinkProperties::fk_nullable(
2311 "schema_id",
2312 "id",
2313 Cardinality::ManyToOne,
2314 ),
2315 },
2316 OntologyLink {
2317 name: "default_priv_granted_to",
2318 target: "role",
2319 properties: LinkProperties::fk("grantee", "id", Cardinality::ManyToOne),
2320 },
2321 ]
2322 },
2323 column_semantic_types: &const {
2324 [
2325 ("role_id", SemanticType::RoleId),
2326 ("database_id", SemanticType::DatabaseId),
2327 ("schema_id", SemanticType::SchemaId),
2328 ("object_type", SemanticType::ObjectType),
2329 ("grantee", SemanticType::RoleId),
2330 ]
2331 },
2332 }),
2333});
2334
2335pub static MZ_SYSTEM_PRIVILEGES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2336 name: "mz_system_privileges",
2337 schema: MZ_CATALOG_SCHEMA,
2338 oid: oid::TABLE_MZ_SYSTEM_PRIVILEGES_OID,
2339 desc: RelationDesc::builder()
2340 .with_column("privileges", SqlScalarType::MzAclItem.nullable(false))
2341 .finish(),
2342 column_comments: BTreeMap::from_iter([(
2343 "privileges",
2344 "The privileges belonging to the system.",
2345 )]),
2346 is_retained_metrics_object: false,
2347 access: vec![PUBLIC_SELECT],
2348 ontology: Some(Ontology {
2349 entity_name: "system_privilege",
2350 description: "A system-level privilege grant",
2351 links: &const { [] },
2352 column_semantic_types: &[],
2353 }),
2354});
2355
2356pub static MZ_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2357 name: "mz_storage_usage",
2358 schema: MZ_CATALOG_SCHEMA,
2359 oid: oid::VIEW_MZ_STORAGE_USAGE_OID,
2360 desc: RelationDesc::builder()
2361 .with_column("object_id", SqlScalarType::String.nullable(false))
2362 .with_column("size_bytes", SqlScalarType::UInt64.nullable(false))
2363 .with_column(
2364 "collection_timestamp",
2365 SqlScalarType::TimestampTz { precision: None }.nullable(false),
2366 )
2367 .with_key(vec![0, 2])
2368 .finish(),
2369 column_comments: BTreeMap::from_iter([
2370 (
2371 "object_id",
2372 "The ID of the table, source, or materialized view.",
2373 ),
2374 (
2375 "size_bytes",
2376 "The number of storage bytes used by the object.",
2377 ),
2378 (
2379 "collection_timestamp",
2380 "The time at which storage usage of the object was assessed.",
2381 ),
2382 ]),
2383 sql: "
2384SELECT
2385 object_id,
2386 sum(size_bytes)::uint8 AS size_bytes,
2387 collection_timestamp
2388FROM
2389 mz_internal.mz_storage_shards
2390 JOIN mz_internal.mz_storage_usage_by_shard USING (shard_id)
2391GROUP BY object_id, collection_timestamp",
2392 access: vec![PUBLIC_SELECT],
2393 ontology: Some(Ontology {
2394 entity_name: "storage_usage",
2395 description: "Historical storage usage per object over time",
2396 links: &const {
2397 [OntologyLink {
2398 name: "storage_usage_of",
2399 target: "object",
2400 properties: LinkProperties::fk("object_id", "id", Cardinality::ManyToOne),
2401 }]
2402 },
2403 column_semantic_types: &const {
2404 [
2405 ("object_id", SemanticType::CatalogItemId),
2406 ("size_bytes", SemanticType::ByteCount),
2407 ("collection_timestamp", SemanticType::WallclockTimestamp),
2408 ]
2409 },
2410 }),
2411});
2412
2413pub static MZ_RECENT_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| {
2414 BuiltinView {
2415 name: "mz_recent_storage_usage",
2416 schema: MZ_CATALOG_SCHEMA,
2417 oid: oid::VIEW_MZ_RECENT_STORAGE_USAGE_OID,
2418 desc: RelationDesc::builder()
2419 .with_column("object_id", SqlScalarType::String.nullable(false))
2420 .with_column("size_bytes", SqlScalarType::UInt64.nullable(true))
2421 .with_key(vec![0])
2422 .finish(),
2423 column_comments: BTreeMap::from_iter([
2424 ("object_id", "The ID of the table, source, or materialized view."),
2425 ("size_bytes", "The number of storage bytes used by the object in the most recent assessment."),
2426 ]),
2427 sql: "
2428WITH
2429
2430recent_storage_usage_by_shard AS (
2431 SELECT shard_id, size_bytes, collection_timestamp
2432 FROM mz_internal.mz_storage_usage_by_shard
2433 -- Restricting to the last 6 hours makes it feasible to index the view.
2434 WHERE collection_timestamp + '6 hours' >= mz_now()
2435),
2436
2437most_recent_collection_timestamp_by_shard AS (
2438 SELECT shard_id, max(collection_timestamp) AS collection_timestamp
2439 FROM recent_storage_usage_by_shard
2440 GROUP BY shard_id
2441)
2442
2443SELECT
2444 object_id,
2445 sum(size_bytes)::uint8 AS size_bytes
2446FROM
2447 mz_internal.mz_storage_shards
2448 LEFT JOIN most_recent_collection_timestamp_by_shard
2449 ON mz_storage_shards.shard_id = most_recent_collection_timestamp_by_shard.shard_id
2450 LEFT JOIN recent_storage_usage_by_shard
2451 ON mz_storage_shards.shard_id = recent_storage_usage_by_shard.shard_id
2452 AND most_recent_collection_timestamp_by_shard.collection_timestamp = recent_storage_usage_by_shard.collection_timestamp
2453GROUP BY object_id",
2454 access: vec![PUBLIC_SELECT],
2455 ontology: Some(Ontology {
2456 entity_name: "recent_storage",
2457 description: "Most recent storage usage snapshot per object",
2458 links: &const { [
2459 OntologyLink { name: "recent_storage_of", target: "object", properties: LinkProperties::fk("object_id", "id", Cardinality::OneToOne) },
2460 ] },
2461 column_semantic_types: &const {[("object_id", SemanticType::CatalogItemId), ("size_bytes", SemanticType::ByteCount)]},
2462 }),
2463}
2464});
2465
2466pub static MZ_RECENT_STORAGE_USAGE_IND: LazyLock<BuiltinIndex> = LazyLock::new(|| BuiltinIndex {
2467 name: "mz_recent_storage_usage_ind",
2468 schema: MZ_CATALOG_SCHEMA,
2469 oid: oid::INDEX_MZ_RECENT_STORAGE_USAGE_IND_OID,
2470 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_recent_storage_usage (object_id)",
2471 is_retained_metrics_object: false,
2472});
2473
2474pub static MZ_RELATIONS: LazyLock<BuiltinView> = LazyLock::new(|| {
2475 BuiltinView {
2476 name: "mz_relations",
2477 schema: MZ_CATALOG_SCHEMA,
2478 oid: oid::VIEW_MZ_RELATIONS_OID,
2479 desc: RelationDesc::builder()
2480 .with_column("id", SqlScalarType::String.nullable(false))
2481 .with_column("oid", SqlScalarType::Oid.nullable(false))
2482 .with_column("schema_id", SqlScalarType::String.nullable(false))
2483 .with_column("name", SqlScalarType::String.nullable(false))
2484 .with_column("type", SqlScalarType::String.nullable(false))
2485 .with_column("owner_id", SqlScalarType::String.nullable(false))
2486 .with_column("cluster_id", SqlScalarType::String.nullable(true))
2487 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false))
2488 .finish(),
2489 column_comments: BTreeMap::from_iter([
2490 ("id", "Materialize's unique ID for the relation."),
2491 ("oid", "A PostgreSQL-compatible OID for the relation."),
2492 ("schema_id", "The ID of the schema to which the relation belongs. Corresponds to `mz_schemas.id`."),
2493 ("name", "The name of the relation."),
2494 ("type", "The type of the relation: either `table`, `source`, `view`, or `materialized-view`."),
2495 ("owner_id", "The role ID of the owner of the relation. Corresponds to `mz_roles.id`."),
2496 ("cluster_id", "The ID of the cluster maintaining the source, materialized view, index, or sink. Corresponds to `mz_clusters.id`. `NULL` for other object types."),
2497 ("privileges", "The privileges belonging to the relation."),
2498 ]),
2499 sql: "
2500 SELECT id, oid, schema_id, name, 'table' AS type, owner_id, NULL::text AS cluster_id, privileges FROM mz_catalog.mz_tables
2501UNION ALL SELECT id, oid, schema_id, name, 'source', owner_id, cluster_id, privileges FROM mz_catalog.mz_sources
2502UNION ALL SELECT id, oid, schema_id, name, 'view', owner_id, NULL::text, privileges FROM mz_catalog.mz_views
2503UNION ALL SELECT id, oid, schema_id, name, 'materialized-view', owner_id, cluster_id, privileges FROM mz_catalog.mz_materialized_views",
2504 access: vec![PUBLIC_SELECT],
2505 ontology: Some(Ontology {
2506 entity_name: "relation",
2507 description: "Union of all relation types: tables, sources, views, MVs (convenience view)",
2508 links: &const { [
2509 OntologyLink { name: "union_includes", target: "table", properties: LinkProperties::union_disc("type", "table") },
2510 OntologyLink { name: "union_includes", target: "source", properties: LinkProperties::union_disc("type", "source") },
2511 OntologyLink { name: "union_includes", target: "view", properties: LinkProperties::union_disc("type", "view") },
2512 OntologyLink { name: "union_includes", target: "mv", properties: LinkProperties::union_disc("type", "materialized-view") },
2513 ] },
2514 column_semantic_types: &const {[("id", SemanticType::CatalogItemId), ("oid", SemanticType::OID), ("schema_id", SemanticType::SchemaId), ("type", SemanticType::ObjectType), ("owner_id", SemanticType::RoleId), ("cluster_id", SemanticType::ClusterId)]},
2515 }),
2516 }
2517});
2518
2519pub static MZ_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| {
2520 BuiltinView {
2521 name: "mz_objects",
2522 schema: MZ_CATALOG_SCHEMA,
2523 oid: oid::VIEW_MZ_OBJECTS_OID,
2524 desc: RelationDesc::builder()
2525 .with_column("id", SqlScalarType::String.nullable(false))
2526 .with_column("oid", SqlScalarType::Oid.nullable(false))
2527 .with_column("schema_id", SqlScalarType::String.nullable(false))
2528 .with_column("name", SqlScalarType::String.nullable(false))
2529 .with_column("type", SqlScalarType::String.nullable(false))
2530 .with_column("owner_id", SqlScalarType::String.nullable(false))
2531 .with_column("cluster_id", SqlScalarType::String.nullable(true))
2532 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(true))
2533 .finish(),
2534 column_comments: BTreeMap::from_iter([
2535 ("id", "Materialize's unique ID for the object."),
2536 ("oid", "A PostgreSQL-compatible OID for the object."),
2537 ("schema_id", "The ID of the schema to which the object belongs. Corresponds to `mz_schemas.id`."),
2538 ("name", "The name of the object."),
2539 ("type", "The type of the object: one of `table`, `source`, `view`, `materialized-view`, `sink`, `index`, `connection`, `secret`, `type`, or `function`."),
2540 ("owner_id", "The role ID of the owner of the object. Corresponds to `mz_roles.id`."),
2541 ("cluster_id", "The ID of the cluster maintaining the source, materialized view, index, or sink. Corresponds to `mz_clusters.id`. `NULL` for other object types."),
2542 ("privileges", "The privileges belonging to the object."),
2543 ]),
2544 sql:
2545 "SELECT id, oid, schema_id, name, type, owner_id, cluster_id, privileges FROM mz_catalog.mz_relations
2546UNION ALL
2547 SELECT id, oid, schema_id, name, 'sink', owner_id, cluster_id, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_sinks
2548UNION ALL
2549 SELECT mz_indexes.id, mz_indexes.oid, mz_relations.schema_id, mz_indexes.name, 'index', mz_indexes.owner_id, mz_indexes.cluster_id, NULL::mz_catalog.mz_aclitem[]
2550 FROM mz_catalog.mz_indexes
2551 JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
2552UNION ALL
2553 SELECT id, oid, schema_id, name, 'connection', owner_id, NULL::text, privileges FROM mz_catalog.mz_connections
2554UNION ALL
2555 SELECT id, oid, schema_id, name, 'type', owner_id, NULL::text, privileges FROM mz_catalog.mz_types
2556UNION ALL
2557 SELECT id, oid, schema_id, name, 'function', owner_id, NULL::text, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_functions
2558UNION ALL
2559 SELECT id, oid, schema_id, name, 'secret', owner_id, NULL::text, privileges FROM mz_catalog.mz_secrets",
2560 access: vec![PUBLIC_SELECT],
2561 ontology: Some(Ontology {
2562 entity_name: "object",
2563 description: "Union of all object types: relations, indexes, connections, etc. (convenience view)",
2564 links: &const {
2565 [
2566 OntologyLink {
2567 name: "union_includes",
2568 target: "relation",
2569 properties: LinkProperties::Union {
2570 discriminator_column: None,
2571 discriminator_value: None,
2572 note: Some("covers all mz_relations rows (table, source, view, mv)"),
2573 },
2574 },
2575 OntologyLink {
2576 name: "union_includes",
2577 target: "table",
2578 properties: LinkProperties::union_disc("type", "table"),
2579 },
2580 OntologyLink {
2581 name: "union_includes",
2582 target: "source",
2583 properties: LinkProperties::union_disc("type", "source"),
2584 },
2585 OntologyLink {
2586 name: "union_includes",
2587 target: "view",
2588 properties: LinkProperties::union_disc("type", "view"),
2589 },
2590 OntologyLink {
2591 name: "union_includes",
2592 target: "mv",
2593 properties: LinkProperties::union_disc("type", "materialized-view"),
2594 },
2595 OntologyLink {
2596 name: "union_includes",
2597 target: "sink",
2598 properties: LinkProperties::union_disc("type", "sink"),
2599 },
2600 OntologyLink {
2601 name: "union_includes",
2602 target: "index",
2603 properties: LinkProperties::union_disc("type", "index"),
2604 },
2605 OntologyLink {
2606 name: "union_includes",
2607 target: "connection",
2608 properties: LinkProperties::union_disc("type", "connection"),
2609 },
2610 OntologyLink {
2611 name: "union_includes",
2612 target: "type",
2613 properties: LinkProperties::union_disc("type", "type"),
2614 },
2615 OntologyLink {
2616 name: "union_includes",
2617 target: "function",
2618 properties: LinkProperties::union_disc("type", "function"),
2619 },
2620 OntologyLink {
2621 name: "union_includes",
2622 target: "secret",
2623 properties: LinkProperties::union_disc("type", "secret"),
2624 },
2625 OntologyLink {
2626 name: "in_schema",
2627 target: "schema",
2628 properties: LinkProperties::fk("schema_id", "id", Cardinality::ManyToOne),
2629 },
2630 OntologyLink {
2631 name: "owned_by",
2632 target: "role",
2633 properties: LinkProperties::fk("owner_id", "id", Cardinality::ManyToOne),
2634 },
2635 OntologyLink {
2636 name: "on_cluster",
2637 target: "cluster",
2638 properties: LinkProperties::fk_nullable(
2639 "cluster_id",
2640 "id",
2641 Cardinality::ManyToOne,
2642 ),
2643 },
2644 ]
2645 },
2646 column_semantic_types: &const {
2647 [
2648 ("id", SemanticType::CatalogItemId),
2649 ("oid", SemanticType::OID),
2650 ("schema_id", SemanticType::SchemaId),
2651 ("type", SemanticType::ObjectType),
2652 ("owner_id", SemanticType::RoleId),
2653 ("cluster_id", SemanticType::ClusterId),
2654 ]
2655 },
2656 }),
2657 }
2658});
2659
2660pub static MZ_TIMEZONE_ABBREVIATIONS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2661 name: "mz_timezone_abbreviations",
2662 schema: MZ_CATALOG_SCHEMA,
2663 oid: oid::VIEW_MZ_TIMEZONE_ABBREVIATIONS_OID,
2664 desc: RelationDesc::builder()
2665 .with_column("abbreviation", SqlScalarType::String.nullable(false))
2666 .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
2667 .with_column("dst", SqlScalarType::Bool.nullable(true))
2668 .with_column("timezone_name", SqlScalarType::String.nullable(true))
2669 .with_key(vec![0])
2670 .finish(),
2671 column_comments: BTreeMap::from_iter([
2672 ("abbreviation", "The timezone abbreviation."),
2673 (
2674 "utc_offset",
2675 "The UTC offset of the timezone or `NULL` if fixed.",
2676 ),
2677 (
2678 "dst",
2679 "Whether the timezone is in daylight savings or `NULL` if fixed.",
2680 ),
2681 (
2682 "timezone_name",
2683 "The full name of the non-fixed timezone or `NULL` if not fixed.",
2684 ),
2685 ]),
2686 sql: format!(
2687 "SELECT * FROM ({}) _ (abbreviation, utc_offset, dst, timezone_name)",
2688 mz_pgtz::abbrev::MZ_CATALOG_TIMEZONE_ABBREVIATIONS_SQL,
2689 )
2690 .leak(),
2691 access: vec![PUBLIC_SELECT],
2692 ontology: None,
2693});
2694
2695pub static MZ_TIMEZONE_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2696 name: "mz_timezone_names",
2697 schema: MZ_CATALOG_SCHEMA,
2698 oid: oid::VIEW_MZ_TIMEZONE_NAMES_OID,
2699 desc: RelationDesc::builder()
2700 .with_column("name", SqlScalarType::String.nullable(false))
2701 .with_key(vec![0])
2702 .finish(),
2703 column_comments: BTreeMap::from_iter([("name", "The timezone name.")]),
2704 sql: format!(
2705 "SELECT * FROM ({}) _ (name)",
2706 mz_pgtz::timezone::MZ_CATALOG_TIMEZONE_NAMES_SQL,
2707 )
2708 .leak(),
2709 access: vec![PUBLIC_SELECT],
2710 ontology: None,
2711});
2712
2713pub const MZ_DATABASES_IND: BuiltinIndex = BuiltinIndex {
2714 name: "mz_databases_ind",
2715 schema: MZ_CATALOG_SCHEMA,
2716 oid: oid::INDEX_MZ_DATABASES_IND_OID,
2717 sql: "IN CLUSTER mz_catalog_server
2718ON mz_catalog.mz_databases (name)",
2719 is_retained_metrics_object: false,
2720};
2721
2722pub const MZ_SCHEMAS_IND: BuiltinIndex = BuiltinIndex {
2723 name: "mz_schemas_ind",
2724 schema: MZ_CATALOG_SCHEMA,
2725 oid: oid::INDEX_MZ_SCHEMAS_IND_OID,
2726 sql: "IN CLUSTER mz_catalog_server
2727ON mz_catalog.mz_schemas (database_id)",
2728 is_retained_metrics_object: false,
2729};
2730
2731pub const MZ_CONNECTIONS_IND: BuiltinIndex = BuiltinIndex {
2732 name: "mz_connections_ind",
2733 schema: MZ_CATALOG_SCHEMA,
2734 oid: oid::INDEX_MZ_CONNECTIONS_IND_OID,
2735 sql: "IN CLUSTER mz_catalog_server
2736ON mz_catalog.mz_connections (schema_id)",
2737 is_retained_metrics_object: false,
2738};
2739
2740pub const MZ_TABLES_IND: BuiltinIndex = BuiltinIndex {
2741 name: "mz_tables_ind",
2742 schema: MZ_CATALOG_SCHEMA,
2743 oid: oid::INDEX_MZ_TABLES_IND_OID,
2744 sql: "IN CLUSTER mz_catalog_server
2745ON mz_catalog.mz_tables (schema_id)",
2746 is_retained_metrics_object: false,
2747};
2748
2749pub const MZ_TYPES_IND: BuiltinIndex = BuiltinIndex {
2750 name: "mz_types_ind",
2751 schema: MZ_CATALOG_SCHEMA,
2752 oid: oid::INDEX_MZ_TYPES_IND_OID,
2753 sql: "IN CLUSTER mz_catalog_server
2754ON mz_catalog.mz_types (schema_id)",
2755 is_retained_metrics_object: false,
2756};
2757
2758pub const MZ_OBJECTS_IND: BuiltinIndex = BuiltinIndex {
2759 name: "mz_objects_ind",
2760 schema: MZ_CATALOG_SCHEMA,
2761 oid: oid::INDEX_MZ_OBJECTS_IND_OID,
2762 sql: "IN CLUSTER mz_catalog_server
2763ON mz_catalog.mz_objects (schema_id)",
2764 is_retained_metrics_object: false,
2765};
2766
2767pub const MZ_COLUMNS_IND: BuiltinIndex = BuiltinIndex {
2768 name: "mz_columns_ind",
2769 schema: MZ_CATALOG_SCHEMA,
2770 oid: oid::INDEX_MZ_COLUMNS_IND_OID,
2771 sql: "IN CLUSTER mz_catalog_server
2772ON mz_catalog.mz_columns (name)",
2773 is_retained_metrics_object: false,
2774};
2775
2776pub const MZ_SECRETS_IND: BuiltinIndex = BuiltinIndex {
2777 name: "mz_secrets_ind",
2778 schema: MZ_CATALOG_SCHEMA,
2779 oid: oid::INDEX_MZ_SECRETS_IND_OID,
2780 sql: "IN CLUSTER mz_catalog_server
2781ON mz_catalog.mz_secrets (name)",
2782 is_retained_metrics_object: false,
2783};
2784
2785pub const MZ_VIEWS_IND: BuiltinIndex = BuiltinIndex {
2786 name: "mz_views_ind",
2787 schema: MZ_CATALOG_SCHEMA,
2788 oid: oid::INDEX_MZ_VIEWS_IND_OID,
2789 sql: "IN CLUSTER mz_catalog_server
2790ON mz_catalog.mz_views (schema_id)",
2791 is_retained_metrics_object: false,
2792};
2793
2794pub const MZ_CLUSTERS_IND: BuiltinIndex = BuiltinIndex {
2795 name: "mz_clusters_ind",
2796 schema: MZ_CATALOG_SCHEMA,
2797 oid: oid::INDEX_MZ_CLUSTERS_IND_OID,
2798 sql: "IN CLUSTER mz_catalog_server
2799ON mz_catalog.mz_clusters (id)",
2800 is_retained_metrics_object: false,
2801};
2802
2803pub const MZ_INDEXES_IND: BuiltinIndex = BuiltinIndex {
2804 name: "mz_indexes_ind",
2805 schema: MZ_CATALOG_SCHEMA,
2806 oid: oid::INDEX_MZ_INDEXES_IND_OID,
2807 sql: "IN CLUSTER mz_catalog_server
2808ON mz_catalog.mz_indexes (id)",
2809 is_retained_metrics_object: false,
2810};
2811
2812pub const MZ_ROLES_IND: BuiltinIndex = BuiltinIndex {
2813 name: "mz_roles_ind",
2814 schema: MZ_CATALOG_SCHEMA,
2815 oid: oid::INDEX_MZ_ROLES_IND_OID,
2816 sql: "IN CLUSTER mz_catalog_server
2817ON mz_catalog.mz_roles (id)",
2818 is_retained_metrics_object: false,
2819};
2820
2821pub const MZ_SOURCES_IND: BuiltinIndex = BuiltinIndex {
2822 name: "mz_sources_ind",
2823 schema: MZ_CATALOG_SCHEMA,
2824 oid: oid::INDEX_MZ_SOURCES_IND_OID,
2825 sql: "IN CLUSTER mz_catalog_server
2826ON mz_catalog.mz_sources (id)",
2827 is_retained_metrics_object: true,
2828};
2829
2830pub const MZ_SINKS_IND: BuiltinIndex = BuiltinIndex {
2831 name: "mz_sinks_ind",
2832 schema: MZ_CATALOG_SCHEMA,
2833 oid: oid::INDEX_MZ_SINKS_IND_OID,
2834 sql: "IN CLUSTER mz_catalog_server
2835ON mz_catalog.mz_sinks (id)",
2836 is_retained_metrics_object: true,
2837};
2838
2839pub const MZ_MATERIALIZED_VIEWS_IND: BuiltinIndex = BuiltinIndex {
2840 name: "mz_materialized_views_ind",
2841 schema: MZ_CATALOG_SCHEMA,
2842 oid: oid::INDEX_MZ_MATERIALIZED_VIEWS_IND_OID,
2843 sql: "IN CLUSTER mz_catalog_server
2844ON mz_catalog.mz_materialized_views (id)",
2845 is_retained_metrics_object: false,
2846};
2847
2848pub const MZ_CLUSTER_REPLICAS_IND: BuiltinIndex = BuiltinIndex {
2849 name: "mz_cluster_replicas_ind",
2850 schema: MZ_CATALOG_SCHEMA,
2851 oid: oid::INDEX_MZ_CLUSTER_REPLICAS_IND_OID,
2852 sql: "IN CLUSTER mz_catalog_server
2853ON mz_catalog.mz_cluster_replicas (id)",
2854 is_retained_metrics_object: true,
2855};
2856
2857pub const MZ_CLUSTER_REPLICA_SIZES_IND: BuiltinIndex = BuiltinIndex {
2858 name: "mz_cluster_replica_sizes_ind",
2859 schema: MZ_CATALOG_SCHEMA,
2860 oid: oid::INDEX_MZ_CLUSTER_REPLICA_SIZES_IND_OID,
2861 sql: "IN CLUSTER mz_catalog_server
2862ON mz_catalog.mz_cluster_replica_sizes (size)",
2863 is_retained_metrics_object: true,
2864};
2865
2866pub const MZ_KAFKA_SOURCES_IND: BuiltinIndex = BuiltinIndex {
2867 name: "mz_kafka_sources_ind",
2868 schema: MZ_CATALOG_SCHEMA,
2869 oid: oid::INDEX_MZ_KAFKA_SOURCES_IND_OID,
2870 sql: "IN CLUSTER mz_catalog_server
2871ON mz_catalog.mz_kafka_sources (id)",
2872 is_retained_metrics_object: true,
2873};