1pub mod notice;
26
27use std::collections::BTreeMap;
28use std::hash::Hash;
29use std::string::ToString;
30use std::sync::LazyLock;
31
32use mz_compute_client::logging::{ComputeLog, DifferentialLog, LogVariant, TimelyLog};
33use mz_ore::collections::HashMap;
34use mz_pgrepr::oid;
35use mz_repr::adt::mz_acl_item::{AclMode, MzAclItem};
36use mz_repr::adt::numeric::NumericMaxScale;
37use mz_repr::namespaces::{
38 INFORMATION_SCHEMA, MZ_CATALOG_SCHEMA, MZ_INTERNAL_SCHEMA, MZ_INTROSPECTION_SCHEMA,
39 MZ_UNSAFE_SCHEMA, PG_CATALOG_SCHEMA,
40};
41use mz_repr::role_id::RoleId;
42use mz_repr::{RelationDesc, SqlRelationType, SqlScalarType};
43use mz_sql::catalog::RoleAttributesRaw;
44use mz_sql::catalog::{
45 CatalogItemType, CatalogType, CatalogTypeDetails, CatalogTypePgMetadata, NameReference,
46 ObjectType, SystemObjectType, TypeReference,
47};
48use mz_sql::rbac;
49use mz_sql::session::user::{
50 ANALYTICS_USER_NAME, MZ_ANALYTICS_ROLE_ID, MZ_MONITOR_REDACTED_ROLE_ID, MZ_MONITOR_ROLE_ID,
51 MZ_SUPPORT_ROLE_ID, MZ_SYSTEM_ROLE_ID, SUPPORT_USER_NAME, SYSTEM_USER_NAME,
52};
53use mz_storage_client::controller::IntrospectionType;
54use mz_storage_client::healthcheck::WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW_DESC;
55use mz_storage_client::healthcheck::{
56 MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_DESC, MZ_PREPARED_STATEMENT_HISTORY_DESC,
57 MZ_SESSION_HISTORY_DESC, MZ_SINK_STATUS_HISTORY_DESC, MZ_SOURCE_STATUS_HISTORY_DESC,
58 MZ_SQL_TEXT_DESC, MZ_STATEMENT_EXECUTION_HISTORY_DESC, REPLICA_METRICS_HISTORY_DESC,
59 REPLICA_STATUS_HISTORY_DESC, WALLCLOCK_LAG_HISTORY_DESC,
60};
61use mz_storage_client::statistics::{MZ_SINK_STATISTICS_RAW_DESC, MZ_SOURCE_STATISTICS_RAW_DESC};
62use serde::Serialize;
63
64use crate::durable::objects::SystemObjectDescription;
65use crate::memory::objects::DataSourceDesc;
66
67pub const BUILTIN_PREFIXES: &[&str] = &["mz_", "pg_", "external_"];
68const BUILTIN_CLUSTER_REPLICA_NAME: &str = "r1";
69
70pub const RUNTIME_ALTERABLE_FINGERPRINT_SENTINEL: &str = "<RUNTIME-ALTERABLE>";
86
87#[derive(Clone, Debug)]
88pub enum Builtin<T: 'static + TypeReference> {
89 Log(&'static BuiltinLog),
90 Table(&'static BuiltinTable),
91 View(&'static BuiltinView),
92 Type(&'static BuiltinType<T>),
93 Func(BuiltinFunc),
94 Source(&'static BuiltinSource),
95 ContinualTask(&'static BuiltinContinualTask),
96 Index(&'static BuiltinIndex),
97 Connection(&'static BuiltinConnection),
98}
99
100impl<T: TypeReference> Builtin<T> {
101 pub fn name(&self) -> &'static str {
102 match self {
103 Builtin::Log(log) => log.name,
104 Builtin::Table(table) => table.name,
105 Builtin::View(view) => view.name,
106 Builtin::Type(typ) => typ.name,
107 Builtin::Func(func) => func.name,
108 Builtin::Source(coll) => coll.name,
109 Builtin::ContinualTask(ct) => ct.name,
110 Builtin::Index(index) => index.name,
111 Builtin::Connection(connection) => connection.name,
112 }
113 }
114
115 pub fn schema(&self) -> &'static str {
116 match self {
117 Builtin::Log(log) => log.schema,
118 Builtin::Table(table) => table.schema,
119 Builtin::View(view) => view.schema,
120 Builtin::Type(typ) => typ.schema,
121 Builtin::Func(func) => func.schema,
122 Builtin::Source(coll) => coll.schema,
123 Builtin::ContinualTask(ct) => ct.schema,
124 Builtin::Index(index) => index.schema,
125 Builtin::Connection(connection) => connection.schema,
126 }
127 }
128
129 pub fn catalog_item_type(&self) -> CatalogItemType {
130 match self {
131 Builtin::Log(_) => CatalogItemType::Source,
132 Builtin::Source(_) => CatalogItemType::Source,
133 Builtin::ContinualTask(_) => CatalogItemType::ContinualTask,
134 Builtin::Table(_) => CatalogItemType::Table,
135 Builtin::View(_) => CatalogItemType::View,
136 Builtin::Type(_) => CatalogItemType::Type,
137 Builtin::Func(_) => CatalogItemType::Func,
138 Builtin::Index(_) => CatalogItemType::Index,
139 Builtin::Connection(_) => CatalogItemType::Connection,
140 }
141 }
142
143 pub fn runtime_alterable(&self) -> bool {
145 match self {
146 Builtin::Connection(c) => c.runtime_alterable,
147 _ => false,
148 }
149 }
150}
151
152#[derive(Clone, Debug, Hash, Serialize)]
153pub struct BuiltinLog {
154 pub variant: LogVariant,
155 pub name: &'static str,
156 pub schema: &'static str,
157 pub oid: u32,
158 pub access: Vec<MzAclItem>,
160}
161
162#[derive(Clone, Hash, Debug, PartialEq, Eq)]
163pub struct BuiltinTable {
164 pub name: &'static str,
165 pub schema: &'static str,
166 pub oid: u32,
167 pub desc: RelationDesc,
168 pub column_comments: BTreeMap<&'static str, &'static str>,
169 pub is_retained_metrics_object: bool,
172 pub access: Vec<MzAclItem>,
174}
175
176#[derive(Clone, Debug, PartialEq, Eq)]
177pub struct BuiltinSource {
178 pub name: &'static str,
179 pub schema: &'static str,
180 pub oid: u32,
181 pub desc: RelationDesc,
182 pub column_comments: BTreeMap<&'static str, &'static str>,
183 pub data_source: DataSourceDesc,
184 pub is_retained_metrics_object: bool,
187 pub access: Vec<MzAclItem>,
189}
190
191#[derive(Hash, Debug, PartialEq, Eq)]
192pub struct BuiltinContinualTask {
193 pub name: &'static str,
194 pub schema: &'static str,
195 pub oid: u32,
196 pub desc: RelationDesc,
197 pub sql: &'static str,
198 pub access: Vec<MzAclItem>,
200}
201
202#[derive(Hash, Debug)]
203pub struct BuiltinView {
204 pub name: &'static str,
205 pub schema: &'static str,
206 pub oid: u32,
207 pub desc: RelationDesc,
208 pub column_comments: BTreeMap<&'static str, &'static str>,
209 pub sql: &'static str,
210 pub access: Vec<MzAclItem>,
212}
213
214impl BuiltinView {
215 pub fn create_sql(&self) -> String {
216 format!("CREATE VIEW {}.{} AS {}", self.schema, self.name, self.sql)
217 }
218}
219
220#[derive(Debug)]
221pub struct BuiltinType<T: TypeReference> {
222 pub name: &'static str,
223 pub schema: &'static str,
224 pub oid: u32,
225 pub details: CatalogTypeDetails<T>,
226}
227
228#[derive(Clone, Debug)]
229pub struct BuiltinFunc {
230 pub schema: &'static str,
231 pub name: &'static str,
232 pub inner: &'static mz_sql::func::Func,
233}
234
235#[derive(Debug)]
241pub struct BuiltinIndex {
242 pub name: &'static str,
243 pub schema: &'static str,
244 pub oid: u32,
245 pub sql: &'static str,
249 pub is_retained_metrics_object: bool,
250}
251
252impl BuiltinIndex {
253 pub fn create_sql(&self) -> String {
254 format!("CREATE INDEX {}\n{}", self.name, self.sql)
255 }
256}
257
258impl BuiltinContinualTask {
259 pub fn create_sql(&self) -> String {
260 format!(
261 "CREATE CONTINUAL TASK {}.{}\n{}",
262 self.schema, self.name, self.sql
263 )
264 }
265}
266
267#[derive(Hash, Debug)]
268pub struct BuiltinConnection {
269 pub name: &'static str,
270 pub schema: &'static str,
271 pub oid: u32,
272 pub sql: &'static str,
273 pub access: &'static [MzAclItem],
274 pub owner_id: &'static RoleId,
275 pub runtime_alterable: bool,
280}
281
282#[derive(Clone, Debug)]
283pub struct BuiltinRole {
284 pub id: RoleId,
285 pub name: &'static str,
289 pub oid: u32,
290 pub attributes: RoleAttributesRaw,
291}
292
293#[derive(Clone, Debug)]
294pub struct BuiltinCluster {
295 pub name: &'static str,
299 pub privileges: &'static [MzAclItem],
300 pub owner_id: &'static RoleId,
301}
302
303#[derive(Clone, Debug, PartialEq, Eq)]
304pub struct BuiltinClusterReplica {
305 pub name: &'static str,
307 pub cluster_name: &'static str,
309}
310
311pub trait Fingerprint {
313 fn fingerprint(&self) -> String;
314}
315
316impl<T: TypeReference> Fingerprint for &Builtin<T> {
317 fn fingerprint(&self) -> String {
318 match self {
319 Builtin::Log(log) => log.fingerprint(),
320 Builtin::Table(table) => table.fingerprint(),
321 Builtin::View(view) => view.fingerprint(),
322 Builtin::Type(typ) => typ.fingerprint(),
323 Builtin::Func(func) => func.fingerprint(),
324 Builtin::Source(coll) => coll.fingerprint(),
325 Builtin::ContinualTask(ct) => ct.fingerprint(),
326 Builtin::Index(index) => index.fingerprint(),
327 Builtin::Connection(connection) => connection.fingerprint(),
328 }
329 }
330}
331
332impl<T: TypeReference> Fingerprint for &BuiltinType<T> {
334 fn fingerprint(&self) -> String {
335 "".to_string()
336 }
337}
338
339impl Fingerprint for &BuiltinFunc {
340 fn fingerprint(&self) -> String {
341 "".to_string()
342 }
343}
344
345impl Fingerprint for &BuiltinLog {
346 fn fingerprint(&self) -> String {
347 self.variant.desc().fingerprint()
348 }
349}
350
351impl Fingerprint for &BuiltinTable {
352 fn fingerprint(&self) -> String {
353 self.desc.fingerprint()
354 }
355}
356
357impl Fingerprint for &BuiltinView {
358 fn fingerprint(&self) -> String {
359 self.sql.to_string()
360 }
361}
362
363impl Fingerprint for &BuiltinSource {
364 fn fingerprint(&self) -> String {
365 self.desc.fingerprint()
366 }
367}
368
369impl Fingerprint for &BuiltinContinualTask {
370 fn fingerprint(&self) -> String {
371 self.create_sql()
372 }
373}
374
375impl Fingerprint for &BuiltinIndex {
376 fn fingerprint(&self) -> String {
377 self.create_sql()
378 }
379}
380
381impl Fingerprint for &BuiltinConnection {
382 fn fingerprint(&self) -> String {
383 self.sql.to_string()
384 }
385}
386
387impl Fingerprint for RelationDesc {
388 fn fingerprint(&self) -> String {
389 self.typ().fingerprint()
390 }
391}
392
393impl Fingerprint for SqlRelationType {
394 fn fingerprint(&self) -> String {
395 serde_json::to_string(self).expect("serialization cannot fail")
396 }
397}
398
399pub const TYPE_BOOL: BuiltinType<NameReference> = BuiltinType {
419 name: "bool",
420 schema: PG_CATALOG_SCHEMA,
421 oid: oid::TYPE_BOOL_OID,
422 details: CatalogTypeDetails {
423 typ: CatalogType::Bool,
424 array_id: None,
425 pg_metadata: Some(CatalogTypePgMetadata {
426 typinput_oid: 1242,
427 typreceive_oid: 2436,
428 }),
429 },
430};
431
432pub const TYPE_BYTEA: BuiltinType<NameReference> = BuiltinType {
433 name: "bytea",
434 schema: PG_CATALOG_SCHEMA,
435 oid: oid::TYPE_BYTEA_OID,
436 details: CatalogTypeDetails {
437 typ: CatalogType::Bytes,
438 array_id: None,
439 pg_metadata: Some(CatalogTypePgMetadata {
440 typinput_oid: 1244,
441 typreceive_oid: 2412,
442 }),
443 },
444};
445
446pub const TYPE_INT8: BuiltinType<NameReference> = BuiltinType {
447 name: "int8",
448 schema: PG_CATALOG_SCHEMA,
449 oid: oid::TYPE_INT8_OID,
450 details: CatalogTypeDetails {
451 typ: CatalogType::Int64,
452 array_id: None,
453 pg_metadata: Some(CatalogTypePgMetadata {
454 typinput_oid: 460,
455 typreceive_oid: 2408,
456 }),
457 },
458};
459
460pub const TYPE_INT4: BuiltinType<NameReference> = BuiltinType {
461 name: "int4",
462 schema: PG_CATALOG_SCHEMA,
463 oid: oid::TYPE_INT4_OID,
464 details: CatalogTypeDetails {
465 typ: CatalogType::Int32,
466 array_id: None,
467 pg_metadata: Some(CatalogTypePgMetadata {
468 typinput_oid: 42,
469 typreceive_oid: 2406,
470 }),
471 },
472};
473
474pub const TYPE_TEXT: BuiltinType<NameReference> = BuiltinType {
475 name: "text",
476 schema: PG_CATALOG_SCHEMA,
477 oid: oid::TYPE_TEXT_OID,
478 details: CatalogTypeDetails {
479 typ: CatalogType::String,
480 array_id: None,
481 pg_metadata: Some(CatalogTypePgMetadata {
482 typinput_oid: 46,
483 typreceive_oid: 2414,
484 }),
485 },
486};
487
488pub const TYPE_OID: BuiltinType<NameReference> = BuiltinType {
489 name: "oid",
490 schema: PG_CATALOG_SCHEMA,
491 oid: oid::TYPE_OID_OID,
492 details: CatalogTypeDetails {
493 typ: CatalogType::Oid,
494 array_id: None,
495 pg_metadata: Some(CatalogTypePgMetadata {
496 typinput_oid: 1798,
497 typreceive_oid: 2418,
498 }),
499 },
500};
501
502pub const TYPE_FLOAT4: BuiltinType<NameReference> = BuiltinType {
503 name: "float4",
504 schema: PG_CATALOG_SCHEMA,
505 oid: oid::TYPE_FLOAT4_OID,
506 details: CatalogTypeDetails {
507 typ: CatalogType::Float32,
508 array_id: None,
509 pg_metadata: Some(CatalogTypePgMetadata {
510 typinput_oid: 200,
511 typreceive_oid: 2424,
512 }),
513 },
514};
515
516pub const TYPE_FLOAT8: BuiltinType<NameReference> = BuiltinType {
517 name: "float8",
518 schema: PG_CATALOG_SCHEMA,
519 oid: oid::TYPE_FLOAT8_OID,
520 details: CatalogTypeDetails {
521 typ: CatalogType::Float64,
522 array_id: None,
523 pg_metadata: Some(CatalogTypePgMetadata {
524 typinput_oid: 214,
525 typreceive_oid: 2426,
526 }),
527 },
528};
529
530pub const TYPE_BOOL_ARRAY: BuiltinType<NameReference> = BuiltinType {
531 name: "_bool",
532 schema: PG_CATALOG_SCHEMA,
533 oid: oid::TYPE_BOOL_ARRAY_OID,
534 details: CatalogTypeDetails {
535 typ: CatalogType::Array {
536 element_reference: TYPE_BOOL.name,
537 },
538 array_id: None,
539 pg_metadata: Some(CatalogTypePgMetadata {
540 typinput_oid: 750,
541 typreceive_oid: 2400,
542 }),
543 },
544};
545
546pub const TYPE_BYTEA_ARRAY: BuiltinType<NameReference> = BuiltinType {
547 name: "_bytea",
548 schema: PG_CATALOG_SCHEMA,
549 oid: oid::TYPE_BYTEA_ARRAY_OID,
550 details: CatalogTypeDetails {
551 typ: CatalogType::Array {
552 element_reference: TYPE_BYTEA.name,
553 },
554 array_id: None,
555 pg_metadata: Some(CatalogTypePgMetadata {
556 typinput_oid: 750,
557 typreceive_oid: 2400,
558 }),
559 },
560};
561
562pub const TYPE_INT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
563 name: "_int4",
564 schema: PG_CATALOG_SCHEMA,
565 oid: oid::TYPE_INT4_ARRAY_OID,
566 details: CatalogTypeDetails {
567 typ: CatalogType::Array {
568 element_reference: TYPE_INT4.name,
569 },
570 array_id: None,
571 pg_metadata: Some(CatalogTypePgMetadata {
572 typinput_oid: 750,
573 typreceive_oid: 2400,
574 }),
575 },
576};
577
578pub const TYPE_TEXT_ARRAY: BuiltinType<NameReference> = BuiltinType {
579 name: "_text",
580 schema: PG_CATALOG_SCHEMA,
581 oid: oid::TYPE_TEXT_ARRAY_OID,
582 details: CatalogTypeDetails {
583 typ: CatalogType::Array {
584 element_reference: TYPE_TEXT.name,
585 },
586 array_id: None,
587 pg_metadata: Some(CatalogTypePgMetadata {
588 typinput_oid: 750,
589 typreceive_oid: 2400,
590 }),
591 },
592};
593
594pub const TYPE_INT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
595 name: "_int8",
596 schema: PG_CATALOG_SCHEMA,
597 oid: oid::TYPE_INT8_ARRAY_OID,
598 details: CatalogTypeDetails {
599 typ: CatalogType::Array {
600 element_reference: TYPE_INT8.name,
601 },
602 array_id: None,
603 pg_metadata: Some(CatalogTypePgMetadata {
604 typinput_oid: 750,
605 typreceive_oid: 2400,
606 }),
607 },
608};
609
610pub const TYPE_FLOAT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
611 name: "_float4",
612 schema: PG_CATALOG_SCHEMA,
613 oid: oid::TYPE_FLOAT4_ARRAY_OID,
614 details: CatalogTypeDetails {
615 typ: CatalogType::Array {
616 element_reference: TYPE_FLOAT4.name,
617 },
618 array_id: None,
619 pg_metadata: Some(CatalogTypePgMetadata {
620 typinput_oid: 750,
621 typreceive_oid: 2400,
622 }),
623 },
624};
625
626pub const TYPE_FLOAT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
627 name: "_float8",
628 schema: PG_CATALOG_SCHEMA,
629 oid: oid::TYPE_FLOAT8_ARRAY_OID,
630 details: CatalogTypeDetails {
631 typ: CatalogType::Array {
632 element_reference: TYPE_FLOAT8.name,
633 },
634 array_id: None,
635 pg_metadata: Some(CatalogTypePgMetadata {
636 typinput_oid: 750,
637 typreceive_oid: 2400,
638 }),
639 },
640};
641
642pub const TYPE_OID_ARRAY: BuiltinType<NameReference> = BuiltinType {
643 name: "_oid",
644 schema: PG_CATALOG_SCHEMA,
645 oid: oid::TYPE_OID_ARRAY_OID,
646 details: CatalogTypeDetails {
647 typ: CatalogType::Array {
648 element_reference: TYPE_OID.name,
649 },
650 array_id: None,
651 pg_metadata: Some(CatalogTypePgMetadata {
652 typinput_oid: 750,
653 typreceive_oid: 2400,
654 }),
655 },
656};
657
658pub const TYPE_DATE: BuiltinType<NameReference> = BuiltinType {
659 name: "date",
660 schema: PG_CATALOG_SCHEMA,
661 oid: oid::TYPE_DATE_OID,
662 details: CatalogTypeDetails {
663 typ: CatalogType::Date,
664 array_id: None,
665 pg_metadata: Some(CatalogTypePgMetadata {
666 typinput_oid: 1084,
667 typreceive_oid: 2468,
668 }),
669 },
670};
671
672pub const TYPE_TIME: BuiltinType<NameReference> = BuiltinType {
673 name: "time",
674 schema: PG_CATALOG_SCHEMA,
675 oid: oid::TYPE_TIME_OID,
676 details: CatalogTypeDetails {
677 typ: CatalogType::Time,
678 array_id: None,
679 pg_metadata: Some(CatalogTypePgMetadata {
680 typinput_oid: 1143,
681 typreceive_oid: 2470,
682 }),
683 },
684};
685
686pub const TYPE_TIMESTAMP: BuiltinType<NameReference> = BuiltinType {
687 name: "timestamp",
688 schema: PG_CATALOG_SCHEMA,
689 oid: oid::TYPE_TIMESTAMP_OID,
690 details: CatalogTypeDetails {
691 typ: CatalogType::Timestamp,
692 array_id: None,
693 pg_metadata: Some(CatalogTypePgMetadata {
694 typinput_oid: 1312,
695 typreceive_oid: 2474,
696 }),
697 },
698};
699
700pub const TYPE_TIMESTAMP_ARRAY: BuiltinType<NameReference> = BuiltinType {
701 name: "_timestamp",
702 schema: PG_CATALOG_SCHEMA,
703 oid: oid::TYPE_TIMESTAMP_ARRAY_OID,
704 details: CatalogTypeDetails {
705 typ: CatalogType::Array {
706 element_reference: TYPE_TIMESTAMP.name,
707 },
708 array_id: None,
709 pg_metadata: Some(CatalogTypePgMetadata {
710 typinput_oid: 750,
711 typreceive_oid: 2400,
712 }),
713 },
714};
715
716pub const TYPE_DATE_ARRAY: BuiltinType<NameReference> = BuiltinType {
717 name: "_date",
718 schema: PG_CATALOG_SCHEMA,
719 oid: oid::TYPE_DATE_ARRAY_OID,
720 details: CatalogTypeDetails {
721 typ: CatalogType::Array {
722 element_reference: TYPE_DATE.name,
723 },
724 array_id: None,
725 pg_metadata: Some(CatalogTypePgMetadata {
726 typinput_oid: 750,
727 typreceive_oid: 2400,
728 }),
729 },
730};
731
732pub const TYPE_TIME_ARRAY: BuiltinType<NameReference> = BuiltinType {
733 name: "_time",
734 schema: PG_CATALOG_SCHEMA,
735 oid: oid::TYPE_TIME_ARRAY_OID,
736 details: CatalogTypeDetails {
737 typ: CatalogType::Array {
738 element_reference: TYPE_TIME.name,
739 },
740 array_id: None,
741 pg_metadata: Some(CatalogTypePgMetadata {
742 typinput_oid: 750,
743 typreceive_oid: 2400,
744 }),
745 },
746};
747
748pub const TYPE_TIMESTAMPTZ: BuiltinType<NameReference> = BuiltinType {
749 name: "timestamptz",
750 schema: PG_CATALOG_SCHEMA,
751 oid: oid::TYPE_TIMESTAMPTZ_OID,
752 details: CatalogTypeDetails {
753 typ: CatalogType::TimestampTz,
754 array_id: None,
755 pg_metadata: Some(CatalogTypePgMetadata {
756 typinput_oid: 1150,
757 typreceive_oid: 2476,
758 }),
759 },
760};
761
762pub const TYPE_TIMESTAMPTZ_ARRAY: BuiltinType<NameReference> = BuiltinType {
763 name: "_timestamptz",
764 schema: PG_CATALOG_SCHEMA,
765 oid: oid::TYPE_TIMESTAMPTZ_ARRAY_OID,
766 details: CatalogTypeDetails {
767 typ: CatalogType::Array {
768 element_reference: TYPE_TIMESTAMPTZ.name,
769 },
770 array_id: None,
771 pg_metadata: Some(CatalogTypePgMetadata {
772 typinput_oid: 750,
773 typreceive_oid: 2400,
774 }),
775 },
776};
777
778pub const TYPE_INTERVAL: BuiltinType<NameReference> = BuiltinType {
779 name: "interval",
780 schema: PG_CATALOG_SCHEMA,
781 oid: oid::TYPE_INTERVAL_OID,
782 details: CatalogTypeDetails {
783 typ: CatalogType::Interval,
784 array_id: None,
785 pg_metadata: Some(CatalogTypePgMetadata {
786 typinput_oid: 1160,
787 typreceive_oid: 2478,
788 }),
789 },
790};
791
792pub const TYPE_INTERVAL_ARRAY: BuiltinType<NameReference> = BuiltinType {
793 name: "_interval",
794 schema: PG_CATALOG_SCHEMA,
795 oid: oid::TYPE_INTERVAL_ARRAY_OID,
796 details: CatalogTypeDetails {
797 typ: CatalogType::Array {
798 element_reference: TYPE_INTERVAL.name,
799 },
800 array_id: None,
801 pg_metadata: Some(CatalogTypePgMetadata {
802 typinput_oid: 750,
803 typreceive_oid: 2400,
804 }),
805 },
806};
807
808pub const TYPE_NAME: BuiltinType<NameReference> = BuiltinType {
809 name: "name",
810 schema: PG_CATALOG_SCHEMA,
811 oid: oid::TYPE_NAME_OID,
812 details: CatalogTypeDetails {
813 typ: CatalogType::PgLegacyName,
814 array_id: None,
815 pg_metadata: Some(CatalogTypePgMetadata {
816 typinput_oid: 34,
817 typreceive_oid: 2422,
818 }),
819 },
820};
821
822pub const TYPE_NAME_ARRAY: BuiltinType<NameReference> = BuiltinType {
823 name: "_name",
824 schema: PG_CATALOG_SCHEMA,
825 oid: oid::TYPE_NAME_ARRAY_OID,
826 details: CatalogTypeDetails {
827 typ: CatalogType::Array {
828 element_reference: TYPE_NAME.name,
829 },
830 array_id: None,
831 pg_metadata: Some(CatalogTypePgMetadata {
832 typinput_oid: 750,
833 typreceive_oid: 2400,
834 }),
835 },
836};
837
838pub const TYPE_NUMERIC: BuiltinType<NameReference> = BuiltinType {
839 name: "numeric",
840 schema: PG_CATALOG_SCHEMA,
841 oid: oid::TYPE_NUMERIC_OID,
842 details: CatalogTypeDetails {
843 typ: CatalogType::Numeric,
844 array_id: None,
845 pg_metadata: Some(CatalogTypePgMetadata {
846 typinput_oid: 1701,
847 typreceive_oid: 2460,
848 }),
849 },
850};
851
852pub const TYPE_NUMERIC_ARRAY: BuiltinType<NameReference> = BuiltinType {
853 name: "_numeric",
854 schema: PG_CATALOG_SCHEMA,
855 oid: oid::TYPE_NUMERIC_ARRAY_OID,
856 details: CatalogTypeDetails {
857 typ: CatalogType::Array {
858 element_reference: TYPE_NUMERIC.name,
859 },
860 array_id: None,
861 pg_metadata: Some(CatalogTypePgMetadata {
862 typinput_oid: 750,
863 typreceive_oid: 2400,
864 }),
865 },
866};
867
868pub const TYPE_RECORD: BuiltinType<NameReference> = BuiltinType {
869 name: "record",
870 schema: PG_CATALOG_SCHEMA,
871 oid: oid::TYPE_RECORD_OID,
872 details: CatalogTypeDetails {
873 typ: CatalogType::Pseudo,
874 array_id: None,
875 pg_metadata: Some(CatalogTypePgMetadata {
876 typinput_oid: 2290,
877 typreceive_oid: 2402,
878 }),
879 },
880};
881
882pub const TYPE_RECORD_ARRAY: BuiltinType<NameReference> = BuiltinType {
883 name: "_record",
884 schema: PG_CATALOG_SCHEMA,
885 oid: oid::TYPE_RECORD_ARRAY_OID,
886 details: CatalogTypeDetails {
887 typ: CatalogType::Array {
888 element_reference: TYPE_RECORD.name,
889 },
890 array_id: None,
891 pg_metadata: Some(CatalogTypePgMetadata {
892 typinput_oid: 750,
893 typreceive_oid: 2400,
894 }),
895 },
896};
897
898pub const TYPE_UUID: BuiltinType<NameReference> = BuiltinType {
899 name: "uuid",
900 schema: PG_CATALOG_SCHEMA,
901 oid: oid::TYPE_UUID_OID,
902 details: CatalogTypeDetails {
903 typ: CatalogType::Uuid,
904 array_id: None,
905 pg_metadata: Some(CatalogTypePgMetadata {
906 typinput_oid: 2952,
907 typreceive_oid: 2961,
908 }),
909 },
910};
911
912pub const TYPE_UUID_ARRAY: BuiltinType<NameReference> = BuiltinType {
913 name: "_uuid",
914 schema: PG_CATALOG_SCHEMA,
915 oid: oid::TYPE_UUID_ARRAY_OID,
916 details: CatalogTypeDetails {
917 typ: CatalogType::Array {
918 element_reference: TYPE_UUID.name,
919 },
920 array_id: None,
921 pg_metadata: Some(CatalogTypePgMetadata {
922 typinput_oid: 750,
923 typreceive_oid: 2400,
924 }),
925 },
926};
927
928pub const TYPE_JSONB: BuiltinType<NameReference> = BuiltinType {
929 name: "jsonb",
930 schema: PG_CATALOG_SCHEMA,
931 oid: oid::TYPE_JSONB_OID,
932 details: CatalogTypeDetails {
933 typ: CatalogType::Jsonb,
934 array_id: None,
935 pg_metadata: Some(CatalogTypePgMetadata {
936 typinput_oid: 3806,
937 typreceive_oid: 3805,
938 }),
939 },
940};
941
942pub const TYPE_JSONB_ARRAY: BuiltinType<NameReference> = BuiltinType {
943 name: "_jsonb",
944 schema: PG_CATALOG_SCHEMA,
945 oid: oid::TYPE_JSONB_ARRAY_OID,
946 details: CatalogTypeDetails {
947 typ: CatalogType::Array {
948 element_reference: TYPE_JSONB.name,
949 },
950 array_id: None,
951 pg_metadata: Some(CatalogTypePgMetadata {
952 typinput_oid: 750,
953 typreceive_oid: 2400,
954 }),
955 },
956};
957
958pub const TYPE_ANY: BuiltinType<NameReference> = BuiltinType {
959 name: "any",
960 schema: PG_CATALOG_SCHEMA,
961 oid: oid::TYPE_ANY_OID,
962 details: CatalogTypeDetails {
963 typ: CatalogType::Pseudo,
964 array_id: None,
965 pg_metadata: Some(CatalogTypePgMetadata {
966 typinput_oid: 2294,
967 typreceive_oid: 0,
968 }),
969 },
970};
971
972pub const TYPE_ANYARRAY: BuiltinType<NameReference> = BuiltinType {
973 name: "anyarray",
974 schema: PG_CATALOG_SCHEMA,
975 oid: oid::TYPE_ANYARRAY_OID,
976 details: CatalogTypeDetails {
977 typ: CatalogType::Pseudo,
978 array_id: None,
979 pg_metadata: Some(CatalogTypePgMetadata {
980 typinput_oid: 2296,
981 typreceive_oid: 2502,
982 }),
983 },
984};
985
986pub const TYPE_ANYELEMENT: BuiltinType<NameReference> = BuiltinType {
987 name: "anyelement",
988 schema: PG_CATALOG_SCHEMA,
989 oid: oid::TYPE_ANYELEMENT_OID,
990 details: CatalogTypeDetails {
991 typ: CatalogType::Pseudo,
992 array_id: None,
993 pg_metadata: Some(CatalogTypePgMetadata {
994 typinput_oid: 2312,
995 typreceive_oid: 0,
996 }),
997 },
998};
999
1000pub const TYPE_ANYNONARRAY: BuiltinType<NameReference> = BuiltinType {
1001 name: "anynonarray",
1002 schema: PG_CATALOG_SCHEMA,
1003 oid: oid::TYPE_ANYNONARRAY_OID,
1004 details: CatalogTypeDetails {
1005 typ: CatalogType::Pseudo,
1006 array_id: None,
1007 pg_metadata: Some(CatalogTypePgMetadata {
1008 typinput_oid: 2777,
1009 typreceive_oid: 0,
1010 }),
1011 },
1012};
1013
1014pub const TYPE_ANYRANGE: BuiltinType<NameReference> = BuiltinType {
1015 name: "anyrange",
1016 schema: PG_CATALOG_SCHEMA,
1017 oid: oid::TYPE_ANYRANGE_OID,
1018 details: CatalogTypeDetails {
1019 typ: CatalogType::Pseudo,
1020 array_id: None,
1021 pg_metadata: Some(CatalogTypePgMetadata {
1022 typinput_oid: 3832,
1023 typreceive_oid: 0,
1024 }),
1025 },
1026};
1027
1028pub const TYPE_CHAR: BuiltinType<NameReference> = BuiltinType {
1029 name: "char",
1030 schema: PG_CATALOG_SCHEMA,
1031 oid: oid::TYPE_CHAR_OID,
1032 details: CatalogTypeDetails {
1033 typ: CatalogType::PgLegacyChar,
1034 array_id: None,
1035 pg_metadata: Some(CatalogTypePgMetadata {
1036 typinput_oid: 1245,
1037 typreceive_oid: 2434,
1038 }),
1039 },
1040};
1041
1042pub const TYPE_VARCHAR: BuiltinType<NameReference> = BuiltinType {
1043 name: "varchar",
1044 schema: PG_CATALOG_SCHEMA,
1045 oid: oid::TYPE_VARCHAR_OID,
1046 details: CatalogTypeDetails {
1047 typ: CatalogType::VarChar,
1048 array_id: None,
1049 pg_metadata: Some(CatalogTypePgMetadata {
1050 typinput_oid: 1046,
1051 typreceive_oid: 2432,
1052 }),
1053 },
1054};
1055
1056pub const TYPE_INT2: BuiltinType<NameReference> = BuiltinType {
1057 name: "int2",
1058 schema: PG_CATALOG_SCHEMA,
1059 oid: oid::TYPE_INT2_OID,
1060 details: CatalogTypeDetails {
1061 typ: CatalogType::Int16,
1062 array_id: None,
1063 pg_metadata: Some(CatalogTypePgMetadata {
1064 typinput_oid: 38,
1065 typreceive_oid: 2404,
1066 }),
1067 },
1068};
1069
1070pub const TYPE_INT2_ARRAY: BuiltinType<NameReference> = BuiltinType {
1071 name: "_int2",
1072 schema: PG_CATALOG_SCHEMA,
1073 oid: oid::TYPE_INT2_ARRAY_OID,
1074 details: CatalogTypeDetails {
1075 typ: CatalogType::Array {
1076 element_reference: TYPE_INT2.name,
1077 },
1078 array_id: None,
1079 pg_metadata: Some(CatalogTypePgMetadata {
1080 typinput_oid: 750,
1081 typreceive_oid: 2400,
1082 }),
1083 },
1084};
1085
1086pub const TYPE_BPCHAR: BuiltinType<NameReference> = BuiltinType {
1087 name: "bpchar",
1088 schema: PG_CATALOG_SCHEMA,
1089 oid: oid::TYPE_BPCHAR_OID,
1090 details: CatalogTypeDetails {
1091 typ: CatalogType::Char,
1092 array_id: None,
1093 pg_metadata: Some(CatalogTypePgMetadata {
1094 typinput_oid: 1044,
1095 typreceive_oid: 2430,
1096 }),
1097 },
1098};
1099
1100pub const TYPE_CHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
1101 name: "_char",
1102 schema: PG_CATALOG_SCHEMA,
1103 oid: oid::TYPE_CHAR_ARRAY_OID,
1104 details: CatalogTypeDetails {
1105 typ: CatalogType::Array {
1106 element_reference: TYPE_CHAR.name,
1107 },
1108 array_id: None,
1109 pg_metadata: Some(CatalogTypePgMetadata {
1110 typinput_oid: 750,
1111 typreceive_oid: 2400,
1112 }),
1113 },
1114};
1115
1116pub const TYPE_VARCHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
1117 name: "_varchar",
1118 schema: PG_CATALOG_SCHEMA,
1119 oid: oid::TYPE_VARCHAR_ARRAY_OID,
1120 details: CatalogTypeDetails {
1121 typ: CatalogType::Array {
1122 element_reference: TYPE_VARCHAR.name,
1123 },
1124 array_id: None,
1125 pg_metadata: Some(CatalogTypePgMetadata {
1126 typinput_oid: 750,
1127 typreceive_oid: 2400,
1128 }),
1129 },
1130};
1131
1132pub const TYPE_BPCHAR_ARRAY: BuiltinType<NameReference> = BuiltinType {
1133 name: "_bpchar",
1134 schema: PG_CATALOG_SCHEMA,
1135 oid: oid::TYPE_BPCHAR_ARRAY_OID,
1136 details: CatalogTypeDetails {
1137 typ: CatalogType::Array {
1138 element_reference: TYPE_BPCHAR.name,
1139 },
1140 array_id: None,
1141 pg_metadata: Some(CatalogTypePgMetadata {
1142 typinput_oid: 750,
1143 typreceive_oid: 2400,
1144 }),
1145 },
1146};
1147
1148pub const TYPE_REGPROC: BuiltinType<NameReference> = BuiltinType {
1149 name: "regproc",
1150 schema: PG_CATALOG_SCHEMA,
1151 oid: oid::TYPE_REGPROC_OID,
1152 details: CatalogTypeDetails {
1153 typ: CatalogType::RegProc,
1154 array_id: None,
1155 pg_metadata: Some(CatalogTypePgMetadata {
1156 typinput_oid: 44,
1157 typreceive_oid: 2444,
1158 }),
1159 },
1160};
1161
1162pub const TYPE_REGPROC_ARRAY: BuiltinType<NameReference> = BuiltinType {
1163 name: "_regproc",
1164 schema: PG_CATALOG_SCHEMA,
1165 oid: oid::TYPE_REGPROC_ARRAY_OID,
1166 details: CatalogTypeDetails {
1167 typ: CatalogType::Array {
1168 element_reference: TYPE_REGPROC.name,
1169 },
1170 array_id: None,
1171 pg_metadata: Some(CatalogTypePgMetadata {
1172 typinput_oid: 750,
1173 typreceive_oid: 2400,
1174 }),
1175 },
1176};
1177
1178pub const TYPE_REGTYPE: BuiltinType<NameReference> = BuiltinType {
1179 name: "regtype",
1180 schema: PG_CATALOG_SCHEMA,
1181 oid: oid::TYPE_REGTYPE_OID,
1182 details: CatalogTypeDetails {
1183 typ: CatalogType::RegType,
1184 array_id: None,
1185 pg_metadata: Some(CatalogTypePgMetadata {
1186 typinput_oid: 2220,
1187 typreceive_oid: 2454,
1188 }),
1189 },
1190};
1191
1192pub const TYPE_REGTYPE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1193 name: "_regtype",
1194 schema: PG_CATALOG_SCHEMA,
1195 oid: oid::TYPE_REGTYPE_ARRAY_OID,
1196 details: CatalogTypeDetails {
1197 typ: CatalogType::Array {
1198 element_reference: TYPE_REGTYPE.name,
1199 },
1200 array_id: None,
1201 pg_metadata: Some(CatalogTypePgMetadata {
1202 typinput_oid: 750,
1203 typreceive_oid: 2400,
1204 }),
1205 },
1206};
1207
1208pub const TYPE_REGCLASS: BuiltinType<NameReference> = BuiltinType {
1209 name: "regclass",
1210 schema: PG_CATALOG_SCHEMA,
1211 oid: oid::TYPE_REGCLASS_OID,
1212 details: CatalogTypeDetails {
1213 typ: CatalogType::RegClass,
1214 array_id: None,
1215 pg_metadata: Some(CatalogTypePgMetadata {
1216 typinput_oid: 2218,
1217 typreceive_oid: 2452,
1218 }),
1219 },
1220};
1221
1222pub const TYPE_REGCLASS_ARRAY: BuiltinType<NameReference> = BuiltinType {
1223 name: "_regclass",
1224 schema: PG_CATALOG_SCHEMA,
1225 oid: oid::TYPE_REGCLASS_ARRAY_OID,
1226 details: CatalogTypeDetails {
1227 typ: CatalogType::Array {
1228 element_reference: TYPE_REGCLASS.name,
1229 },
1230 array_id: None,
1231 pg_metadata: Some(CatalogTypePgMetadata {
1232 typinput_oid: 750,
1233 typreceive_oid: 2400,
1234 }),
1235 },
1236};
1237
1238pub const TYPE_INT2_VECTOR: BuiltinType<NameReference> = BuiltinType {
1239 name: "int2vector",
1240 schema: PG_CATALOG_SCHEMA,
1241 oid: oid::TYPE_INT2_VECTOR_OID,
1242 details: CatalogTypeDetails {
1243 typ: CatalogType::Int2Vector,
1244 array_id: None,
1245 pg_metadata: Some(CatalogTypePgMetadata {
1246 typinput_oid: 40,
1247 typreceive_oid: 2410,
1248 }),
1249 },
1250};
1251
1252pub const TYPE_INT2_VECTOR_ARRAY: BuiltinType<NameReference> = BuiltinType {
1253 name: "_int2vector",
1254 schema: PG_CATALOG_SCHEMA,
1255 oid: oid::TYPE_INT2_VECTOR_ARRAY_OID,
1256 details: CatalogTypeDetails {
1257 typ: CatalogType::Array {
1258 element_reference: TYPE_INT2_VECTOR.name,
1259 },
1260 array_id: None,
1261 pg_metadata: Some(CatalogTypePgMetadata {
1262 typinput_oid: 750,
1263 typreceive_oid: 2400,
1264 }),
1265 },
1266};
1267
1268pub const TYPE_ANYCOMPATIBLE: BuiltinType<NameReference> = BuiltinType {
1269 name: "anycompatible",
1270 schema: PG_CATALOG_SCHEMA,
1271 oid: oid::TYPE_ANYCOMPATIBLE_OID,
1272 details: CatalogTypeDetails {
1273 typ: CatalogType::Pseudo,
1274 array_id: None,
1275 pg_metadata: Some(CatalogTypePgMetadata {
1276 typinput_oid: 5086,
1277 typreceive_oid: 0,
1278 }),
1279 },
1280};
1281
1282pub const TYPE_ANYCOMPATIBLEARRAY: BuiltinType<NameReference> = BuiltinType {
1283 name: "anycompatiblearray",
1284 schema: PG_CATALOG_SCHEMA,
1285 oid: oid::TYPE_ANYCOMPATIBLEARRAY_OID,
1286 details: CatalogTypeDetails {
1287 typ: CatalogType::Pseudo,
1288 array_id: None,
1289 pg_metadata: Some(CatalogTypePgMetadata {
1290 typinput_oid: 5088,
1291 typreceive_oid: 5090,
1292 }),
1293 },
1294};
1295
1296pub const TYPE_ANYCOMPATIBLENONARRAY: BuiltinType<NameReference> = BuiltinType {
1297 name: "anycompatiblenonarray",
1298 schema: PG_CATALOG_SCHEMA,
1299 oid: oid::TYPE_ANYCOMPATIBLENONARRAY_OID,
1300 details: CatalogTypeDetails {
1301 typ: CatalogType::Pseudo,
1302 array_id: None,
1303 pg_metadata: Some(CatalogTypePgMetadata {
1304 typinput_oid: 5092,
1305 typreceive_oid: 0,
1306 }),
1307 },
1308};
1309
1310pub const TYPE_ANYCOMPATIBLERANGE: BuiltinType<NameReference> = BuiltinType {
1311 name: "anycompatiblerange",
1312 schema: PG_CATALOG_SCHEMA,
1313 oid: oid::TYPE_ANYCOMPATIBLERANGE_OID,
1314 details: CatalogTypeDetails {
1315 typ: CatalogType::Pseudo,
1316 array_id: None,
1317 pg_metadata: Some(CatalogTypePgMetadata {
1318 typinput_oid: 5094,
1319 typreceive_oid: 0,
1320 }),
1321 },
1322};
1323
1324pub const TYPE_LIST: BuiltinType<NameReference> = BuiltinType {
1325 name: "list",
1326 schema: MZ_CATALOG_SCHEMA,
1327 oid: mz_pgrepr::oid::TYPE_LIST_OID,
1328 details: CatalogTypeDetails {
1329 typ: CatalogType::Pseudo,
1330 array_id: None,
1331 pg_metadata: None,
1332 },
1333};
1334
1335pub const TYPE_MAP: BuiltinType<NameReference> = BuiltinType {
1336 name: "map",
1337 schema: MZ_CATALOG_SCHEMA,
1338 oid: mz_pgrepr::oid::TYPE_MAP_OID,
1339 details: CatalogTypeDetails {
1340 typ: CatalogType::Pseudo,
1341 array_id: None,
1342 pg_metadata: None,
1343 },
1344};
1345
1346pub const TYPE_ANYCOMPATIBLELIST: BuiltinType<NameReference> = BuiltinType {
1347 name: "anycompatiblelist",
1348 schema: MZ_CATALOG_SCHEMA,
1349 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLELIST_OID,
1350 details: CatalogTypeDetails {
1351 typ: CatalogType::Pseudo,
1352 array_id: None,
1353 pg_metadata: None,
1354 },
1355};
1356
1357pub const TYPE_ANYCOMPATIBLEMAP: BuiltinType<NameReference> = BuiltinType {
1358 name: "anycompatiblemap",
1359 schema: MZ_CATALOG_SCHEMA,
1360 oid: mz_pgrepr::oid::TYPE_ANYCOMPATIBLEMAP_OID,
1361 details: CatalogTypeDetails {
1362 typ: CatalogType::Pseudo,
1363 array_id: None,
1364 pg_metadata: None,
1365 },
1366};
1367
1368pub const TYPE_UINT2: BuiltinType<NameReference> = BuiltinType {
1369 name: "uint2",
1370 schema: MZ_CATALOG_SCHEMA,
1371 oid: mz_pgrepr::oid::TYPE_UINT2_OID,
1372 details: CatalogTypeDetails {
1373 typ: CatalogType::UInt16,
1374 array_id: None,
1375 pg_metadata: None,
1376 },
1377};
1378
1379pub const TYPE_UINT2_ARRAY: BuiltinType<NameReference> = BuiltinType {
1380 name: "_uint2",
1381 schema: MZ_CATALOG_SCHEMA,
1382 oid: mz_pgrepr::oid::TYPE_UINT2_ARRAY_OID,
1383 details: CatalogTypeDetails {
1384 typ: CatalogType::Array {
1385 element_reference: TYPE_UINT2.name,
1386 },
1387 array_id: None,
1388 pg_metadata: None,
1389 },
1390};
1391
1392pub const TYPE_UINT4: BuiltinType<NameReference> = BuiltinType {
1393 name: "uint4",
1394 schema: MZ_CATALOG_SCHEMA,
1395 oid: mz_pgrepr::oid::TYPE_UINT4_OID,
1396 details: CatalogTypeDetails {
1397 typ: CatalogType::UInt32,
1398 array_id: None,
1399 pg_metadata: None,
1400 },
1401};
1402
1403pub const TYPE_UINT4_ARRAY: BuiltinType<NameReference> = BuiltinType {
1404 name: "_uint4",
1405 schema: MZ_CATALOG_SCHEMA,
1406 oid: mz_pgrepr::oid::TYPE_UINT4_ARRAY_OID,
1407 details: CatalogTypeDetails {
1408 typ: CatalogType::Array {
1409 element_reference: TYPE_UINT4.name,
1410 },
1411 array_id: None,
1412 pg_metadata: None,
1413 },
1414};
1415
1416pub const TYPE_UINT8: BuiltinType<NameReference> = BuiltinType {
1417 name: "uint8",
1418 schema: MZ_CATALOG_SCHEMA,
1419 oid: mz_pgrepr::oid::TYPE_UINT8_OID,
1420 details: CatalogTypeDetails {
1421 typ: CatalogType::UInt64,
1422 array_id: None,
1423 pg_metadata: None,
1424 },
1425};
1426
1427pub const TYPE_UINT8_ARRAY: BuiltinType<NameReference> = BuiltinType {
1428 name: "_uint8",
1429 schema: MZ_CATALOG_SCHEMA,
1430 oid: mz_pgrepr::oid::TYPE_UINT8_ARRAY_OID,
1431 details: CatalogTypeDetails {
1432 typ: CatalogType::Array {
1433 element_reference: TYPE_UINT8.name,
1434 },
1435 array_id: None,
1436 pg_metadata: None,
1437 },
1438};
1439
1440pub const TYPE_MZ_TIMESTAMP: BuiltinType<NameReference> = BuiltinType {
1441 name: "mz_timestamp",
1442 schema: MZ_CATALOG_SCHEMA,
1443 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_OID,
1444 details: CatalogTypeDetails {
1445 typ: CatalogType::MzTimestamp,
1446 array_id: None,
1447 pg_metadata: None,
1448 },
1449};
1450
1451pub const TYPE_MZ_TIMESTAMP_ARRAY: BuiltinType<NameReference> = BuiltinType {
1452 name: "_mz_timestamp",
1453 schema: MZ_CATALOG_SCHEMA,
1454 oid: mz_pgrepr::oid::TYPE_MZ_TIMESTAMP_ARRAY_OID,
1455 details: CatalogTypeDetails {
1456 typ: CatalogType::Array {
1457 element_reference: TYPE_MZ_TIMESTAMP.name,
1458 },
1459 array_id: None,
1460 pg_metadata: None,
1461 },
1462};
1463
1464pub const TYPE_INT4_RANGE: BuiltinType<NameReference> = BuiltinType {
1465 name: "int4range",
1466 schema: PG_CATALOG_SCHEMA,
1467 oid: mz_pgrepr::oid::TYPE_INT4RANGE_OID,
1468 details: CatalogTypeDetails {
1469 typ: CatalogType::Range {
1470 element_reference: TYPE_INT4.name,
1471 },
1472 array_id: None,
1473 pg_metadata: Some(CatalogTypePgMetadata {
1474 typinput_oid: 3834,
1475 typreceive_oid: 3836,
1476 }),
1477 },
1478};
1479
1480pub const TYPE_INT4_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1481 name: "_int4range",
1482 schema: PG_CATALOG_SCHEMA,
1483 oid: mz_pgrepr::oid::TYPE_INT4RANGE_ARRAY_OID,
1484 details: CatalogTypeDetails {
1485 typ: CatalogType::Array {
1486 element_reference: TYPE_INT4_RANGE.name,
1487 },
1488 array_id: None,
1489 pg_metadata: Some(CatalogTypePgMetadata {
1490 typinput_oid: 750,
1491 typreceive_oid: 2400,
1492 }),
1493 },
1494};
1495
1496pub const TYPE_INT8_RANGE: BuiltinType<NameReference> = BuiltinType {
1497 name: "int8range",
1498 schema: PG_CATALOG_SCHEMA,
1499 oid: mz_pgrepr::oid::TYPE_INT8RANGE_OID,
1500 details: CatalogTypeDetails {
1501 typ: CatalogType::Range {
1502 element_reference: TYPE_INT8.name,
1503 },
1504 array_id: None,
1505 pg_metadata: Some(CatalogTypePgMetadata {
1506 typinput_oid: 3834,
1507 typreceive_oid: 3836,
1508 }),
1509 },
1510};
1511
1512pub const TYPE_INT8_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1513 name: "_int8range",
1514 schema: PG_CATALOG_SCHEMA,
1515 oid: mz_pgrepr::oid::TYPE_INT8RANGE_ARRAY_OID,
1516 details: CatalogTypeDetails {
1517 typ: CatalogType::Array {
1518 element_reference: TYPE_INT8_RANGE.name,
1519 },
1520 array_id: None,
1521 pg_metadata: Some(CatalogTypePgMetadata {
1522 typinput_oid: 750,
1523 typreceive_oid: 2400,
1524 }),
1525 },
1526};
1527
1528pub const TYPE_DATE_RANGE: BuiltinType<NameReference> = BuiltinType {
1529 name: "daterange",
1530 schema: PG_CATALOG_SCHEMA,
1531 oid: mz_pgrepr::oid::TYPE_DATERANGE_OID,
1532 details: CatalogTypeDetails {
1533 typ: CatalogType::Range {
1534 element_reference: TYPE_DATE.name,
1535 },
1536 array_id: None,
1537 pg_metadata: Some(CatalogTypePgMetadata {
1538 typinput_oid: 3834,
1539 typreceive_oid: 3836,
1540 }),
1541 },
1542};
1543
1544pub const TYPE_DATE_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1545 name: "_daterange",
1546 schema: PG_CATALOG_SCHEMA,
1547 oid: mz_pgrepr::oid::TYPE_DATERANGE_ARRAY_OID,
1548 details: CatalogTypeDetails {
1549 typ: CatalogType::Array {
1550 element_reference: TYPE_DATE_RANGE.name,
1551 },
1552 array_id: None,
1553 pg_metadata: Some(CatalogTypePgMetadata {
1554 typinput_oid: 750,
1555 typreceive_oid: 2400,
1556 }),
1557 },
1558};
1559
1560pub const TYPE_NUM_RANGE: BuiltinType<NameReference> = BuiltinType {
1561 name: "numrange",
1562 schema: PG_CATALOG_SCHEMA,
1563 oid: mz_pgrepr::oid::TYPE_NUMRANGE_OID,
1564 details: CatalogTypeDetails {
1565 typ: CatalogType::Range {
1566 element_reference: TYPE_NUMERIC.name,
1567 },
1568 array_id: None,
1569 pg_metadata: Some(CatalogTypePgMetadata {
1570 typinput_oid: 3834,
1571 typreceive_oid: 3836,
1572 }),
1573 },
1574};
1575
1576pub const TYPE_NUM_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1577 name: "_numrange",
1578 schema: PG_CATALOG_SCHEMA,
1579 oid: mz_pgrepr::oid::TYPE_NUMRANGE_ARRAY_OID,
1580 details: CatalogTypeDetails {
1581 typ: CatalogType::Array {
1582 element_reference: TYPE_NUM_RANGE.name,
1583 },
1584 array_id: None,
1585 pg_metadata: Some(CatalogTypePgMetadata {
1586 typinput_oid: 750,
1587 typreceive_oid: 2400,
1588 }),
1589 },
1590};
1591
1592pub const TYPE_TS_RANGE: BuiltinType<NameReference> = BuiltinType {
1593 name: "tsrange",
1594 schema: PG_CATALOG_SCHEMA,
1595 oid: mz_pgrepr::oid::TYPE_TSRANGE_OID,
1596 details: CatalogTypeDetails {
1597 typ: CatalogType::Range {
1598 element_reference: TYPE_TIMESTAMP.name,
1599 },
1600 array_id: None,
1601 pg_metadata: Some(CatalogTypePgMetadata {
1602 typinput_oid: 3834,
1603 typreceive_oid: 3836,
1604 }),
1605 },
1606};
1607
1608pub const TYPE_TS_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1609 name: "_tsrange",
1610 schema: PG_CATALOG_SCHEMA,
1611 oid: mz_pgrepr::oid::TYPE_TSRANGE_ARRAY_OID,
1612 details: CatalogTypeDetails {
1613 typ: CatalogType::Array {
1614 element_reference: TYPE_TS_RANGE.name,
1615 },
1616 array_id: None,
1617 pg_metadata: Some(CatalogTypePgMetadata {
1618 typinput_oid: 750,
1619 typreceive_oid: 2400,
1620 }),
1621 },
1622};
1623
1624pub const TYPE_TSTZ_RANGE: BuiltinType<NameReference> = BuiltinType {
1625 name: "tstzrange",
1626 schema: PG_CATALOG_SCHEMA,
1627 oid: mz_pgrepr::oid::TYPE_TSTZRANGE_OID,
1628 details: CatalogTypeDetails {
1629 typ: CatalogType::Range {
1630 element_reference: TYPE_TIMESTAMPTZ.name,
1631 },
1632 array_id: None,
1633 pg_metadata: Some(CatalogTypePgMetadata {
1634 typinput_oid: 3834,
1635 typreceive_oid: 3836,
1636 }),
1637 },
1638};
1639
1640pub const TYPE_TSTZ_RANGE_ARRAY: BuiltinType<NameReference> = BuiltinType {
1641 name: "_tstzrange",
1642 schema: PG_CATALOG_SCHEMA,
1643 oid: mz_pgrepr::oid::TYPE_TSTZRANGE_ARRAY_OID,
1644 details: CatalogTypeDetails {
1645 typ: CatalogType::Array {
1646 element_reference: TYPE_TSTZ_RANGE.name,
1647 },
1648 array_id: None,
1649 pg_metadata: Some(CatalogTypePgMetadata {
1650 typinput_oid: 750,
1651 typreceive_oid: 2400,
1652 }),
1653 },
1654};
1655
1656pub const TYPE_MZ_ACL_ITEM: BuiltinType<NameReference> = BuiltinType {
1657 name: "mz_aclitem",
1658 schema: MZ_CATALOG_SCHEMA,
1659 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_OID,
1660 details: CatalogTypeDetails {
1661 typ: CatalogType::MzAclItem,
1662 array_id: None,
1663 pg_metadata: None,
1664 },
1665};
1666
1667pub const TYPE_MZ_ACL_ITEM_ARRAY: BuiltinType<NameReference> = BuiltinType {
1668 name: "_mz_aclitem",
1669 schema: MZ_CATALOG_SCHEMA,
1670 oid: mz_pgrepr::oid::TYPE_MZ_ACL_ITEM_ARRAY_OID,
1671 details: CatalogTypeDetails {
1672 typ: CatalogType::Array {
1673 element_reference: TYPE_MZ_ACL_ITEM.name,
1674 },
1675 array_id: None,
1676 pg_metadata: Some(CatalogTypePgMetadata {
1677 typinput_oid: 750,
1678 typreceive_oid: 2400,
1679 }),
1680 },
1681};
1682
1683pub const TYPE_ACL_ITEM: BuiltinType<NameReference> = BuiltinType {
1684 name: "aclitem",
1685 schema: PG_CATALOG_SCHEMA,
1686 oid: 1033,
1687 details: CatalogTypeDetails {
1688 typ: CatalogType::AclItem,
1689 array_id: None,
1690 pg_metadata: Some(CatalogTypePgMetadata {
1691 typinput_oid: 1031,
1692 typreceive_oid: 0,
1693 }),
1694 },
1695};
1696
1697pub const TYPE_ACL_ITEM_ARRAY: BuiltinType<NameReference> = BuiltinType {
1698 name: "_aclitem",
1699 schema: PG_CATALOG_SCHEMA,
1700 oid: 1034,
1701 details: CatalogTypeDetails {
1702 typ: CatalogType::Array {
1703 element_reference: TYPE_ACL_ITEM.name,
1704 },
1705 array_id: None,
1706 pg_metadata: Some(CatalogTypePgMetadata {
1707 typinput_oid: 750,
1708 typreceive_oid: 2400,
1709 }),
1710 },
1711};
1712
1713pub const TYPE_INTERNAL: BuiltinType<NameReference> = BuiltinType {
1714 name: "internal",
1715 schema: PG_CATALOG_SCHEMA,
1716 oid: 2281,
1717 details: CatalogTypeDetails {
1718 typ: CatalogType::Pseudo,
1719 array_id: None,
1720 pg_metadata: Some(CatalogTypePgMetadata {
1721 typinput_oid: 2304,
1722 typreceive_oid: 0,
1723 }),
1724 },
1725};
1726
1727const PUBLIC_SELECT: MzAclItem = MzAclItem {
1728 grantee: RoleId::Public,
1729 grantor: MZ_SYSTEM_ROLE_ID,
1730 acl_mode: AclMode::SELECT,
1731};
1732
1733const SUPPORT_SELECT: MzAclItem = MzAclItem {
1734 grantee: MZ_SUPPORT_ROLE_ID,
1735 grantor: MZ_SYSTEM_ROLE_ID,
1736 acl_mode: AclMode::SELECT,
1737};
1738
1739const ANALYTICS_SELECT: MzAclItem = MzAclItem {
1740 grantee: MZ_ANALYTICS_ROLE_ID,
1741 grantor: MZ_SYSTEM_ROLE_ID,
1742 acl_mode: AclMode::SELECT,
1743};
1744
1745const MONITOR_SELECT: MzAclItem = MzAclItem {
1746 grantee: MZ_MONITOR_ROLE_ID,
1747 grantor: MZ_SYSTEM_ROLE_ID,
1748 acl_mode: AclMode::SELECT,
1749};
1750
1751const MONITOR_REDACTED_SELECT: MzAclItem = MzAclItem {
1752 grantee: MZ_MONITOR_REDACTED_ROLE_ID,
1753 grantor: MZ_SYSTEM_ROLE_ID,
1754 acl_mode: AclMode::SELECT,
1755};
1756
1757pub static MZ_CATALOG_RAW: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
1758 name: "mz_catalog_raw",
1759 schema: MZ_INTERNAL_SCHEMA,
1760 oid: oid::SOURCE_MZ_CATALOG_RAW_OID,
1761 data_source: DataSourceDesc::Catalog,
1762 desc: crate::durable::persist_desc(),
1763 column_comments: BTreeMap::new(),
1764 is_retained_metrics_object: false,
1765 access: vec![],
1767});
1768
1769pub static MZ_CATALOG_RAW_DESCRIPTION: LazyLock<SystemObjectDescription> =
1770 LazyLock::new(|| SystemObjectDescription {
1771 schema_name: MZ_CATALOG_RAW.schema.to_string(),
1772 object_type: CatalogItemType::Source,
1773 object_name: MZ_CATALOG_RAW.name.to_string(),
1774 });
1775
1776pub static MZ_DATAFLOW_OPERATORS_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1777 name: "mz_dataflow_operators_per_worker",
1778 schema: MZ_INTROSPECTION_SCHEMA,
1779 oid: oid::LOG_MZ_DATAFLOW_OPERATORS_PER_WORKER_OID,
1780 variant: LogVariant::Timely(TimelyLog::Operates),
1781 access: vec![PUBLIC_SELECT],
1782});
1783
1784pub static MZ_DATAFLOW_ADDRESSES_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1785 name: "mz_dataflow_addresses_per_worker",
1786 schema: MZ_INTROSPECTION_SCHEMA,
1787 oid: oid::LOG_MZ_DATAFLOW_ADDRESSES_PER_WORKER_OID,
1788 variant: LogVariant::Timely(TimelyLog::Addresses),
1789 access: vec![PUBLIC_SELECT],
1790});
1791
1792pub static MZ_DATAFLOW_CHANNELS_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1793 name: "mz_dataflow_channels_per_worker",
1794 schema: MZ_INTROSPECTION_SCHEMA,
1795 oid: oid::LOG_MZ_DATAFLOW_CHANNELS_PER_WORKER_OID,
1796 variant: LogVariant::Timely(TimelyLog::Channels),
1797 access: vec![PUBLIC_SELECT],
1798});
1799
1800pub static MZ_SCHEDULING_ELAPSED_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1801 name: "mz_scheduling_elapsed_raw",
1802 schema: MZ_INTROSPECTION_SCHEMA,
1803 oid: oid::LOG_MZ_SCHEDULING_ELAPSED_RAW_OID,
1804 variant: LogVariant::Timely(TimelyLog::Elapsed),
1805 access: vec![PUBLIC_SELECT],
1806});
1807
1808pub static MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_RAW: LazyLock<BuiltinLog> =
1809 LazyLock::new(|| BuiltinLog {
1810 name: "mz_compute_operator_durations_histogram_raw",
1811 schema: MZ_INTROSPECTION_SCHEMA,
1812 oid: oid::LOG_MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_RAW_OID,
1813 variant: LogVariant::Timely(TimelyLog::Histogram),
1814 access: vec![PUBLIC_SELECT],
1815 });
1816
1817pub static MZ_SCHEDULING_PARKS_HISTOGRAM_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1818 name: "mz_scheduling_parks_histogram_raw",
1819 schema: MZ_INTROSPECTION_SCHEMA,
1820 oid: oid::LOG_MZ_SCHEDULING_PARKS_HISTOGRAM_RAW_OID,
1821 variant: LogVariant::Timely(TimelyLog::Parks),
1822 access: vec![PUBLIC_SELECT],
1823});
1824
1825pub static MZ_ARRANGEMENT_RECORDS_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1826 name: "mz_arrangement_records_raw",
1827 schema: MZ_INTROSPECTION_SCHEMA,
1828 oid: oid::LOG_MZ_ARRANGEMENT_RECORDS_RAW_OID,
1829 variant: LogVariant::Differential(DifferentialLog::ArrangementRecords),
1830 access: vec![PUBLIC_SELECT],
1831});
1832
1833pub static MZ_ARRANGEMENT_BATCHES_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1834 name: "mz_arrangement_batches_raw",
1835 schema: MZ_INTROSPECTION_SCHEMA,
1836 oid: oid::LOG_MZ_ARRANGEMENT_BATCHES_RAW_OID,
1837 variant: LogVariant::Differential(DifferentialLog::ArrangementBatches),
1838 access: vec![PUBLIC_SELECT],
1839});
1840
1841pub static MZ_ARRANGEMENT_SHARING_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1842 name: "mz_arrangement_sharing_raw",
1843 schema: MZ_INTROSPECTION_SCHEMA,
1844 oid: oid::LOG_MZ_ARRANGEMENT_SHARING_RAW_OID,
1845 variant: LogVariant::Differential(DifferentialLog::Sharing),
1846 access: vec![PUBLIC_SELECT],
1847});
1848
1849pub static MZ_ARRANGEMENT_BATCHER_RECORDS_RAW: LazyLock<BuiltinLog> =
1850 LazyLock::new(|| BuiltinLog {
1851 name: "mz_arrangement_batcher_records_raw",
1852 schema: MZ_INTROSPECTION_SCHEMA,
1853 oid: oid::LOG_MZ_ARRANGEMENT_BATCHER_RECORDS_RAW_OID,
1854 variant: LogVariant::Differential(DifferentialLog::BatcherRecords),
1855 access: vec![PUBLIC_SELECT],
1856 });
1857
1858pub static MZ_ARRANGEMENT_BATCHER_SIZE_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1859 name: "mz_arrangement_batcher_size_raw",
1860 schema: MZ_INTROSPECTION_SCHEMA,
1861 oid: oid::LOG_MZ_ARRANGEMENT_BATCHER_SIZE_RAW_OID,
1862 variant: LogVariant::Differential(DifferentialLog::BatcherSize),
1863 access: vec![PUBLIC_SELECT],
1864});
1865
1866pub static MZ_ARRANGEMENT_BATCHER_CAPACITY_RAW: LazyLock<BuiltinLog> =
1867 LazyLock::new(|| BuiltinLog {
1868 name: "mz_arrangement_batcher_capacity_raw",
1869 schema: MZ_INTROSPECTION_SCHEMA,
1870 oid: oid::LOG_MZ_ARRANGEMENT_BATCHER_CAPACITY_RAW_OID,
1871 variant: LogVariant::Differential(DifferentialLog::BatcherCapacity),
1872 access: vec![PUBLIC_SELECT],
1873 });
1874
1875pub static MZ_ARRANGEMENT_BATCHER_ALLOCATIONS_RAW: LazyLock<BuiltinLog> =
1876 LazyLock::new(|| BuiltinLog {
1877 name: "mz_arrangement_batcher_allocations_raw",
1878 schema: MZ_INTROSPECTION_SCHEMA,
1879 oid: oid::LOG_MZ_ARRANGEMENT_BATCHER_ALLOCATIONS_RAW_OID,
1880 variant: LogVariant::Differential(DifferentialLog::BatcherAllocations),
1881 access: vec![PUBLIC_SELECT],
1882 });
1883
1884pub static MZ_COMPUTE_EXPORTS_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1885 name: "mz_compute_exports_per_worker",
1886 schema: MZ_INTROSPECTION_SCHEMA,
1887 oid: oid::LOG_MZ_COMPUTE_EXPORTS_PER_WORKER_OID,
1888 variant: LogVariant::Compute(ComputeLog::DataflowCurrent),
1889 access: vec![PUBLIC_SELECT],
1890});
1891
1892pub static MZ_COMPUTE_DATAFLOW_GLOBAL_IDS_PER_WORKER: LazyLock<BuiltinLog> =
1893 LazyLock::new(|| BuiltinLog {
1894 name: "mz_compute_dataflow_global_ids_per_worker",
1895 schema: MZ_INTROSPECTION_SCHEMA,
1896 oid: oid::LOG_MZ_COMPUTE_DATAFLOW_GLOBAL_IDS_PER_WORKER_OID,
1897 variant: LogVariant::Compute(ComputeLog::DataflowGlobal),
1898 access: vec![PUBLIC_SELECT],
1899 });
1900
1901pub static MZ_COMPUTE_FRONTIERS_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1902 name: "mz_compute_frontiers_per_worker",
1903 schema: MZ_INTROSPECTION_SCHEMA,
1904 oid: oid::LOG_MZ_COMPUTE_FRONTIERS_PER_WORKER_OID,
1905 variant: LogVariant::Compute(ComputeLog::FrontierCurrent),
1906 access: vec![PUBLIC_SELECT],
1907});
1908
1909pub static MZ_COMPUTE_IMPORT_FRONTIERS_PER_WORKER: LazyLock<BuiltinLog> =
1910 LazyLock::new(|| BuiltinLog {
1911 name: "mz_compute_import_frontiers_per_worker",
1912 schema: MZ_INTROSPECTION_SCHEMA,
1913 oid: oid::LOG_MZ_COMPUTE_IMPORT_FRONTIERS_PER_WORKER_OID,
1914 variant: LogVariant::Compute(ComputeLog::ImportFrontierCurrent),
1915 access: vec![PUBLIC_SELECT],
1916 });
1917
1918pub static MZ_COMPUTE_ERROR_COUNTS_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1919 name: "mz_compute_error_counts_raw",
1920 schema: MZ_INTROSPECTION_SCHEMA,
1921 oid: oid::LOG_MZ_COMPUTE_ERROR_COUNTS_RAW_OID,
1922 variant: LogVariant::Compute(ComputeLog::ErrorCount),
1923 access: vec![PUBLIC_SELECT],
1924});
1925
1926pub static MZ_COMPUTE_HYDRATION_TIMES_PER_WORKER: LazyLock<BuiltinLog> =
1927 LazyLock::new(|| BuiltinLog {
1928 name: "mz_compute_hydration_times_per_worker",
1929 schema: MZ_INTROSPECTION_SCHEMA,
1930 oid: oid::LOG_MZ_COMPUTE_HYDRATION_TIMES_PER_WORKER_OID,
1931 variant: LogVariant::Compute(ComputeLog::HydrationTime),
1932 access: vec![PUBLIC_SELECT],
1933 });
1934
1935pub static MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES_PER_WORKER: LazyLock<BuiltinLog> =
1936 LazyLock::new(|| BuiltinLog {
1937 name: "mz_compute_operator_hydration_statuses_per_worker",
1938 schema: MZ_INTROSPECTION_SCHEMA,
1939 oid: oid::LOG_MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES_PER_WORKER_OID,
1940 variant: LogVariant::Compute(ComputeLog::OperatorHydrationStatus),
1941 access: vec![PUBLIC_SELECT],
1942 });
1943
1944pub static MZ_ACTIVE_PEEKS_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1945 name: "mz_active_peeks_per_worker",
1946 schema: MZ_INTROSPECTION_SCHEMA,
1947 oid: oid::LOG_MZ_ACTIVE_PEEKS_PER_WORKER_OID,
1948 variant: LogVariant::Compute(ComputeLog::PeekCurrent),
1949 access: vec![PUBLIC_SELECT],
1950});
1951
1952pub static MZ_COMPUTE_LIR_MAPPING_PER_WORKER: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1953 name: "mz_compute_lir_mapping_per_worker",
1954 schema: MZ_INTROSPECTION_SCHEMA,
1955 oid: oid::LOG_MZ_COMPUTE_LIR_MAPPING_PER_WORKER_OID,
1956 variant: LogVariant::Compute(ComputeLog::LirMapping),
1957 access: vec![PUBLIC_SELECT],
1958});
1959
1960pub static MZ_PEEK_DURATIONS_HISTOGRAM_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1961 name: "mz_peek_durations_histogram_raw",
1962 schema: MZ_INTROSPECTION_SCHEMA,
1963 oid: oid::LOG_MZ_PEEK_DURATIONS_HISTOGRAM_RAW_OID,
1964 variant: LogVariant::Compute(ComputeLog::PeekDuration),
1965 access: vec![PUBLIC_SELECT],
1966});
1967
1968pub static MZ_ARRANGEMENT_HEAP_SIZE_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1969 name: "mz_arrangement_heap_size_raw",
1970 schema: MZ_INTROSPECTION_SCHEMA,
1971 oid: oid::LOG_MZ_ARRANGEMENT_HEAP_SIZE_RAW_OID,
1972 variant: LogVariant::Compute(ComputeLog::ArrangementHeapSize),
1973 access: vec![PUBLIC_SELECT],
1974});
1975
1976pub static MZ_ARRANGEMENT_HEAP_CAPACITY_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
1977 name: "mz_arrangement_heap_capacity_raw",
1978 schema: MZ_INTROSPECTION_SCHEMA,
1979 oid: oid::LOG_MZ_ARRANGEMENT_HEAP_CAPACITY_RAW_OID,
1980 variant: LogVariant::Compute(ComputeLog::ArrangementHeapCapacity),
1981 access: vec![PUBLIC_SELECT],
1982});
1983
1984pub static MZ_ARRANGEMENT_HEAP_ALLOCATIONS_RAW: LazyLock<BuiltinLog> =
1985 LazyLock::new(|| BuiltinLog {
1986 name: "mz_arrangement_heap_allocations_raw",
1987 schema: MZ_INTROSPECTION_SCHEMA,
1988 oid: oid::LOG_MZ_ARRANGEMENT_HEAP_ALLOCATIONS_RAW_OID,
1989 variant: LogVariant::Compute(ComputeLog::ArrangementHeapAllocations),
1990 access: vec![PUBLIC_SELECT],
1991 });
1992
1993pub static MZ_MESSAGE_BATCH_COUNTS_RECEIVED_RAW: LazyLock<BuiltinLog> =
1994 LazyLock::new(|| BuiltinLog {
1995 name: "mz_message_batch_counts_received_raw",
1996 schema: MZ_INTROSPECTION_SCHEMA,
1997 oid: oid::LOG_MZ_MESSAGE_BATCH_COUNTS_RECEIVED_RAW_OID,
1998 variant: LogVariant::Timely(TimelyLog::BatchesReceived),
1999 access: vec![PUBLIC_SELECT],
2000 });
2001
2002pub static MZ_MESSAGE_BATCH_COUNTS_SENT_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
2003 name: "mz_message_batch_counts_sent_raw",
2004 schema: MZ_INTROSPECTION_SCHEMA,
2005 oid: oid::LOG_MZ_MESSAGE_BATCH_COUNTS_SENT_RAW_OID,
2006 variant: LogVariant::Timely(TimelyLog::BatchesSent),
2007 access: vec![PUBLIC_SELECT],
2008});
2009
2010pub static MZ_MESSAGE_COUNTS_RECEIVED_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
2011 name: "mz_message_counts_received_raw",
2012 schema: MZ_INTROSPECTION_SCHEMA,
2013 oid: oid::LOG_MZ_MESSAGE_COUNTS_RECEIVED_RAW_OID,
2014 variant: LogVariant::Timely(TimelyLog::MessagesReceived),
2015 access: vec![PUBLIC_SELECT],
2016});
2017
2018pub static MZ_MESSAGE_COUNTS_SENT_RAW: LazyLock<BuiltinLog> = LazyLock::new(|| BuiltinLog {
2019 name: "mz_message_counts_sent_raw",
2020 schema: MZ_INTROSPECTION_SCHEMA,
2021 oid: oid::LOG_MZ_MESSAGE_COUNTS_SENT_RAW_OID,
2022 variant: LogVariant::Timely(TimelyLog::MessagesSent),
2023 access: vec![PUBLIC_SELECT],
2024});
2025
2026pub static MZ_DATAFLOW_OPERATOR_REACHABILITY_RAW: LazyLock<BuiltinLog> =
2027 LazyLock::new(|| BuiltinLog {
2028 name: "mz_dataflow_operator_reachability_raw",
2029 schema: MZ_INTROSPECTION_SCHEMA,
2030 oid: oid::LOG_MZ_DATAFLOW_OPERATOR_REACHABILITY_RAW_OID,
2031 variant: LogVariant::Timely(TimelyLog::Reachability),
2032 access: vec![PUBLIC_SELECT],
2033 });
2034
2035pub static MZ_ICEBERG_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2036 name: "mz_iceberg_sinks",
2037 schema: MZ_CATALOG_SCHEMA,
2038 oid: oid::TABLE_MZ_ICEBERG_SINKS_OID,
2039 desc: RelationDesc::builder()
2040 .with_column("id", SqlScalarType::String.nullable(false))
2041 .with_column("namespace", SqlScalarType::String.nullable(false))
2042 .with_column("table", SqlScalarType::String.nullable(false))
2043 .finish(),
2044 column_comments: BTreeMap::from_iter([
2045 ("id", "The ID of the sink."),
2046 (
2047 "namespace",
2048 "The namespace of the Iceberg table into which the sink is writing.",
2049 ),
2050 ("table", "The Iceberg table into which the sink is writing."),
2051 ]),
2052 is_retained_metrics_object: false,
2053 access: vec![PUBLIC_SELECT],
2054});
2055
2056pub static MZ_KAFKA_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2057 name: "mz_kafka_sinks",
2058 schema: MZ_CATALOG_SCHEMA,
2059 oid: oid::TABLE_MZ_KAFKA_SINKS_OID,
2060 desc: RelationDesc::builder()
2061 .with_column("id", SqlScalarType::String.nullable(false))
2062 .with_column("topic", SqlScalarType::String.nullable(false))
2063 .with_key(vec![0])
2064 .finish(),
2065 column_comments: BTreeMap::from_iter([
2066 ("id", "The ID of the sink."),
2067 (
2068 "topic",
2069 "The name of the Kafka topic into which the sink is writing.",
2070 ),
2071 ]),
2072 is_retained_metrics_object: false,
2073 access: vec![PUBLIC_SELECT],
2074});
2075pub static MZ_KAFKA_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2076 name: "mz_kafka_connections",
2077 schema: MZ_CATALOG_SCHEMA,
2078 oid: oid::TABLE_MZ_KAFKA_CONNECTIONS_OID,
2079 desc: RelationDesc::builder()
2080 .with_column("id", SqlScalarType::String.nullable(false))
2081 .with_column(
2082 "brokers",
2083 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
2084 )
2085 .with_column("sink_progress_topic", SqlScalarType::String.nullable(false))
2086 .finish(),
2087 column_comments: BTreeMap::from_iter([
2088 ("id", "The ID of the connection."),
2089 (
2090 "brokers",
2091 "The addresses of the Kafka brokers to connect to.",
2092 ),
2093 (
2094 "sink_progress_topic",
2095 "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.",
2096 ),
2097 ]),
2098 is_retained_metrics_object: false,
2099 access: vec![PUBLIC_SELECT],
2100});
2101pub static MZ_KAFKA_SOURCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2102 name: "mz_kafka_sources",
2103 schema: MZ_CATALOG_SCHEMA,
2104 oid: oid::TABLE_MZ_KAFKA_SOURCES_OID,
2105 desc: RelationDesc::builder()
2106 .with_column("id", SqlScalarType::String.nullable(false))
2107 .with_column("group_id_prefix", SqlScalarType::String.nullable(false))
2108 .with_column("topic", SqlScalarType::String.nullable(false))
2109 .finish(),
2110 column_comments: BTreeMap::from_iter([
2111 (
2112 "id",
2113 "The ID of the Kafka source. Corresponds to `mz_catalog.mz_sources.id`.",
2114 ),
2115 (
2116 "group_id_prefix",
2117 "The value of the `GROUP ID PREFIX` connection option.",
2118 ),
2119 (
2120 "topic",
2121 "The name of the Kafka topic the source is reading from.",
2122 ),
2123 ]),
2124 is_retained_metrics_object: false,
2125 access: vec![PUBLIC_SELECT],
2126});
2127pub static MZ_POSTGRES_SOURCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2128 name: "mz_postgres_sources",
2129 schema: MZ_INTERNAL_SCHEMA,
2130 oid: oid::TABLE_MZ_POSTGRES_SOURCES_OID,
2131 desc: RelationDesc::builder()
2132 .with_column("id", SqlScalarType::String.nullable(false))
2133 .with_column("replication_slot", SqlScalarType::String.nullable(false))
2134 .with_column("timeline_id", SqlScalarType::UInt64.nullable(true))
2135 .finish(),
2136 column_comments: BTreeMap::from_iter([
2137 (
2138 "id",
2139 "The ID of the source. Corresponds to `mz_catalog.mz_sources.id`.",
2140 ),
2141 (
2142 "replication_slot",
2143 "The name of the replication slot in the PostgreSQL database that Materialize will create and stream data from.",
2144 ),
2145 (
2146 "timeline_id",
2147 "The PostgreSQL timeline ID determined on source creation.",
2148 ),
2149 ]),
2150 is_retained_metrics_object: false,
2151 access: vec![PUBLIC_SELECT],
2152});
2153pub static MZ_POSTGRES_SOURCE_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2154 name: "mz_postgres_source_tables",
2155 schema: MZ_INTERNAL_SCHEMA,
2156 oid: oid::TABLE_MZ_POSTGRES_SOURCE_TABLES_OID,
2157 desc: RelationDesc::builder()
2158 .with_column("id", SqlScalarType::String.nullable(false))
2159 .with_column("schema_name", SqlScalarType::String.nullable(false))
2160 .with_column("table_name", SqlScalarType::String.nullable(false))
2161 .finish(),
2162 column_comments: BTreeMap::from_iter([
2163 (
2164 "id",
2165 "The ID of the subsource or table. Corresponds to `mz_catalog.mz_sources.id` or `mz_catalog.mz_tables.id`.",
2166 ),
2167 (
2168 "schema_name",
2169 "The schema of the upstream table being ingested.",
2170 ),
2171 (
2172 "table_name",
2173 "The name of the upstream table being ingested.",
2174 ),
2175 ]),
2176 is_retained_metrics_object: true,
2177 access: vec![PUBLIC_SELECT],
2178});
2179pub static MZ_MYSQL_SOURCE_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2180 name: "mz_mysql_source_tables",
2181 schema: MZ_INTERNAL_SCHEMA,
2182 oid: oid::TABLE_MZ_MYSQL_SOURCE_TABLES_OID,
2183 desc: RelationDesc::builder()
2184 .with_column("id", SqlScalarType::String.nullable(false))
2185 .with_column("schema_name", SqlScalarType::String.nullable(false))
2186 .with_column("table_name", SqlScalarType::String.nullable(false))
2187 .finish(),
2188 column_comments: BTreeMap::from_iter([
2189 (
2190 "id",
2191 "The ID of the subsource or table. Corresponds to `mz_catalog.mz_sources.id` or `mz_catalog.mz_tables.id`.",
2192 ),
2193 (
2194 "schema_name",
2195 "The schema (or, database) of the upstream table being ingested.",
2196 ),
2197 (
2198 "table_name",
2199 "The name of the upstream table being ingested.",
2200 ),
2201 ]),
2202 is_retained_metrics_object: true,
2203 access: vec![PUBLIC_SELECT],
2204});
2205pub static MZ_SQL_SERVER_SOURCE_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2206 name: "mz_sql_server_source_tables",
2207 schema: MZ_INTERNAL_SCHEMA,
2208 oid: oid::TABLE_MZ_SQL_SERVER_SOURCE_TABLES_OID,
2209 desc: RelationDesc::builder()
2210 .with_column("id", SqlScalarType::String.nullable(false))
2211 .with_column("schema_name", SqlScalarType::String.nullable(false))
2212 .with_column("table_name", SqlScalarType::String.nullable(false))
2213 .finish(),
2214 column_comments: BTreeMap::from_iter([
2215 (
2216 "id",
2217 "The ID of the subsource or table. Corresponds to `mz_catalog.mz_sources.id` or `mz_catalog.mz_tables.id`.",
2218 ),
2219 (
2220 "schema_name",
2221 "The schema of the upstream table being ingested.",
2222 ),
2223 (
2224 "table_name",
2225 "The name of the upstream table being ingested.",
2226 ),
2227 ]),
2228 is_retained_metrics_object: true,
2229 access: vec![PUBLIC_SELECT],
2230});
2231pub static MZ_KAFKA_SOURCE_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2232 name: "mz_kafka_source_tables",
2233 schema: MZ_INTERNAL_SCHEMA,
2234 oid: oid::TABLE_MZ_KAFKA_SOURCE_TABLES_OID,
2235 desc: RelationDesc::builder()
2236 .with_column("id", SqlScalarType::String.nullable(false))
2237 .with_column("topic", SqlScalarType::String.nullable(false))
2238 .with_column("envelope_type", SqlScalarType::String.nullable(true))
2239 .with_column("key_format", SqlScalarType::String.nullable(true))
2240 .with_column("value_format", SqlScalarType::String.nullable(true))
2241 .finish(),
2242 column_comments: BTreeMap::from_iter([
2243 (
2244 "id",
2245 "The ID of the table. Corresponds to `mz_catalog.mz_tables.id`.",
2246 ),
2247 ("topic", "The topic being ingested."),
2248 (
2249 "envelope_type",
2250 "The envelope type: `none`, `upsert`, or `debezium`. `NULL` for other source types.",
2251 ),
2252 (
2253 "key_format",
2254 "The format of the Kafka message key: `avro`, `csv`, `regex`, `bytes`, `json`, `text`, or `NULL`.",
2255 ),
2256 (
2257 "value_format",
2258 "The format of the Kafka message value: `avro`, `csv`, `regex`, `bytes`, `json`, `text`. `NULL` for other source types.",
2259 ),
2260 ]),
2261 is_retained_metrics_object: true,
2262 access: vec![PUBLIC_SELECT],
2263});
2264pub static MZ_OBJECT_DEPENDENCIES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2265 name: "mz_object_dependencies",
2266 schema: MZ_INTERNAL_SCHEMA,
2267 oid: oid::TABLE_MZ_OBJECT_DEPENDENCIES_OID,
2268 desc: RelationDesc::builder()
2269 .with_column("object_id", SqlScalarType::String.nullable(false))
2270 .with_column(
2271 "referenced_object_id",
2272 SqlScalarType::String.nullable(false),
2273 )
2274 .finish(),
2275 column_comments: BTreeMap::from_iter([
2276 (
2277 "object_id",
2278 "The ID of the dependent object. Corresponds to `mz_objects.id`.",
2279 ),
2280 (
2281 "referenced_object_id",
2282 "The ID of the referenced object. Corresponds to `mz_objects.id`.",
2283 ),
2284 ]),
2285 is_retained_metrics_object: true,
2286 access: vec![PUBLIC_SELECT],
2287});
2288pub static MZ_COMPUTE_DEPENDENCIES: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
2289 name: "mz_compute_dependencies",
2290 schema: MZ_INTERNAL_SCHEMA,
2291 oid: oid::SOURCE_MZ_COMPUTE_DEPENDENCIES_OID,
2292 data_source: IntrospectionType::ComputeDependencies.into(),
2293 desc: RelationDesc::builder()
2294 .with_column("object_id", SqlScalarType::String.nullable(false))
2295 .with_column("dependency_id", SqlScalarType::String.nullable(false))
2296 .finish(),
2297 column_comments: BTreeMap::from_iter([
2298 (
2299 "object_id",
2300 "The ID of a compute object. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, or `mz_internal.mz_subscriptions`.",
2301 ),
2302 (
2303 "dependency_id",
2304 "The ID of a compute dependency. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, `mz_catalog.mz_sources.id`, or `mz_catalog.mz_tables.id`.",
2305 ),
2306 ]),
2307 is_retained_metrics_object: false,
2308 access: vec![PUBLIC_SELECT],
2309});
2310
2311pub static MZ_DATABASES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2312 name: "mz_databases",
2313 schema: MZ_CATALOG_SCHEMA,
2314 oid: oid::TABLE_MZ_DATABASES_OID,
2315 desc: RelationDesc::builder()
2316 .with_column("id", SqlScalarType::String.nullable(false))
2317 .with_column("oid", SqlScalarType::Oid.nullable(false))
2318 .with_column("name", SqlScalarType::String.nullable(false))
2319 .with_column("owner_id", SqlScalarType::String.nullable(false))
2320 .with_column(
2321 "privileges",
2322 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2323 )
2324 .with_key(vec![0])
2325 .with_key(vec![1])
2326 .finish(),
2327 column_comments: BTreeMap::from_iter([
2328 ("id", "Materialize's unique ID for the database."),
2329 ("oid", "A PostgreSQL-compatible OID for the database."),
2330 ("name", "The name of the database."),
2331 (
2332 "owner_id",
2333 "The role ID of the owner of the database. Corresponds to `mz_roles.id`.",
2334 ),
2335 ("privileges", "The privileges belonging to the database."),
2336 ]),
2337 is_retained_metrics_object: false,
2338 access: vec![PUBLIC_SELECT],
2339});
2340pub static MZ_SCHEMAS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2341 name: "mz_schemas",
2342 schema: MZ_CATALOG_SCHEMA,
2343 oid: oid::TABLE_MZ_SCHEMAS_OID,
2344 desc: RelationDesc::builder()
2345 .with_column("id", SqlScalarType::String.nullable(false))
2346 .with_column("oid", SqlScalarType::Oid.nullable(false))
2347 .with_column("database_id", SqlScalarType::String.nullable(true))
2348 .with_column("name", SqlScalarType::String.nullable(false))
2349 .with_column("owner_id", SqlScalarType::String.nullable(false))
2350 .with_column(
2351 "privileges",
2352 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2353 )
2354 .with_key(vec![0])
2355 .with_key(vec![1])
2356 .finish(),
2357 column_comments: BTreeMap::from_iter([
2358 ("id", "Materialize's unique ID for the schema."),
2359 ("oid", "A PostgreSQL-compatible oid for the schema."),
2360 (
2361 "database_id",
2362 "The ID of the database containing the schema. Corresponds to `mz_databases.id`.",
2363 ),
2364 ("name", "The name of the schema."),
2365 (
2366 "owner_id",
2367 "The role ID of the owner of the schema. Corresponds to `mz_roles.id`.",
2368 ),
2369 ("privileges", "The privileges belonging to the schema."),
2370 ]),
2371 is_retained_metrics_object: false,
2372 access: vec![PUBLIC_SELECT],
2373});
2374pub static MZ_COLUMNS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2375 name: "mz_columns",
2376 schema: MZ_CATALOG_SCHEMA,
2377 oid: oid::TABLE_MZ_COLUMNS_OID,
2378 desc: RelationDesc::builder()
2379 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("name", SqlScalarType::String.nullable(false))
2381 .with_column("position", SqlScalarType::UInt64.nullable(false))
2382 .with_column("nullable", SqlScalarType::Bool.nullable(false))
2383 .with_column("type", SqlScalarType::String.nullable(false))
2384 .with_column("default", SqlScalarType::String.nullable(true))
2385 .with_column("type_oid", SqlScalarType::Oid.nullable(false))
2386 .with_column("type_mod", SqlScalarType::Int32.nullable(false))
2387 .finish(),
2388 column_comments: BTreeMap::from_iter([
2389 (
2390 "id",
2391 "The unique ID of the table, source, or view containing the column.",
2392 ),
2393 ("name", "The name of the column."),
2394 (
2395 "position",
2396 "The 1-indexed position of the column in its containing table, source, or view.",
2397 ),
2398 ("nullable", "Can the column contain a `NULL` value?"),
2399 ("type", "The data type of the column."),
2400 ("default", "The default expression of the column."),
2401 (
2402 "type_oid",
2403 "The OID of the type of the column (references `mz_types`).",
2404 ),
2405 ("type_mod", "The packed type identifier of the column."),
2406 ]),
2407 is_retained_metrics_object: false,
2408 access: vec![PUBLIC_SELECT],
2409});
2410pub static MZ_INDEXES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2411 name: "mz_indexes",
2412 schema: MZ_CATALOG_SCHEMA,
2413 oid: oid::TABLE_MZ_INDEXES_OID,
2414 desc: RelationDesc::builder()
2415 .with_column("id", SqlScalarType::String.nullable(false))
2416 .with_column("oid", SqlScalarType::Oid.nullable(false))
2417 .with_column("name", SqlScalarType::String.nullable(false))
2418 .with_column("on_id", SqlScalarType::String.nullable(false))
2419 .with_column("cluster_id", SqlScalarType::String.nullable(false))
2420 .with_column("owner_id", SqlScalarType::String.nullable(false))
2421 .with_column("create_sql", SqlScalarType::String.nullable(false))
2422 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2423 .with_key(vec![0])
2424 .with_key(vec![1])
2425 .finish(),
2426 column_comments: BTreeMap::from_iter([
2427 ("id", "Materialize's unique ID for the index."),
2428 ("oid", "A PostgreSQL-compatible OID for the index."),
2429 ("name", "The name of the index."),
2430 (
2431 "on_id",
2432 "The ID of the relation on which the index is built.",
2433 ),
2434 (
2435 "cluster_id",
2436 "The ID of the cluster in which the index is built.",
2437 ),
2438 (
2439 "owner_id",
2440 "The role ID of the owner of the index. Corresponds to `mz_roles.id`.",
2441 ),
2442 ("create_sql", "The `CREATE` SQL statement for the index."),
2443 (
2444 "redacted_create_sql",
2445 "The redacted `CREATE` SQL statement for the index.",
2446 ),
2447 ]),
2448 is_retained_metrics_object: false,
2449 access: vec![PUBLIC_SELECT],
2450});
2451pub static MZ_INDEX_COLUMNS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2452 name: "mz_index_columns",
2453 schema: MZ_CATALOG_SCHEMA,
2454 oid: oid::TABLE_MZ_INDEX_COLUMNS_OID,
2455 desc: RelationDesc::builder()
2456 .with_column("index_id", SqlScalarType::String.nullable(false))
2457 .with_column("index_position", SqlScalarType::UInt64.nullable(false))
2458 .with_column("on_position", SqlScalarType::UInt64.nullable(true))
2459 .with_column("on_expression", SqlScalarType::String.nullable(true))
2460 .with_column("nullable", SqlScalarType::Bool.nullable(false))
2461 .finish(),
2462 column_comments: BTreeMap::from_iter([
2463 (
2464 "index_id",
2465 "The ID of the index which contains this column. Corresponds to `mz_indexes.id`.",
2466 ),
2467 (
2468 "index_position",
2469 "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.)",
2470 ),
2471 (
2472 "on_position",
2473 "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.",
2474 ),
2475 (
2476 "on_expression",
2477 "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.",
2478 ),
2479 (
2480 "nullable",
2481 "Can this column of the index evaluate to `NULL`?",
2482 ),
2483 ]),
2484 is_retained_metrics_object: false,
2485 access: vec![PUBLIC_SELECT],
2486});
2487pub static MZ_TABLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2488 name: "mz_tables",
2489 schema: MZ_CATALOG_SCHEMA,
2490 oid: oid::TABLE_MZ_TABLES_OID,
2491 desc: RelationDesc::builder()
2492 .with_column("id", SqlScalarType::String.nullable(false))
2493 .with_column("oid", SqlScalarType::Oid.nullable(false))
2494 .with_column("schema_id", SqlScalarType::String.nullable(false))
2495 .with_column("name", SqlScalarType::String.nullable(false))
2496 .with_column("owner_id", SqlScalarType::String.nullable(false))
2497 .with_column(
2498 "privileges",
2499 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2500 )
2501 .with_column("create_sql", SqlScalarType::String.nullable(true))
2502 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
2503 .with_column("source_id", SqlScalarType::String.nullable(true))
2504 .with_key(vec![0])
2505 .with_key(vec![1])
2506 .finish(),
2507 column_comments: BTreeMap::from_iter([
2508 ("id", "Materialize's unique ID for the table."),
2509 ("oid", "A PostgreSQL-compatible OID for the table."),
2510 (
2511 "schema_id",
2512 "The ID of the schema to which the table belongs. Corresponds to `mz_schemas.id`.",
2513 ),
2514 ("name", "The name of the table."),
2515 (
2516 "owner_id",
2517 "The role ID of the owner of the table. Corresponds to `mz_roles.id`.",
2518 ),
2519 ("privileges", "The privileges belonging to the table."),
2520 ("create_sql", "The `CREATE` SQL statement for the table."),
2521 (
2522 "redacted_create_sql",
2523 "The redacted `CREATE` SQL statement for the table.",
2524 ),
2525 (
2526 "source_id",
2527 "The ID of the source associated with the table, if any. Corresponds to `mz_sources.id`.",
2528 ),
2529 ]),
2530 is_retained_metrics_object: true,
2531 access: vec![PUBLIC_SELECT],
2532});
2533pub static MZ_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2534 name: "mz_connections",
2535 schema: MZ_CATALOG_SCHEMA,
2536 oid: oid::TABLE_MZ_CONNECTIONS_OID,
2537 desc: RelationDesc::builder()
2538 .with_column("id", SqlScalarType::String.nullable(false))
2539 .with_column("oid", SqlScalarType::Oid.nullable(false))
2540 .with_column("schema_id", SqlScalarType::String.nullable(false))
2541 .with_column("name", SqlScalarType::String.nullable(false))
2542 .with_column("type", SqlScalarType::String.nullable(false))
2543 .with_column("owner_id", SqlScalarType::String.nullable(false))
2544 .with_column(
2545 "privileges",
2546 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2547 )
2548 .with_column("create_sql", SqlScalarType::String.nullable(false))
2549 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2550 .with_key(vec![0])
2551 .with_key(vec![1])
2552 .finish(),
2553 column_comments: BTreeMap::from_iter([
2554 ("id", "The unique ID of the connection."),
2555 ("oid", "A PostgreSQL-compatible OID for the connection."),
2556 (
2557 "schema_id",
2558 "The ID of the schema to which the connection belongs. Corresponds to `mz_schemas.id`.",
2559 ),
2560 ("name", "The name of the connection."),
2561 (
2562 "type",
2563 "The type of the connection: `confluent-schema-registry`, `kafka`, `postgres`, or `ssh-tunnel`.",
2564 ),
2565 (
2566 "owner_id",
2567 "The role ID of the owner of the connection. Corresponds to `mz_roles.id`.",
2568 ),
2569 ("privileges", "The privileges belonging to the connection."),
2570 (
2571 "create_sql",
2572 "The `CREATE` SQL statement for the connection.",
2573 ),
2574 (
2575 "redacted_create_sql",
2576 "The redacted `CREATE` SQL statement for the connection.",
2577 ),
2578 ]),
2579 is_retained_metrics_object: false,
2580 access: vec![PUBLIC_SELECT],
2581});
2582pub static MZ_SSH_TUNNEL_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2583 name: "mz_ssh_tunnel_connections",
2584 schema: MZ_CATALOG_SCHEMA,
2585 oid: oid::TABLE_MZ_SSH_TUNNEL_CONNECTIONS_OID,
2586 desc: RelationDesc::builder()
2587 .with_column("id", SqlScalarType::String.nullable(false))
2588 .with_column("public_key_1", SqlScalarType::String.nullable(false))
2589 .with_column("public_key_2", SqlScalarType::String.nullable(false))
2590 .finish(),
2591 column_comments: BTreeMap::from_iter([
2592 ("id", "The ID of the connection."),
2593 (
2594 "public_key_1",
2595 "The first public key associated with the SSH tunnel.",
2596 ),
2597 (
2598 "public_key_2",
2599 "The second public key associated with the SSH tunnel.",
2600 ),
2601 ]),
2602 is_retained_metrics_object: false,
2603 access: vec![PUBLIC_SELECT],
2604});
2605pub static MZ_SOURCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2606 name: "mz_sources",
2607 schema: MZ_CATALOG_SCHEMA,
2608 oid: oid::TABLE_MZ_SOURCES_OID,
2609 desc: RelationDesc::builder()
2610 .with_column("id", SqlScalarType::String.nullable(false))
2611 .with_column("oid", SqlScalarType::Oid.nullable(false))
2612 .with_column("schema_id", SqlScalarType::String.nullable(false))
2613 .with_column("name", SqlScalarType::String.nullable(false))
2614 .with_column("type", SqlScalarType::String.nullable(false))
2615 .with_column("connection_id", SqlScalarType::String.nullable(true))
2616 .with_column("size", SqlScalarType::String.nullable(true))
2617 .with_column("envelope_type", SqlScalarType::String.nullable(true))
2618 .with_column("key_format", SqlScalarType::String.nullable(true))
2619 .with_column("value_format", SqlScalarType::String.nullable(true))
2620 .with_column("cluster_id", SqlScalarType::String.nullable(true))
2621 .with_column("owner_id", SqlScalarType::String.nullable(false))
2622 .with_column(
2623 "privileges",
2624 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2625 )
2626 .with_column("create_sql", SqlScalarType::String.nullable(true))
2627 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
2628 .with_key(vec![0])
2629 .with_key(vec![1])
2630 .finish(),
2631 column_comments: BTreeMap::from_iter([
2632 ("id", "Materialize's unique ID for the source."),
2633 ("oid", "A PostgreSQL-compatible OID for the source."),
2634 (
2635 "schema_id",
2636 "The ID of the schema to which the source belongs. Corresponds to `mz_schemas.id`.",
2637 ),
2638 ("name", "The name of the source."),
2639 (
2640 "type",
2641 "The type of the source: `kafka`, `mysql`, `postgres`, `load-generator`, `progress`, or `subsource`.",
2642 ),
2643 (
2644 "connection_id",
2645 "The ID of the connection associated with the source, if any. Corresponds to `mz_connections.id`.",
2646 ),
2647 ("size", "*Deprecated* The size of the source."),
2648 (
2649 "envelope_type",
2650 "For Kafka sources, the envelope type: `none`, `upsert`, or `debezium`. `NULL` for other source types.",
2651 ),
2652 (
2653 "key_format",
2654 "For Kafka sources, the format of the Kafka message key: `avro`, `csv`, `regex`, `bytes`, `json`, `text`, or `NULL`.",
2655 ),
2656 (
2657 "value_format",
2658 "For Kafka sources, the format of the Kafka message value: `avro`, `csv`, `regex`, `bytes`, `json`, `text`. `NULL` for other source types.",
2659 ),
2660 (
2661 "cluster_id",
2662 "The ID of the cluster maintaining the source. Corresponds to `mz_clusters.id`.",
2663 ),
2664 (
2665 "owner_id",
2666 "The role ID of the owner of the source. Corresponds to `mz_roles.id`.",
2667 ),
2668 ("privileges", "The privileges granted on the source."),
2669 ("create_sql", "The `CREATE` SQL statement for the source."),
2670 (
2671 "redacted_create_sql",
2672 "The redacted `CREATE` SQL statement for the source.",
2673 ),
2674 ]),
2675 is_retained_metrics_object: true,
2676 access: vec![PUBLIC_SELECT],
2677});
2678pub static MZ_SINKS: LazyLock<BuiltinTable> = LazyLock::new(|| {
2679 BuiltinTable {
2680 name: "mz_sinks",
2681 schema: MZ_CATALOG_SCHEMA,
2682 oid: oid::TABLE_MZ_SINKS_OID,
2683 desc: RelationDesc::builder()
2684 .with_column("id", SqlScalarType::String.nullable(false))
2685 .with_column("oid", SqlScalarType::Oid.nullable(false))
2686 .with_column("schema_id", SqlScalarType::String.nullable(false))
2687 .with_column("name", SqlScalarType::String.nullable(false))
2688 .with_column("type", SqlScalarType::String.nullable(false))
2689 .with_column("connection_id", SqlScalarType::String.nullable(true))
2690 .with_column("size", SqlScalarType::String.nullable(true))
2691 .with_column("envelope_type", SqlScalarType::String.nullable(true))
2692 .with_column("format", SqlScalarType::String.nullable(true))
2695 .with_column("key_format", SqlScalarType::String.nullable(true))
2696 .with_column("value_format", SqlScalarType::String.nullable(true))
2697 .with_column("cluster_id", SqlScalarType::String.nullable(false))
2698 .with_column("owner_id", SqlScalarType::String.nullable(false))
2699 .with_column("create_sql", SqlScalarType::String.nullable(false))
2700 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2701 .with_key(vec![0])
2702 .with_key(vec![1])
2703 .finish(),
2704 column_comments: BTreeMap::from_iter([
2705 ("id", "Materialize's unique ID for the sink."),
2706 ("oid", "A PostgreSQL-compatible OID for the sink."),
2707 (
2708 "schema_id",
2709 "The ID of the schema to which the sink belongs. Corresponds to `mz_schemas.id`.",
2710 ),
2711 ("name", "The name of the sink."),
2712 ("type", "The type of the sink: `kafka`."),
2713 (
2714 "connection_id",
2715 "The ID of the connection associated with the sink, if any. Corresponds to `mz_connections.id`.",
2716 ),
2717 ("size", "The size of the sink."),
2718 (
2719 "envelope_type",
2720 "The envelope of the sink: `upsert`, or `debezium`.",
2721 ),
2722 (
2723 "format",
2724 "*Deprecated* The format of the Kafka messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
2725 ),
2726 (
2727 "key_format",
2728 "The format of the Kafka message key for messages produced by the sink: `avro`, `json`, `bytes`, `text`, or `NULL`.",
2729 ),
2730 (
2731 "value_format",
2732 "The format of the Kafka message value for messages produced by the sink: `avro`, `json`, `text`, or `bytes`.",
2733 ),
2734 (
2735 "cluster_id",
2736 "The ID of the cluster maintaining the sink. Corresponds to `mz_clusters.id`.",
2737 ),
2738 (
2739 "owner_id",
2740 "The role ID of the owner of the sink. Corresponds to `mz_roles.id`.",
2741 ),
2742 ("create_sql", "The `CREATE` SQL statement for the sink."),
2743 (
2744 "redacted_create_sql",
2745 "The redacted `CREATE` SQL statement for the sink.",
2746 ),
2747 ]),
2748 is_retained_metrics_object: true,
2749 access: vec![PUBLIC_SELECT],
2750 }
2751});
2752pub static MZ_VIEWS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2753 name: "mz_views",
2754 schema: MZ_CATALOG_SCHEMA,
2755 oid: oid::TABLE_MZ_VIEWS_OID,
2756 desc: RelationDesc::builder()
2757 .with_column("id", SqlScalarType::String.nullable(false))
2758 .with_column("oid", SqlScalarType::Oid.nullable(false))
2759 .with_column("schema_id", SqlScalarType::String.nullable(false))
2760 .with_column("name", SqlScalarType::String.nullable(false))
2761 .with_column("definition", SqlScalarType::String.nullable(false))
2762 .with_column("owner_id", SqlScalarType::String.nullable(false))
2763 .with_column(
2764 "privileges",
2765 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2766 )
2767 .with_column("create_sql", SqlScalarType::String.nullable(false))
2768 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2769 .with_key(vec![0])
2770 .with_key(vec![1])
2771 .finish(),
2772 column_comments: BTreeMap::from_iter([
2773 ("id", "Materialize's unique ID for the view."),
2774 ("oid", "A PostgreSQL-compatible OID for the view."),
2775 (
2776 "schema_id",
2777 "The ID of the schema to which the view belongs. Corresponds to `mz_schemas.id`.",
2778 ),
2779 ("name", "The name of the view."),
2780 ("definition", "The view definition (a `SELECT` query)."),
2781 (
2782 "owner_id",
2783 "The role ID of the owner of the view. Corresponds to `mz_roles.id`.",
2784 ),
2785 ("privileges", "The privileges belonging to the view."),
2786 ("create_sql", "The `CREATE` SQL statement for the view."),
2787 (
2788 "redacted_create_sql",
2789 "The redacted `CREATE` SQL statement for the view.",
2790 ),
2791 ]),
2792 is_retained_metrics_object: false,
2793 access: vec![PUBLIC_SELECT],
2794});
2795pub static MZ_MATERIALIZED_VIEWS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2796 name: "mz_materialized_views",
2797 schema: MZ_CATALOG_SCHEMA,
2798 oid: oid::TABLE_MZ_MATERIALIZED_VIEWS_OID,
2799 desc: RelationDesc::builder()
2800 .with_column("id", SqlScalarType::String.nullable(false))
2801 .with_column("oid", SqlScalarType::Oid.nullable(false))
2802 .with_column("schema_id", SqlScalarType::String.nullable(false))
2803 .with_column("name", SqlScalarType::String.nullable(false))
2804 .with_column("cluster_id", SqlScalarType::String.nullable(false))
2805 .with_column("definition", SqlScalarType::String.nullable(false))
2806 .with_column("owner_id", SqlScalarType::String.nullable(false))
2807 .with_column(
2808 "privileges",
2809 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2810 )
2811 .with_column("create_sql", SqlScalarType::String.nullable(false))
2812 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2813 .with_key(vec![0])
2814 .with_key(vec![1])
2815 .finish(),
2816 column_comments: BTreeMap::from_iter([
2817 ("id", "Materialize's unique ID for the materialized view."),
2818 (
2819 "oid",
2820 "A PostgreSQL-compatible OID for the materialized view.",
2821 ),
2822 (
2823 "schema_id",
2824 "The ID of the schema to which the materialized view belongs. Corresponds to `mz_schemas.id`.",
2825 ),
2826 ("name", "The name of the materialized view."),
2827 (
2828 "cluster_id",
2829 "The ID of the cluster maintaining the materialized view. Corresponds to `mz_clusters.id`.",
2830 ),
2831 (
2832 "definition",
2833 "The materialized view definition (a `SELECT` query).",
2834 ),
2835 (
2836 "owner_id",
2837 "The role ID of the owner of the materialized view. Corresponds to `mz_roles.id`.",
2838 ),
2839 (
2840 "privileges",
2841 "The privileges belonging to the materialized view.",
2842 ),
2843 (
2844 "create_sql",
2845 "The `CREATE` SQL statement for the materialized view.",
2846 ),
2847 (
2848 "redacted_create_sql",
2849 "The redacted `CREATE` SQL statement for the materialized view.",
2850 ),
2851 ]),
2852 is_retained_metrics_object: false,
2853 access: vec![PUBLIC_SELECT],
2854});
2855pub static MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES: LazyLock<BuiltinTable> = LazyLock::new(|| {
2856 BuiltinTable {
2857 name: "mz_materialized_view_refresh_strategies",
2858 schema: MZ_INTERNAL_SCHEMA,
2859 oid: oid::TABLE_MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES_OID,
2860 desc: RelationDesc::builder()
2861 .with_column(
2862 "materialized_view_id",
2863 SqlScalarType::String.nullable(false),
2864 )
2865 .with_column("type", SqlScalarType::String.nullable(false))
2866 .with_column("interval", SqlScalarType::Interval.nullable(true))
2867 .with_column(
2868 "aligned_to",
2869 SqlScalarType::TimestampTz { precision: None }.nullable(true),
2870 )
2871 .with_column(
2872 "at",
2873 SqlScalarType::TimestampTz { precision: None }.nullable(true),
2874 )
2875 .finish(),
2876 column_comments: BTreeMap::from_iter([
2877 (
2878 "materialized_view_id",
2879 "The ID of the materialized view. Corresponds to `mz_catalog.mz_materialized_views.id`",
2880 ),
2881 (
2882 "type",
2883 "`at`, `every`, or `on-commit`. Default: `on-commit`",
2884 ),
2885 (
2886 "interval",
2887 "The refresh interval of a `REFRESH EVERY` option, or `NULL` if the `type` is not `every`.",
2888 ),
2889 (
2890 "aligned_to",
2891 "The `ALIGNED TO` option of a `REFRESH EVERY` option, or `NULL` if the `type` is not `every`.",
2892 ),
2893 (
2894 "at",
2895 "The time of a `REFRESH AT`, or `NULL` if the `type` is not `at`.",
2896 ),
2897 ]),
2898 is_retained_metrics_object: false,
2899 access: vec![PUBLIC_SELECT],
2900 }
2901});
2902pub static MZ_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2903 name: "mz_types",
2904 schema: MZ_CATALOG_SCHEMA,
2905 oid: oid::TABLE_MZ_TYPES_OID,
2906 desc: RelationDesc::builder()
2907 .with_column("id", SqlScalarType::String.nullable(false))
2908 .with_column("oid", SqlScalarType::Oid.nullable(false))
2909 .with_column("schema_id", SqlScalarType::String.nullable(false))
2910 .with_column("name", SqlScalarType::String.nullable(false))
2911 .with_column("category", SqlScalarType::String.nullable(false))
2912 .with_column("owner_id", SqlScalarType::String.nullable(false))
2913 .with_column(
2914 "privileges",
2915 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2916 )
2917 .with_column("create_sql", SqlScalarType::String.nullable(true))
2918 .with_column("redacted_create_sql", SqlScalarType::String.nullable(true))
2919 .with_key(vec![0])
2920 .with_key(vec![1])
2921 .finish(),
2922 column_comments: BTreeMap::from_iter([
2923 ("id", "Materialize's unique ID for the type."),
2924 ("oid", "A PostgreSQL-compatible OID for the type."),
2925 (
2926 "schema_id",
2927 "The ID of the schema to which the type belongs. Corresponds to `mz_schemas.id`.",
2928 ),
2929 ("name", "The name of the type."),
2930 ("category", "The category of the type."),
2931 (
2932 "owner_id",
2933 "The role ID of the owner of the type. Corresponds to `mz_roles.id`.",
2934 ),
2935 ("privileges", "The privileges belonging to the type."),
2936 ("create_sql", "The `CREATE` SQL statement for the type."),
2937 (
2938 "redacted_create_sql",
2939 "The redacted `CREATE` SQL statement for the type.",
2940 ),
2941 ]),
2942 is_retained_metrics_object: false,
2943 access: vec![PUBLIC_SELECT],
2944});
2945pub static MZ_CONTINUAL_TASKS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2946 name: "mz_continual_tasks",
2947 schema: MZ_INTERNAL_SCHEMA,
2948 oid: oid::TABLE_MZ_CONTINUAL_TASKS_OID,
2949 desc: RelationDesc::builder()
2950 .with_column("id", SqlScalarType::String.nullable(false))
2951 .with_column("oid", SqlScalarType::Oid.nullable(false))
2952 .with_column("schema_id", SqlScalarType::String.nullable(false))
2953 .with_column("name", SqlScalarType::String.nullable(false))
2954 .with_column("cluster_id", SqlScalarType::String.nullable(false))
2955 .with_column("definition", SqlScalarType::String.nullable(false))
2956 .with_column("owner_id", SqlScalarType::String.nullable(false))
2957 .with_column(
2958 "privileges",
2959 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2960 )
2961 .with_column("create_sql", SqlScalarType::String.nullable(false))
2962 .with_column("redacted_create_sql", SqlScalarType::String.nullable(false))
2963 .with_key(vec![0])
2964 .with_key(vec![1])
2965 .finish(),
2966 column_comments: BTreeMap::new(),
2967 is_retained_metrics_object: false,
2968 access: vec![PUBLIC_SELECT],
2969});
2970pub static MZ_NETWORK_POLICIES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
2971 name: "mz_network_policies",
2972 schema: MZ_INTERNAL_SCHEMA,
2973 oid: oid::TABLE_MZ_NETWORK_POLICIES_OID,
2974 desc: RelationDesc::builder()
2975 .with_column("id", SqlScalarType::String.nullable(false))
2976 .with_column("name", SqlScalarType::String.nullable(false))
2977 .with_column("owner_id", SqlScalarType::String.nullable(false))
2978 .with_column(
2979 "privileges",
2980 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
2981 )
2982 .with_column("oid", SqlScalarType::Oid.nullable(false))
2983 .finish(),
2984 column_comments: BTreeMap::from_iter([
2985 ("id", "The ID of the network policy."),
2986 ("name", "The name of the network policy."),
2987 (
2988 "owner_id",
2989 "The role ID of the owner of the network policy. Corresponds to `mz_catalog.mz_roles.id`.",
2990 ),
2991 (
2992 "privileges",
2993 "The privileges belonging to the network policy.",
2994 ),
2995 ("oid", "A PostgreSQL-compatible OID for the network policy."),
2996 ]),
2997 is_retained_metrics_object: false,
2998 access: vec![PUBLIC_SELECT],
2999});
3000pub static MZ_NETWORK_POLICY_RULES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3001 name: "mz_network_policy_rules",
3002 schema: MZ_INTERNAL_SCHEMA,
3003 oid: oid::TABLE_MZ_NETWORK_POLICY_RULES_OID,
3004 desc: RelationDesc::builder()
3005 .with_column("name", SqlScalarType::String.nullable(false))
3006 .with_column("policy_id", SqlScalarType::String.nullable(false))
3007 .with_column("action", SqlScalarType::String.nullable(false))
3008 .with_column("address", SqlScalarType::String.nullable(false))
3009 .with_column("direction", SqlScalarType::String.nullable(false))
3010 .finish(),
3011 column_comments: BTreeMap::from_iter([
3012 (
3013 "name",
3014 "The name of the network policy rule. Can be combined with `policy_id` to form a unique identifier.",
3015 ),
3016 (
3017 "policy_id",
3018 "The ID the network policy the rule is part of. Corresponds to `mz_network_policy_rules.id`.",
3019 ),
3020 (
3021 "action",
3022 "The action of the rule. `allow` is the only supported action.",
3023 ),
3024 ("address", "The address the rule will take action on."),
3025 (
3026 "direction",
3027 "The direction of traffic the rule applies to. `ingress` is the only supported direction.",
3028 ),
3029 ]),
3030 is_retained_metrics_object: false,
3031 access: vec![PUBLIC_SELECT],
3032});
3033pub static MZ_TYPE_PG_METADATA: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3036 name: "mz_type_pg_metadata",
3037 schema: MZ_INTERNAL_SCHEMA,
3038 oid: oid::TABLE_MZ_TYPE_PG_METADATA_OID,
3039 desc: RelationDesc::builder()
3040 .with_column("id", SqlScalarType::String.nullable(false))
3041 .with_column("typinput", SqlScalarType::Oid.nullable(false))
3042 .with_column("typreceive", SqlScalarType::Oid.nullable(false))
3043 .finish(),
3044 column_comments: BTreeMap::new(),
3045 is_retained_metrics_object: false,
3046 access: vec![PUBLIC_SELECT],
3047});
3048pub static MZ_ARRAY_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3049 name: "mz_array_types",
3050 schema: MZ_CATALOG_SCHEMA,
3051 oid: oid::TABLE_MZ_ARRAY_TYPES_OID,
3052 desc: RelationDesc::builder()
3053 .with_column("id", SqlScalarType::String.nullable(false))
3054 .with_column("element_id", SqlScalarType::String.nullable(false))
3055 .finish(),
3056 column_comments: BTreeMap::from_iter([
3057 ("id", "The ID of the array type."),
3058 ("element_id", "The ID of the array's element type."),
3059 ]),
3060 is_retained_metrics_object: false,
3061 access: vec![PUBLIC_SELECT],
3062});
3063pub static MZ_BASE_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3064 name: "mz_base_types",
3065 schema: MZ_CATALOG_SCHEMA,
3066 oid: oid::TABLE_MZ_BASE_TYPES_OID,
3067 desc: RelationDesc::builder()
3068 .with_column("id", SqlScalarType::String.nullable(false))
3069 .finish(),
3070 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
3071 is_retained_metrics_object: false,
3072 access: vec![PUBLIC_SELECT],
3073});
3074pub static MZ_LIST_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3075 name: "mz_list_types",
3076 schema: MZ_CATALOG_SCHEMA,
3077 oid: oid::TABLE_MZ_LIST_TYPES_OID,
3078 desc: RelationDesc::builder()
3079 .with_column("id", SqlScalarType::String.nullable(false))
3080 .with_column("element_id", SqlScalarType::String.nullable(false))
3081 .with_column(
3082 "element_modifiers",
3083 SqlScalarType::List {
3084 element_type: Box::new(SqlScalarType::Int64),
3085 custom_id: None,
3086 }
3087 .nullable(true),
3088 )
3089 .finish(),
3090 column_comments: BTreeMap::from_iter([
3091 ("id", "The ID of the list type."),
3092 ("element_id", "The IID of the list's element type."),
3093 (
3094 "element_modifiers",
3095 "The element type modifiers, or `NULL` if none.",
3096 ),
3097 ]),
3098 is_retained_metrics_object: false,
3099 access: vec![PUBLIC_SELECT],
3100});
3101pub static MZ_MAP_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3102 name: "mz_map_types",
3103 schema: MZ_CATALOG_SCHEMA,
3104 oid: oid::TABLE_MZ_MAP_TYPES_OID,
3105 desc: RelationDesc::builder()
3106 .with_column("id", SqlScalarType::String.nullable(false))
3107 .with_column("key_id", SqlScalarType::String.nullable(false))
3108 .with_column("value_id", SqlScalarType::String.nullable(false))
3109 .with_column(
3110 "key_modifiers",
3111 SqlScalarType::List {
3112 element_type: Box::new(SqlScalarType::Int64),
3113 custom_id: None,
3114 }
3115 .nullable(true),
3116 )
3117 .with_column(
3118 "value_modifiers",
3119 SqlScalarType::List {
3120 element_type: Box::new(SqlScalarType::Int64),
3121 custom_id: None,
3122 }
3123 .nullable(true),
3124 )
3125 .finish(),
3126 column_comments: BTreeMap::from_iter([
3127 ("id", "The ID of the map type."),
3128 ("key_id", "The ID of the map's key type."),
3129 ("value_id", "The ID of the map's value type."),
3130 (
3131 "key_modifiers",
3132 "The key type modifiers, or `NULL` if none.",
3133 ),
3134 (
3135 "value_modifiers",
3136 "The value type modifiers, or `NULL` if none.",
3137 ),
3138 ]),
3139 is_retained_metrics_object: false,
3140 access: vec![PUBLIC_SELECT],
3141});
3142pub static MZ_ROLES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3143 name: "mz_roles",
3144 schema: MZ_CATALOG_SCHEMA,
3145 oid: oid::TABLE_MZ_ROLES_OID,
3146 desc: RelationDesc::builder()
3147 .with_column("id", SqlScalarType::String.nullable(false))
3148 .with_column("oid", SqlScalarType::Oid.nullable(false))
3149 .with_column("name", SqlScalarType::String.nullable(false))
3150 .with_column("inherit", SqlScalarType::Bool.nullable(false))
3151 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(true))
3152 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
3153 .with_key(vec![0])
3154 .with_key(vec![1])
3155 .finish(),
3156 column_comments: BTreeMap::from_iter([
3157 ("id", "Materialize's unique ID for the role."),
3158 ("oid", "A PostgreSQL-compatible OID for the role."),
3159 ("name", "The name of the role."),
3160 (
3161 "inherit",
3162 "Indicates whether the role has inheritance of privileges.",
3163 ),
3164 ("rolcanlogin", "Indicates whether the role can log in."),
3165 ("rolsuper", "Indicates whether the role is a superuser."),
3166 ]),
3167 is_retained_metrics_object: false,
3168 access: vec![PUBLIC_SELECT],
3169});
3170pub static MZ_ROLE_MEMBERS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3171 name: "mz_role_members",
3172 schema: MZ_CATALOG_SCHEMA,
3173 oid: oid::TABLE_MZ_ROLE_MEMBERS_OID,
3174 desc: RelationDesc::builder()
3175 .with_column("role_id", SqlScalarType::String.nullable(false))
3176 .with_column("member", SqlScalarType::String.nullable(false))
3177 .with_column("grantor", SqlScalarType::String.nullable(false))
3178 .finish(),
3179 column_comments: BTreeMap::from_iter([
3180 (
3181 "role_id",
3182 "The ID of the role the `member` is a member of. Corresponds to `mz_roles.id`.",
3183 ),
3184 (
3185 "member",
3186 "The ID of the role that is a member of `role_id`. Corresponds to `mz_roles.id`.",
3187 ),
3188 (
3189 "grantor",
3190 "The ID of the role that granted membership of `member` to `role_id`. Corresponds to `mz_roles.id`.",
3191 ),
3192 ]),
3193 is_retained_metrics_object: false,
3194 access: vec![PUBLIC_SELECT],
3195});
3196pub static MZ_ROLE_PARAMETERS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3197 name: "mz_role_parameters",
3198 schema: MZ_CATALOG_SCHEMA,
3199 oid: oid::TABLE_MZ_ROLE_PARAMETERS_OID,
3200 desc: RelationDesc::builder()
3201 .with_column("role_id", SqlScalarType::String.nullable(false))
3202 .with_column("parameter_name", SqlScalarType::String.nullable(false))
3203 .with_column("parameter_value", SqlScalarType::String.nullable(false))
3204 .finish(),
3205 column_comments: BTreeMap::from_iter([
3206 (
3207 "role_id",
3208 "The ID of the role whose configuration parameter default is set. Corresponds to `mz_roles.id`.",
3209 ),
3210 (
3211 "parameter_name",
3212 "The configuration parameter name. One of the supported configuration parameters.",
3213 ),
3214 (
3215 "parameter_value",
3216 "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.",
3217 ),
3218 ]),
3219 is_retained_metrics_object: false,
3220 access: vec![PUBLIC_SELECT],
3221});
3222pub static MZ_ROLE_AUTH: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3223 name: "mz_role_auth",
3224 schema: MZ_CATALOG_SCHEMA,
3225 oid: oid::TABLE_MZ_ROLE_AUTH_OID,
3226 desc: RelationDesc::builder()
3227 .with_column("role_id", SqlScalarType::String.nullable(false))
3228 .with_column("role_oid", SqlScalarType::Oid.nullable(false))
3229 .with_column("password_hash", SqlScalarType::String.nullable(true))
3230 .with_column(
3231 "updated_at",
3232 SqlScalarType::TimestampTz { precision: None }.nullable(false),
3233 )
3234 .finish(),
3235 column_comments: BTreeMap::from_iter([
3236 (
3237 "role_id",
3238 "The ID of the role. Corresponds to `mz_roles.id`.",
3239 ),
3240 ("role_oid", "A PostgreSQL-compatible OID for the role."),
3241 (
3242 "password_hash",
3243 "The hashed password for the role, if any. Uses the `SCRAM-SHA-256` algorithm.",
3244 ),
3245 (
3246 "updated_at",
3247 "The time at which the password was last updated.",
3248 ),
3249 ]),
3250 is_retained_metrics_object: false,
3251 access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
3252});
3253pub static MZ_PSEUDO_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3254 name: "mz_pseudo_types",
3255 schema: MZ_CATALOG_SCHEMA,
3256 oid: oid::TABLE_MZ_PSEUDO_TYPES_OID,
3257 desc: RelationDesc::builder()
3258 .with_column("id", SqlScalarType::String.nullable(false))
3259 .finish(),
3260 column_comments: BTreeMap::from_iter([("id", "The ID of the type.")]),
3261 is_retained_metrics_object: false,
3262 access: vec![PUBLIC_SELECT],
3263});
3264pub static MZ_FUNCTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| {
3265 BuiltinTable {
3266 name: "mz_functions",
3267 schema: MZ_CATALOG_SCHEMA,
3268 oid: oid::TABLE_MZ_FUNCTIONS_OID,
3269 desc: RelationDesc::builder()
3270 .with_column("id", SqlScalarType::String.nullable(false)) .with_column("oid", SqlScalarType::Oid.nullable(false))
3272 .with_column("schema_id", SqlScalarType::String.nullable(false))
3273 .with_column("name", SqlScalarType::String.nullable(false))
3274 .with_column(
3275 "argument_type_ids",
3276 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
3277 )
3278 .with_column(
3279 "variadic_argument_type_id",
3280 SqlScalarType::String.nullable(true),
3281 )
3282 .with_column("return_type_id", SqlScalarType::String.nullable(true))
3283 .with_column("returns_set", SqlScalarType::Bool.nullable(false))
3284 .with_column("owner_id", SqlScalarType::String.nullable(false))
3285 .finish(),
3286 column_comments: BTreeMap::from_iter([
3287 ("id", "Materialize's unique ID for the function."),
3288 ("oid", "A PostgreSQL-compatible OID for the function."),
3289 (
3290 "schema_id",
3291 "The ID of the schema to which the function belongs. Corresponds to `mz_schemas.id`.",
3292 ),
3293 ("name", "The name of the function."),
3294 (
3295 "argument_type_ids",
3296 "The ID of each argument's type. Each entry refers to `mz_types.id`.",
3297 ),
3298 (
3299 "variadic_argument_type_id",
3300 "The ID of the variadic argument's type, or `NULL` if the function does not have a variadic argument. Refers to `mz_types.id`.",
3301 ),
3302 (
3303 "return_type_id",
3304 "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`].",
3305 ),
3306 (
3307 "returns_set",
3308 "Whether the function returns a set, i.e. the function is a table function.",
3309 ),
3310 (
3311 "owner_id",
3312 "The role ID of the owner of the function. Corresponds to `mz_roles.id`.",
3313 ),
3314 ]),
3315 is_retained_metrics_object: false,
3316 access: vec![PUBLIC_SELECT],
3317 }
3318});
3319pub static MZ_OPERATORS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3320 name: "mz_operators",
3321 schema: MZ_CATALOG_SCHEMA,
3322 oid: oid::TABLE_MZ_OPERATORS_OID,
3323 desc: RelationDesc::builder()
3324 .with_column("oid", SqlScalarType::Oid.nullable(false))
3325 .with_column("name", SqlScalarType::String.nullable(false))
3326 .with_column(
3327 "argument_type_ids",
3328 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
3329 )
3330 .with_column("return_type_id", SqlScalarType::String.nullable(true))
3331 .finish(),
3332 column_comments: BTreeMap::new(),
3333 is_retained_metrics_object: false,
3334 access: vec![PUBLIC_SELECT],
3335});
3336pub static MZ_AGGREGATES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3337 name: "mz_aggregates",
3338 schema: MZ_INTERNAL_SCHEMA,
3339 oid: oid::TABLE_MZ_AGGREGATES_OID,
3340 desc: RelationDesc::builder()
3341 .with_column("oid", SqlScalarType::Oid.nullable(false))
3342 .with_column("agg_kind", SqlScalarType::String.nullable(false))
3343 .with_column("agg_num_direct_args", SqlScalarType::Int16.nullable(false))
3344 .finish(),
3345 column_comments: BTreeMap::new(),
3346 is_retained_metrics_object: false,
3347 access: vec![PUBLIC_SELECT],
3348});
3349
3350pub static MZ_CLUSTERS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3351 name: "mz_clusters",
3352 schema: MZ_CATALOG_SCHEMA,
3353 oid: oid::TABLE_MZ_CLUSTERS_OID,
3354 desc: RelationDesc::builder()
3355 .with_column("id", SqlScalarType::String.nullable(false))
3356 .with_column("name", SqlScalarType::String.nullable(false))
3357 .with_column("owner_id", SqlScalarType::String.nullable(false))
3358 .with_column(
3359 "privileges",
3360 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
3361 )
3362 .with_column("managed", SqlScalarType::Bool.nullable(false))
3363 .with_column("size", SqlScalarType::String.nullable(true))
3364 .with_column("replication_factor", SqlScalarType::UInt32.nullable(true))
3365 .with_column("disk", SqlScalarType::Bool.nullable(true))
3366 .with_column(
3367 "availability_zones",
3368 SqlScalarType::List {
3369 element_type: Box::new(SqlScalarType::String),
3370 custom_id: None,
3371 }
3372 .nullable(true),
3373 )
3374 .with_column(
3375 "introspection_debugging",
3376 SqlScalarType::Bool.nullable(true),
3377 )
3378 .with_column(
3379 "introspection_interval",
3380 SqlScalarType::Interval.nullable(true),
3381 )
3382 .with_key(vec![0])
3383 .finish(),
3384 column_comments: BTreeMap::from_iter([
3385 ("id", "Materialize's unique ID for the cluster."),
3386 ("name", "The name of the cluster."),
3387 (
3388 "owner_id",
3389 "The role ID of the owner of the cluster. Corresponds to `mz_roles.id`.",
3390 ),
3391 ("privileges", "The privileges belonging to the cluster."),
3392 (
3393 "managed",
3394 "Whether the cluster is a managed cluster with automatically managed replicas.",
3395 ),
3396 (
3397 "size",
3398 "If the cluster is managed, the desired size of the cluster's replicas. `NULL` for unmanaged clusters.",
3399 ),
3400 (
3401 "replication_factor",
3402 "If the cluster is managed, the desired number of replicas of the cluster. `NULL` for unmanaged clusters.",
3403 ),
3404 (
3405 "disk",
3406 "**Unstable** If the cluster is managed, `true` if the replicas have the `DISK` option . `NULL` for unmanaged clusters.",
3407 ),
3408 (
3409 "availability_zones",
3410 "**Unstable** If the cluster is managed, the list of availability zones specified in `AVAILABILITY ZONES`. `NULL` for unmanaged clusters.",
3411 ),
3412 (
3413 "introspection_debugging",
3414 "Whether introspection of the gathering of the introspection data is enabled.",
3415 ),
3416 (
3417 "introspection_interval",
3418 "The interval at which to collect introspection data.",
3419 ),
3420 ]),
3421 is_retained_metrics_object: false,
3422 access: vec![PUBLIC_SELECT],
3423});
3424
3425pub static MZ_CLUSTER_WORKLOAD_CLASSES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3426 name: "mz_cluster_workload_classes",
3427 schema: MZ_INTERNAL_SCHEMA,
3428 oid: oid::TABLE_MZ_CLUSTER_WORKLOAD_CLASSES_OID,
3429 desc: RelationDesc::builder()
3430 .with_column("id", SqlScalarType::String.nullable(false))
3431 .with_column("workload_class", SqlScalarType::String.nullable(true))
3432 .with_key(vec![0])
3433 .finish(),
3434 column_comments: BTreeMap::new(),
3435 is_retained_metrics_object: false,
3436 access: vec![PUBLIC_SELECT],
3437});
3438
3439pub const MZ_CLUSTER_WORKLOAD_CLASSES_IND: BuiltinIndex = BuiltinIndex {
3440 name: "mz_cluster_workload_classes_ind",
3441 schema: MZ_INTERNAL_SCHEMA,
3442 oid: oid::INDEX_MZ_CLUSTER_WORKLOAD_CLASSES_IND_OID,
3443 sql: "IN CLUSTER mz_catalog_server
3444ON mz_internal.mz_cluster_workload_classes (id)",
3445 is_retained_metrics_object: false,
3446};
3447
3448pub static MZ_CLUSTER_SCHEDULES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3449 name: "mz_cluster_schedules",
3450 schema: MZ_INTERNAL_SCHEMA,
3451 oid: oid::TABLE_MZ_CLUSTER_SCHEDULES_OID,
3452 desc: RelationDesc::builder()
3453 .with_column("cluster_id", SqlScalarType::String.nullable(false))
3454 .with_column("type", SqlScalarType::String.nullable(false))
3455 .with_column(
3456 "refresh_hydration_time_estimate",
3457 SqlScalarType::Interval.nullable(true),
3458 )
3459 .finish(),
3460 column_comments: BTreeMap::from_iter([
3461 (
3462 "cluster_id",
3463 "The ID of the cluster. Corresponds to `mz_clusters.id`.",
3464 ),
3465 ("type", "`on-refresh`, or `manual`. Default: `manual`"),
3466 (
3467 "refresh_hydration_time_estimate",
3468 "The interval given in the `HYDRATION TIME ESTIMATE` option.",
3469 ),
3470 ]),
3471 is_retained_metrics_object: false,
3472 access: vec![PUBLIC_SELECT],
3473});
3474
3475pub static MZ_SECRETS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3476 name: "mz_secrets",
3477 schema: MZ_CATALOG_SCHEMA,
3478 oid: oid::TABLE_MZ_SECRETS_OID,
3479 desc: RelationDesc::builder()
3480 .with_column("id", SqlScalarType::String.nullable(false))
3481 .with_column("oid", SqlScalarType::Oid.nullable(false))
3482 .with_column("schema_id", SqlScalarType::String.nullable(false))
3483 .with_column("name", SqlScalarType::String.nullable(false))
3484 .with_column("owner_id", SqlScalarType::String.nullable(false))
3485 .with_column(
3486 "privileges",
3487 SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false),
3488 )
3489 .finish(),
3490 column_comments: BTreeMap::from_iter([
3491 ("id", "The unique ID of the secret."),
3492 ("oid", "A PostgreSQL-compatible oid for the secret."),
3493 (
3494 "schema_id",
3495 "The ID of the schema to which the secret belongs. Corresponds to `mz_schemas.id`.",
3496 ),
3497 ("name", "The name of the secret."),
3498 (
3499 "owner_id",
3500 "The role ID of the owner of the secret. Corresponds to `mz_roles.id`.",
3501 ),
3502 ("privileges", "The privileges belonging to the secret."),
3503 ]),
3504 is_retained_metrics_object: false,
3505 access: vec![PUBLIC_SELECT],
3506});
3507
3508pub static MZ_CLUSTER_REPLICAS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3509 name: "mz_cluster_replicas",
3510 schema: MZ_CATALOG_SCHEMA,
3511 oid: oid::TABLE_MZ_CLUSTER_REPLICAS_OID,
3512 desc: RelationDesc::builder()
3513 .with_column("id", SqlScalarType::String.nullable(false))
3514 .with_column("name", SqlScalarType::String.nullable(false))
3515 .with_column("cluster_id", SqlScalarType::String.nullable(false))
3516 .with_column("size", SqlScalarType::String.nullable(true))
3517 .with_column("availability_zone", SqlScalarType::String.nullable(true))
3520 .with_column("owner_id", SqlScalarType::String.nullable(false))
3521 .with_column("disk", SqlScalarType::Bool.nullable(true))
3522 .finish(),
3523 column_comments: BTreeMap::from_iter([
3524 ("id", "Materialize's unique ID for the cluster replica."),
3525 ("name", "The name of the cluster replica."),
3526 (
3527 "cluster_id",
3528 "The ID of the cluster to which the replica belongs. Corresponds to `mz_clusters.id`.",
3529 ),
3530 (
3531 "size",
3532 "The cluster replica's size, selected during creation.",
3533 ),
3534 (
3535 "availability_zone",
3536 "The availability zone in which the cluster is running.",
3537 ),
3538 (
3539 "owner_id",
3540 "The role ID of the owner of the cluster replica. Corresponds to `mz_roles.id`.",
3541 ),
3542 ("disk", "If the replica has a local disk."),
3543 ]),
3544 is_retained_metrics_object: true,
3545 access: vec![PUBLIC_SELECT],
3546});
3547
3548pub static MZ_INTERNAL_CLUSTER_REPLICAS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3549 name: "mz_internal_cluster_replicas",
3550 schema: MZ_INTERNAL_SCHEMA,
3551 oid: oid::TABLE_MZ_INTERNAL_CLUSTER_REPLICAS_OID,
3552 desc: RelationDesc::builder()
3553 .with_column("id", SqlScalarType::String.nullable(false))
3554 .finish(),
3555 column_comments: BTreeMap::from_iter([(
3556 "id",
3557 "The ID of a cluster replica. Corresponds to `mz_cluster_replicas.id`.",
3558 )]),
3559 is_retained_metrics_object: false,
3560 access: vec![PUBLIC_SELECT],
3561});
3562
3563pub static MZ_PENDING_CLUSTER_REPLICAS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3564 name: "mz_pending_cluster_replicas",
3565 schema: MZ_INTERNAL_SCHEMA,
3566 oid: oid::TABLE_MZ_PENDING_CLUSTER_REPLICAS_OID,
3567 desc: RelationDesc::builder()
3568 .with_column("id", SqlScalarType::String.nullable(false))
3569 .finish(),
3570 column_comments: BTreeMap::from_iter([(
3571 "id",
3572 "The ID of a cluster replica. Corresponds to `mz_cluster_replicas.id`.",
3573 )]),
3574 is_retained_metrics_object: false,
3575 access: vec![PUBLIC_SELECT],
3576});
3577
3578pub static MZ_CLUSTER_REPLICA_STATUS_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| {
3579 BuiltinSource {
3580 name: "mz_cluster_replica_status_history",
3581 schema: MZ_INTERNAL_SCHEMA,
3582 oid: oid::SOURCE_MZ_CLUSTER_REPLICA_STATUS_HISTORY_OID,
3583 data_source: IntrospectionType::ReplicaStatusHistory.into(),
3584 desc: REPLICA_STATUS_HISTORY_DESC.clone(),
3585 column_comments: BTreeMap::from_iter([
3586 ("replica_id", "The ID of a cluster replica."),
3587 ("process_id", "The ID of a process within the replica."),
3588 (
3589 "status",
3590 "The status of the cluster replica: `online` or `offline`.",
3591 ),
3592 (
3593 "reason",
3594 "If the cluster replica is in an `offline` state, the reason (if available). For example, `oom-killed`.",
3595 ),
3596 (
3597 "occurred_at",
3598 "Wall-clock timestamp at which the event occurred.",
3599 ),
3600 ]),
3601 is_retained_metrics_object: false,
3602 access: vec![PUBLIC_SELECT],
3603 }
3604});
3605
3606pub static MZ_CLUSTER_REPLICA_STATUS_HISTORY_CT: LazyLock<BuiltinContinualTask> = LazyLock::new(
3607 || {
3608 BuiltinContinualTask {
3609 name: "mz_cluster_replica_status_history_ct",
3610 schema: MZ_INTERNAL_SCHEMA,
3611 oid: oid::CT_MZ_CLUSTER_REPLICA_STATUS_HISTORY_OID,
3612 desc: REPLICA_STATUS_HISTORY_DESC.clone(),
3613 sql: "
3614IN CLUSTER mz_catalog_server
3615ON INPUT mz_internal.mz_cluster_replica_status_history AS (
3616 DELETE FROM mz_internal.mz_cluster_replica_status_history_ct WHERE occurred_at + '30d' < mz_now();
3617 INSERT INTO mz_internal.mz_cluster_replica_status_history_ct SELECT * FROM mz_internal.mz_cluster_replica_status_history;
3618)",
3619 access: vec![PUBLIC_SELECT],
3620 }
3621 },
3622);
3623
3624pub static MZ_CLUSTER_REPLICA_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
3625 name: "mz_cluster_replica_statuses",
3626 schema: MZ_INTERNAL_SCHEMA,
3627 oid: oid::VIEW_MZ_CLUSTER_REPLICA_STATUSES_OID,
3628 desc: RelationDesc::builder()
3629 .with_column("replica_id", SqlScalarType::String.nullable(false))
3630 .with_column("process_id", SqlScalarType::UInt64.nullable(false))
3631 .with_column("status", SqlScalarType::String.nullable(false))
3632 .with_column("reason", SqlScalarType::String.nullable(true))
3633 .with_column(
3634 "updated_at",
3635 SqlScalarType::TimestampTz { precision: None }.nullable(false),
3636 )
3637 .with_key(vec![0, 1])
3638 .finish(),
3639 column_comments: BTreeMap::from_iter([
3640 (
3641 "replica_id",
3642 "Materialize's unique ID for the cluster replica.",
3643 ),
3644 (
3645 "process_id",
3646 "The ID of the process within the cluster replica.",
3647 ),
3648 (
3649 "status",
3650 "The status of the cluster replica: `online` or `offline`.",
3651 ),
3652 (
3653 "reason",
3654 "If the cluster replica is in a `offline` state, the reason (if available). For example, `oom-killed`.",
3655 ),
3656 (
3657 "updated_at",
3658 "The time at which the status was last updated.",
3659 ),
3660 ]),
3661 sql: "
3662SELECT
3663 DISTINCT ON (replica_id, process_id)
3664 replica_id,
3665 process_id,
3666 status,
3667 reason,
3668 occurred_at as updated_at
3669FROM mz_internal.mz_cluster_replica_status_history
3670JOIN mz_cluster_replicas r ON r.id = replica_id
3671ORDER BY replica_id, process_id, occurred_at DESC",
3672 access: vec![PUBLIC_SELECT],
3673});
3674
3675pub static MZ_CLUSTER_REPLICA_SIZES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3676 name: "mz_cluster_replica_sizes",
3677 schema: MZ_CATALOG_SCHEMA,
3678 oid: oid::TABLE_MZ_CLUSTER_REPLICA_SIZES_OID,
3679 desc: RelationDesc::builder()
3680 .with_column("size", SqlScalarType::String.nullable(false))
3681 .with_column("processes", SqlScalarType::UInt64.nullable(false))
3682 .with_column("workers", SqlScalarType::UInt64.nullable(false))
3683 .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(false))
3684 .with_column("memory_bytes", SqlScalarType::UInt64.nullable(false))
3685 .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
3686 .with_column(
3687 "credits_per_hour",
3688 SqlScalarType::Numeric { max_scale: None }.nullable(false),
3689 )
3690 .finish(),
3691 column_comments: BTreeMap::from_iter([
3692 ("size", "The human-readable replica size."),
3693 ("processes", "The number of processes in the replica."),
3694 (
3695 "workers",
3696 "The number of Timely Dataflow workers per process.",
3697 ),
3698 (
3699 "cpu_nano_cores",
3700 "The CPU allocation per process, in billionths of a vCPU core.",
3701 ),
3702 (
3703 "memory_bytes",
3704 "The RAM allocation per process, in billionths of a vCPU core.",
3705 ),
3706 ("disk_bytes", "The disk allocation per process."),
3707 (
3708 "credits_per_hour",
3709 "The number of compute credits consumed per hour.",
3710 ),
3711 ]),
3712 is_retained_metrics_object: true,
3713 access: vec![PUBLIC_SELECT],
3714});
3715
3716pub static MZ_AUDIT_EVENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
3717 name: "mz_audit_events",
3718 schema: MZ_CATALOG_SCHEMA,
3719 oid: oid::TABLE_MZ_AUDIT_EVENTS_OID,
3720 desc: RelationDesc::builder()
3721 .with_column("id", SqlScalarType::UInt64.nullable(false))
3722 .with_column("event_type", SqlScalarType::String.nullable(false))
3723 .with_column("object_type", SqlScalarType::String.nullable(false))
3724 .with_column("details", SqlScalarType::Jsonb.nullable(false))
3725 .with_column("user", SqlScalarType::String.nullable(true))
3726 .with_column(
3727 "occurred_at",
3728 SqlScalarType::TimestampTz { precision: None }.nullable(false),
3729 )
3730 .with_key(vec![0])
3731 .finish(),
3732 column_comments: BTreeMap::from_iter([
3733 (
3734 "id",
3735 "Materialize's unique, monotonically increasing ID for the event.",
3736 ),
3737 (
3738 "event_type",
3739 "The type of the event: `create`, `drop`, or `alter`.",
3740 ),
3741 (
3742 "object_type",
3743 "The type of the affected object: `cluster`, `cluster-replica`, `connection`, `database`, `function`, `index`, `materialized-view`, `role`, `schema`, `secret`, `sink`, `source`, `table`, `type`, or `view`.",
3744 ),
3745 (
3746 "details",
3747 "Additional details about the event. The shape of the details varies based on `event_type` and `object_type`.",
3748 ),
3749 (
3750 "user",
3751 "The user who triggered the event, or `NULL` if triggered by the system.",
3752 ),
3753 (
3754 "occurred_at",
3755 "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.",
3756 ),
3757 ]),
3758 is_retained_metrics_object: false,
3759 access: vec![PUBLIC_SELECT],
3760});
3761
3762pub static MZ_SOURCE_STATUS_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
3763 name: "mz_source_status_history",
3764 schema: MZ_INTERNAL_SCHEMA,
3765 oid: oid::SOURCE_MZ_SOURCE_STATUS_HISTORY_OID,
3766 data_source: IntrospectionType::SourceStatusHistory.into(),
3767 desc: MZ_SOURCE_STATUS_HISTORY_DESC.clone(),
3768 column_comments: BTreeMap::from_iter([
3769 (
3770 "occurred_at",
3771 "Wall-clock timestamp of the source status change.",
3772 ),
3773 (
3774 "source_id",
3775 "The ID of the source. Corresponds to `mz_catalog.mz_sources.id`.",
3776 ),
3777 (
3778 "status",
3779 "The status of the source: one of `created`, `starting`, `running`, `paused`, `stalled`, `failed`, or `dropped`.",
3780 ),
3781 (
3782 "error",
3783 "If the source is in an error state, the error message.",
3784 ),
3785 (
3786 "details",
3787 "Additional metadata provided by the source. In case of error, may contain a `hint` field with helpful suggestions.",
3788 ),
3789 (
3790 "replica_id",
3791 "The ID of the replica that an instance of a source is running on.",
3792 ),
3793 ]),
3794 is_retained_metrics_object: false,
3795 access: vec![PUBLIC_SELECT],
3796});
3797
3798pub static MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(
3799 || BuiltinSource {
3800 name: "mz_aws_privatelink_connection_status_history",
3801 schema: MZ_INTERNAL_SCHEMA,
3802 oid: oid::SOURCE_MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_OID,
3803 data_source: DataSourceDesc::Introspection(
3804 IntrospectionType::PrivatelinkConnectionStatusHistory,
3805 ),
3806 desc: MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_DESC.clone(),
3807 column_comments: BTreeMap::from_iter([
3808 ("occurred_at", "Wall-clock timestamp of the status change."),
3809 (
3810 "connection_id",
3811 "The unique identifier of the AWS PrivateLink connection. Corresponds to `mz_catalog.mz_connections.id`.",
3812 ),
3813 (
3814 "status",
3815 "The status of the connection: one of `pending-service-discovery`, `creating-endpoint`, `recreating-endpoint`, `updating-endpoint`, `available`, `deleted`, `deleting`, `expired`, `failed`, `pending`, `pending-acceptance`, `rejected`, or `unknown`.",
3816 ),
3817 ]),
3818 is_retained_metrics_object: false,
3819 access: vec![PUBLIC_SELECT],
3820 },
3821);
3822
3823pub static MZ_AWS_PRIVATELINK_CONNECTION_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| {
3824 BuiltinView {
3825 name: "mz_aws_privatelink_connection_statuses",
3826 schema: MZ_INTERNAL_SCHEMA,
3827 oid: oid::VIEW_MZ_AWS_PRIVATELINK_CONNECTION_STATUSES_OID,
3828 desc: RelationDesc::builder()
3829 .with_column("id", SqlScalarType::String.nullable(false))
3830 .with_column("name", SqlScalarType::String.nullable(false))
3831 .with_column(
3832 "last_status_change_at",
3833 SqlScalarType::TimestampTz { precision: None }.nullable(true),
3834 )
3835 .with_column("status", SqlScalarType::String.nullable(true))
3836 .with_key(vec![0])
3837 .finish(),
3838 column_comments: BTreeMap::from_iter([
3839 (
3840 "id",
3841 "The ID of the connection. Corresponds to `mz_catalog.mz_connections.id`.",
3842 ),
3843 ("name", "The name of the connection."),
3844 (
3845 "last_status_change_at",
3846 "Wall-clock timestamp of the connection status change.",
3847 ),
3848 (
3849 "status",
3850 "The status of the connection: one of `pending-service-discovery`, `creating-endpoint`, `recreating-endpoint`, `updating-endpoint`, `available`, `deleted`, `deleting`, `expired`, `failed`, `pending`, `pending-acceptance`, `rejected`, or `unknown`.",
3851 ),
3852 ]),
3853 sql: "
3854 WITH statuses_w_last_status AS (
3855 SELECT
3856 connection_id,
3857 occurred_at,
3858 status,
3859 lag(status) OVER (PARTITION BY connection_id ORDER BY occurred_at) AS last_status
3860 FROM mz_internal.mz_aws_privatelink_connection_status_history
3861 ),
3862 latest_events AS (
3863 -- Only take the most recent transition for each ID
3864 SELECT DISTINCT ON(connection_id) connection_id, occurred_at, status
3865 FROM statuses_w_last_status
3866 -- Only keep first status transitions
3867 WHERE status <> last_status OR last_status IS NULL
3868 ORDER BY connection_id, occurred_at DESC
3869 )
3870 SELECT
3871 conns.id,
3872 name,
3873 occurred_at as last_status_change_at,
3874 status
3875 FROM latest_events
3876 JOIN mz_catalog.mz_connections AS conns
3877 ON conns.id = latest_events.connection_id",
3878 access: vec![PUBLIC_SELECT],
3879 }
3880});
3881
3882pub static MZ_STATEMENT_EXECUTION_HISTORY: LazyLock<BuiltinSource> =
3883 LazyLock::new(|| BuiltinSource {
3884 name: "mz_statement_execution_history",
3885 schema: MZ_INTERNAL_SCHEMA,
3886 oid: oid::SOURCE_MZ_STATEMENT_EXECUTION_HISTORY_OID,
3887 data_source: IntrospectionType::StatementExecutionHistory.into(),
3888 desc: MZ_STATEMENT_EXECUTION_HISTORY_DESC.clone(),
3889 column_comments: BTreeMap::new(),
3890 is_retained_metrics_object: false,
3891 access: vec![MONITOR_SELECT],
3892 });
3893
3894pub static MZ_STATEMENT_EXECUTION_HISTORY_REDACTED: LazyLock<BuiltinView> = LazyLock::new(|| {
3895 BuiltinView {
3896 name: "mz_statement_execution_history_redacted",
3897 schema: MZ_INTERNAL_SCHEMA,
3898 oid: oid::VIEW_MZ_STATEMENT_EXECUTION_HISTORY_REDACTED_OID,
3899 desc: RelationDesc::builder()
3901 .with_column("id", SqlScalarType::Uuid.nullable(false))
3902 .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
3903 .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
3904 .with_column("cluster_id", SqlScalarType::String.nullable(true))
3905 .with_column("application_name", SqlScalarType::String.nullable(false))
3906 .with_column("cluster_name", SqlScalarType::String.nullable(true))
3907 .with_column("database_name", SqlScalarType::String.nullable(false))
3908 .with_column("search_path", SqlScalarType::List { element_type: Box::new(SqlScalarType::String), custom_id: None }.nullable(false))
3909 .with_column("transaction_isolation", SqlScalarType::String.nullable(false))
3910 .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
3911 .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
3912 .with_column("transient_index_id", SqlScalarType::String.nullable(true))
3913 .with_column("mz_version", SqlScalarType::String.nullable(false))
3914 .with_column("began_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
3915 .with_column("finished_at", SqlScalarType::TimestampTz { precision: None }.nullable(true))
3916 .with_column("finished_status", SqlScalarType::String.nullable(true))
3917 .with_column("result_size", SqlScalarType::Int64.nullable(true))
3918 .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
3919 .with_column("execution_strategy", SqlScalarType::String.nullable(true))
3920 .finish(),
3921 column_comments: BTreeMap::new(),
3922 sql: "
3923SELECT id, prepared_statement_id, sample_rate, cluster_id, application_name,
3924cluster_name, database_name, search_path, transaction_isolation, execution_timestamp, transaction_id,
3925transient_index_id, mz_version, began_at, finished_at, finished_status,
3926result_size, rows_returned, execution_strategy
3927FROM mz_internal.mz_statement_execution_history",
3928 access: vec![SUPPORT_SELECT, ANALYTICS_SELECT, MONITOR_REDACTED_SELECT, MONITOR_SELECT],
3929}
3930});
3931
3932pub static MZ_PREPARED_STATEMENT_HISTORY: LazyLock<BuiltinSource> =
3933 LazyLock::new(|| BuiltinSource {
3934 name: "mz_prepared_statement_history",
3935 schema: MZ_INTERNAL_SCHEMA,
3936 oid: oid::SOURCE_MZ_PREPARED_STATEMENT_HISTORY_OID,
3937 data_source: IntrospectionType::PreparedStatementHistory.into(),
3938 desc: MZ_PREPARED_STATEMENT_HISTORY_DESC.clone(),
3939 column_comments: BTreeMap::new(),
3940 is_retained_metrics_object: false,
3941 access: vec![
3942 SUPPORT_SELECT,
3943 ANALYTICS_SELECT,
3944 MONITOR_REDACTED_SELECT,
3945 MONITOR_SELECT,
3946 ],
3947 });
3948
3949pub static MZ_SQL_TEXT: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
3950 name: "mz_sql_text",
3951 schema: MZ_INTERNAL_SCHEMA,
3952 oid: oid::SOURCE_MZ_SQL_TEXT_OID,
3953 desc: MZ_SQL_TEXT_DESC.clone(),
3954 data_source: IntrospectionType::SqlText.into(),
3955 column_comments: BTreeMap::new(),
3956 is_retained_metrics_object: false,
3957 access: vec![MONITOR_SELECT],
3958});
3959
3960pub static MZ_SQL_TEXT_REDACTED: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
3961 name: "mz_sql_text_redacted",
3962 schema: MZ_INTERNAL_SCHEMA,
3963 oid: oid::VIEW_MZ_SQL_TEXT_REDACTED_OID,
3964 desc: RelationDesc::builder()
3965 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
3966 .with_column("redacted_sql", SqlScalarType::String.nullable(false))
3967 .finish(),
3968 column_comments: BTreeMap::new(),
3969 sql: "SELECT sql_hash, redacted_sql FROM mz_internal.mz_sql_text",
3970 access: vec![
3971 MONITOR_SELECT,
3972 MONITOR_REDACTED_SELECT,
3973 SUPPORT_SELECT,
3974 ANALYTICS_SELECT,
3975 ],
3976});
3977
3978pub static MZ_RECENT_SQL_TEXT: LazyLock<BuiltinView> = LazyLock::new(|| {
3979 BuiltinView {
3980 name: "mz_recent_sql_text",
3981 schema: MZ_INTERNAL_SCHEMA,
3982 oid: oid::VIEW_MZ_RECENT_SQL_TEXT_OID,
3983 desc: RelationDesc::builder()
3988 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
3989 .with_column("sql", SqlScalarType::String.nullable(false))
3990 .with_column("redacted_sql", SqlScalarType::String.nullable(false))
3991 .with_key(vec![0, 1, 2])
3992 .finish(),
3993 column_comments: BTreeMap::new(),
3994 sql: "SELECT DISTINCT sql_hash, sql, redacted_sql FROM mz_internal.mz_sql_text WHERE prepared_day + INTERVAL '4 days' >= mz_now()",
3995 access: vec![MONITOR_SELECT],
3996 }
3997});
3998
3999pub static MZ_RECENT_SQL_TEXT_REDACTED: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
4000 name: "mz_recent_sql_text_redacted",
4001 schema: MZ_INTERNAL_SCHEMA,
4002 oid: oid::VIEW_MZ_RECENT_SQL_TEXT_REDACTED_OID,
4003 desc: RelationDesc::builder()
4004 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
4005 .with_column("redacted_sql", SqlScalarType::String.nullable(false))
4006 .finish(),
4007 column_comments: BTreeMap::new(),
4008 sql: "SELECT sql_hash, redacted_sql FROM mz_internal.mz_recent_sql_text",
4009 access: vec![
4010 MONITOR_SELECT,
4011 MONITOR_REDACTED_SELECT,
4012 SUPPORT_SELECT,
4013 ANALYTICS_SELECT,
4014 ],
4015});
4016
4017pub static MZ_RECENT_SQL_TEXT_IND: LazyLock<BuiltinIndex> = LazyLock::new(|| BuiltinIndex {
4018 name: "mz_recent_sql_text_ind",
4019 schema: MZ_INTERNAL_SCHEMA,
4020 oid: oid::INDEX_MZ_RECENT_SQL_TEXT_IND_OID,
4021 sql: "IN CLUSTER mz_catalog_server ON mz_internal.mz_recent_sql_text (sql_hash)",
4022 is_retained_metrics_object: false,
4023});
4024
4025pub static MZ_SESSION_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
4026 name: "mz_session_history",
4027 schema: MZ_INTERNAL_SCHEMA,
4028 oid: oid::SOURCE_MZ_SESSION_HISTORY_OID,
4029 data_source: IntrospectionType::SessionHistory.into(),
4030 desc: MZ_SESSION_HISTORY_DESC.clone(),
4031 column_comments: BTreeMap::from_iter([
4032 (
4033 "session_id",
4034 "The globally unique ID of the session. Corresponds to `mz_sessions.id`.",
4035 ),
4036 (
4037 "connected_at",
4038 "The time at which the session was established.",
4039 ),
4040 (
4041 "initial_application_name",
4042 "The `application_name` session metadata field.",
4043 ),
4044 (
4045 "authenticated_user",
4046 "The name of the user for which the session was established.",
4047 ),
4048 ]),
4049 is_retained_metrics_object: false,
4050 access: vec![PUBLIC_SELECT],
4051});
4052
4053pub static MZ_ACTIVITY_LOG_THINNED: LazyLock<BuiltinView> = LazyLock::new(|| {
4054 BuiltinView {
4055 name: "mz_activity_log_thinned",
4056 schema: MZ_INTERNAL_SCHEMA,
4057 oid: oid::VIEW_MZ_ACTIVITY_LOG_THINNED_OID,
4058 desc: RelationDesc::builder()
4059 .with_column("execution_id", SqlScalarType::Uuid.nullable(false))
4060 .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
4061 .with_column("cluster_id", SqlScalarType::String.nullable(true))
4062 .with_column("application_name", SqlScalarType::String.nullable(false))
4063 .with_column("cluster_name", SqlScalarType::String.nullable(true))
4064 .with_column("database_name", SqlScalarType::String.nullable(false))
4065 .with_column("search_path", SqlScalarType::List { element_type: Box::new(SqlScalarType::String), custom_id: None }.nullable(false))
4066 .with_column("transaction_isolation", SqlScalarType::String.nullable(false))
4067 .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
4068 .with_column("transient_index_id", SqlScalarType::String.nullable(true))
4069 .with_column("params", SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false))
4070 .with_column("mz_version", SqlScalarType::String.nullable(false))
4071 .with_column("began_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4072 .with_column("finished_at", SqlScalarType::TimestampTz { precision: None }.nullable(true))
4073 .with_column("finished_status", SqlScalarType::String.nullable(true))
4074 .with_column("error_message", SqlScalarType::String.nullable(true))
4075 .with_column("result_size", SqlScalarType::Int64.nullable(true))
4076 .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
4077 .with_column("execution_strategy", SqlScalarType::String.nullable(true))
4078 .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
4079 .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
4080 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
4081 .with_column("prepared_statement_name", SqlScalarType::String.nullable(false))
4082 .with_column("session_id", SqlScalarType::Uuid.nullable(false))
4083 .with_column("prepared_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4084 .with_column("statement_type", SqlScalarType::String.nullable(true))
4085 .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
4086 .with_column("connected_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4087 .with_column("initial_application_name", SqlScalarType::String.nullable(false))
4088 .with_column("authenticated_user", SqlScalarType::String.nullable(false))
4089 .finish(),
4090 column_comments: BTreeMap::new(),
4091 sql: "
4092SELECT mseh.id AS execution_id, sample_rate, cluster_id, application_name, cluster_name, database_name, search_path,
4093transaction_isolation, execution_timestamp, transient_index_id, params, mz_version, began_at, finished_at, finished_status,
4094error_message, result_size, rows_returned, execution_strategy, transaction_id,
4095mpsh.id AS prepared_statement_id, sql_hash, mpsh.name AS prepared_statement_name,
4096mpsh.session_id, prepared_at, statement_type, throttled_count,
4097connected_at, initial_application_name, authenticated_user
4098FROM mz_internal.mz_statement_execution_history mseh,
4099 mz_internal.mz_prepared_statement_history mpsh,
4100 mz_internal.mz_session_history msh
4101WHERE mseh.prepared_statement_id = mpsh.id
4102AND mpsh.session_id = msh.session_id",
4103 access: vec![MONITOR_SELECT],
4104 }
4105});
4106
4107pub static MZ_RECENT_ACTIVITY_LOG_THINNED: LazyLock<BuiltinView> = LazyLock::new(|| {
4108 BuiltinView {
4109 name: "mz_recent_activity_log_thinned",
4110 schema: MZ_INTERNAL_SCHEMA,
4111 oid: oid::VIEW_MZ_RECENT_ACTIVITY_LOG_THINNED_OID,
4112 desc: RelationDesc::builder()
4113 .with_column("execution_id", SqlScalarType::Uuid.nullable(false))
4114 .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
4115 .with_column("cluster_id", SqlScalarType::String.nullable(true))
4116 .with_column("application_name", SqlScalarType::String.nullable(false))
4117 .with_column("cluster_name", SqlScalarType::String.nullable(true))
4118 .with_column("database_name", SqlScalarType::String.nullable(false))
4119 .with_column("search_path", SqlScalarType::List { element_type: Box::new(SqlScalarType::String), custom_id: None }.nullable(false))
4120 .with_column("transaction_isolation", SqlScalarType::String.nullable(false))
4121 .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
4122 .with_column("transient_index_id", SqlScalarType::String.nullable(true))
4123 .with_column("params", SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false))
4124 .with_column("mz_version", SqlScalarType::String.nullable(false))
4125 .with_column("began_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4126 .with_column("finished_at", SqlScalarType::TimestampTz { precision: None }.nullable(true))
4127 .with_column("finished_status", SqlScalarType::String.nullable(true))
4128 .with_column("error_message", SqlScalarType::String.nullable(true))
4129 .with_column("result_size", SqlScalarType::Int64.nullable(true))
4130 .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
4131 .with_column("execution_strategy", SqlScalarType::String.nullable(true))
4132 .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
4133 .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
4134 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
4135 .with_column("prepared_statement_name", SqlScalarType::String.nullable(false))
4136 .with_column("session_id", SqlScalarType::Uuid.nullable(false))
4137 .with_column("prepared_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4138 .with_column("statement_type", SqlScalarType::String.nullable(true))
4139 .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
4140 .with_column("connected_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4141 .with_column("initial_application_name", SqlScalarType::String.nullable(false))
4142 .with_column("authenticated_user", SqlScalarType::String.nullable(false))
4143 .finish(),
4144 column_comments: BTreeMap::new(),
4145 sql:
4148 "SELECT * FROM mz_internal.mz_activity_log_thinned WHERE prepared_at + INTERVAL '1 day' > mz_now()
4149AND began_at + INTERVAL '1 day' > mz_now() AND connected_at + INTERVAL '2 days' > mz_now()",
4150 access: vec![MONITOR_SELECT],
4151 }
4152});
4153
4154pub static MZ_RECENT_ACTIVITY_LOG: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
4155 name: "mz_recent_activity_log",
4156 schema: MZ_INTERNAL_SCHEMA,
4157 oid: oid::VIEW_MZ_RECENT_ACTIVITY_LOG_OID,
4158 desc: RelationDesc::builder()
4159 .with_column("execution_id", SqlScalarType::Uuid.nullable(false))
4160 .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
4161 .with_column("cluster_id", SqlScalarType::String.nullable(true))
4162 .with_column("application_name", SqlScalarType::String.nullable(false))
4163 .with_column("cluster_name", SqlScalarType::String.nullable(true))
4164 .with_column("database_name", SqlScalarType::String.nullable(false))
4165 .with_column(
4166 "search_path",
4167 SqlScalarType::List {
4168 element_type: Box::new(SqlScalarType::String),
4169 custom_id: None,
4170 }
4171 .nullable(false),
4172 )
4173 .with_column(
4174 "transaction_isolation",
4175 SqlScalarType::String.nullable(false),
4176 )
4177 .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
4178 .with_column("transient_index_id", SqlScalarType::String.nullable(true))
4179 .with_column(
4180 "params",
4181 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
4182 )
4183 .with_column("mz_version", SqlScalarType::String.nullable(false))
4184 .with_column(
4185 "began_at",
4186 SqlScalarType::TimestampTz { precision: None }.nullable(false),
4187 )
4188 .with_column(
4189 "finished_at",
4190 SqlScalarType::TimestampTz { precision: None }.nullable(true),
4191 )
4192 .with_column("finished_status", SqlScalarType::String.nullable(true))
4193 .with_column("error_message", SqlScalarType::String.nullable(true))
4194 .with_column("result_size", SqlScalarType::Int64.nullable(true))
4195 .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
4196 .with_column("execution_strategy", SqlScalarType::String.nullable(true))
4197 .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
4198 .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
4199 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
4200 .with_column(
4201 "prepared_statement_name",
4202 SqlScalarType::String.nullable(false),
4203 )
4204 .with_column("session_id", SqlScalarType::Uuid.nullable(false))
4205 .with_column(
4206 "prepared_at",
4207 SqlScalarType::TimestampTz { precision: None }.nullable(false),
4208 )
4209 .with_column("statement_type", SqlScalarType::String.nullable(true))
4210 .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
4211 .with_column(
4212 "connected_at",
4213 SqlScalarType::TimestampTz { precision: None }.nullable(false),
4214 )
4215 .with_column(
4216 "initial_application_name",
4217 SqlScalarType::String.nullable(false),
4218 )
4219 .with_column("authenticated_user", SqlScalarType::String.nullable(false))
4220 .with_column("sql", SqlScalarType::String.nullable(false))
4221 .finish(),
4222 column_comments: BTreeMap::from_iter([
4223 (
4224 "execution_id",
4225 "An ID that is unique for each executed statement.",
4226 ),
4227 (
4228 "sample_rate",
4229 "The actual rate at which the statement was sampled.",
4230 ),
4231 (
4232 "cluster_id",
4233 "The ID of the cluster the statement execution was directed to. Corresponds to mz_clusters.id.",
4234 ),
4235 (
4236 "application_name",
4237 "The value of the `application_name` configuration parameter at execution time.",
4238 ),
4239 (
4240 "cluster_name",
4241 "The name of the cluster with ID `cluster_id` at execution time.",
4242 ),
4243 (
4244 "database_name",
4245 "The value of the `database` configuration parameter at execution time.",
4246 ),
4247 (
4248 "search_path",
4249 "The value of the `search_path` configuration parameter at execution time.",
4250 ),
4251 (
4252 "transaction_isolation",
4253 "The value of the `transaction_isolation` configuration parameter at execution time.",
4254 ),
4255 (
4256 "execution_timestamp",
4257 "The logical timestamp at which execution was scheduled.",
4258 ),
4259 (
4260 "transient_index_id",
4261 "The internal index of the compute dataflow created for the query, if any.",
4262 ),
4263 (
4264 "params",
4265 "The parameters with which the statement was executed.",
4266 ),
4267 (
4268 "mz_version",
4269 "The version of Materialize that was running when the statement was executed.",
4270 ),
4271 (
4272 "began_at",
4273 "The wall-clock time at which the statement began executing.",
4274 ),
4275 (
4276 "finished_at",
4277 "The wall-clock time at which the statement finished executing.",
4278 ),
4279 (
4280 "finished_status",
4281 "The final status of the statement (e.g., `success`, `canceled`, `error`, or `aborted`). `aborted` means that Materialize exited before the statement finished executing.",
4282 ),
4283 (
4284 "error_message",
4285 "The error message, if the statement failed.",
4286 ),
4287 (
4288 "result_size",
4289 "The size in bytes of the result, for statements that return rows.",
4290 ),
4291 (
4292 "rows_returned",
4293 "The number of rows returned, for statements that return rows.",
4294 ),
4295 (
4296 "execution_strategy",
4297 "For `SELECT` queries, the strategy for executing the query. `constant` means computed in the control plane without the involvement of a cluster, `fast-path` means read by a cluster directly from an in-memory index, and `standard` means computed by a temporary dataflow.",
4298 ),
4299 (
4300 "transaction_id",
4301 "The ID of the transaction that the statement was part of. Note that transaction IDs are only unique per session.",
4302 ),
4303 (
4304 "prepared_statement_id",
4305 "An ID that is unique for each prepared statement. For example, if a statement is prepared once and then executed multiple times, all executions will have the same value for this column (but different values for `execution_id`).",
4306 ),
4307 (
4308 "sql_hash",
4309 "An opaque value uniquely identifying the text of the query.",
4310 ),
4311 (
4312 "prepared_statement_name",
4313 "The name given by the client library to the prepared statement.",
4314 ),
4315 (
4316 "session_id",
4317 "An ID that is unique for each session. Corresponds to mz_sessions.id.",
4318 ),
4319 (
4320 "prepared_at",
4321 "The time at which the statement was prepared.",
4322 ),
4323 (
4324 "statement_type",
4325 "The _type_ of the statement, e.g. `select` for a `SELECT` query, or `NULL` if the statement was empty.",
4326 ),
4327 (
4328 "throttled_count",
4329 "The number of statement executions that were dropped due to throttling before the current one was seen. If you have a very high volume of queries and need to log them without throttling, contact our team.",
4330 ),
4331 (
4332 "connected_at",
4333 "The time at which the session was established.",
4334 ),
4335 (
4336 "initial_application_name",
4337 "The initial value of `application_name` at the beginning of the session.",
4338 ),
4339 (
4340 "authenticated_user",
4341 "The name of the user for which the session was established.",
4342 ),
4343 ("sql", "The SQL text of the statement."),
4344 ]),
4345 sql: "SELECT mralt.*, mrst.sql
4346FROM mz_internal.mz_recent_activity_log_thinned mralt,
4347 mz_internal.mz_recent_sql_text mrst
4348WHERE mralt.sql_hash = mrst.sql_hash",
4349 access: vec![MONITOR_SELECT],
4350});
4351
4352pub static MZ_RECENT_ACTIVITY_LOG_REDACTED: LazyLock<BuiltinView> = LazyLock::new(|| {
4353 BuiltinView {
4354 name: "mz_recent_activity_log_redacted",
4355 schema: MZ_INTERNAL_SCHEMA,
4356 oid: oid::VIEW_MZ_RECENT_ACTIVITY_LOG_REDACTED_OID,
4357 desc: RelationDesc::builder()
4359 .with_column("execution_id", SqlScalarType::Uuid.nullable(false))
4360 .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
4361 .with_column("cluster_id", SqlScalarType::String.nullable(true))
4362 .with_column("application_name", SqlScalarType::String.nullable(false))
4363 .with_column("cluster_name", SqlScalarType::String.nullable(true))
4364 .with_column("database_name", SqlScalarType::String.nullable(false))
4365 .with_column("search_path", SqlScalarType::List { element_type: Box::new(SqlScalarType::String), custom_id: None }.nullable(false))
4366 .with_column("transaction_isolation", SqlScalarType::String.nullable(false))
4367 .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
4368 .with_column("transient_index_id", SqlScalarType::String.nullable(true))
4369 .with_column("mz_version", SqlScalarType::String.nullable(false))
4370 .with_column("began_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4371 .with_column("finished_at", SqlScalarType::TimestampTz { precision: None }.nullable(true))
4372 .with_column("finished_status", SqlScalarType::String.nullable(true))
4373 .with_column("result_size", SqlScalarType::Int64.nullable(true))
4374 .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
4375 .with_column("execution_strategy", SqlScalarType::String.nullable(true))
4376 .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
4377 .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
4378 .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
4379 .with_column("prepared_statement_name", SqlScalarType::String.nullable(false))
4380 .with_column("session_id", SqlScalarType::Uuid.nullable(false))
4381 .with_column("prepared_at", SqlScalarType::TimestampTz { precision: None }.nullable(false))
4382 .with_column("statement_type", SqlScalarType::String.nullable(true))
4383 .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
4384 .with_column("initial_application_name", SqlScalarType::String.nullable(false))
4385 .with_column("authenticated_user", SqlScalarType::String.nullable(false))
4386 .with_column("redacted_sql", SqlScalarType::String.nullable(false))
4387 .finish(),
4388 column_comments: BTreeMap::new(),
4389 sql: "SELECT mralt.execution_id, mralt.sample_rate, mralt.cluster_id, mralt.application_name,
4390 mralt.cluster_name, mralt.database_name, mralt.search_path, mralt.transaction_isolation, mralt.execution_timestamp,
4391 mralt.transient_index_id, mralt.mz_version, mralt.began_at, mralt.finished_at,
4392 mralt.finished_status, mralt.result_size, mralt.rows_returned, mralt.execution_strategy, mralt.transaction_id,
4393 mralt.prepared_statement_id, mralt.sql_hash, mralt.prepared_statement_name, mralt.session_id,
4394 mralt.prepared_at, mralt.statement_type, mralt.throttled_count,
4395 mralt.initial_application_name, mralt.authenticated_user,
4396 mrst.redacted_sql
4397FROM mz_internal.mz_recent_activity_log_thinned mralt,
4398 mz_internal.mz_recent_sql_text mrst
4399WHERE mralt.sql_hash = mrst.sql_hash",
4400 access: vec![MONITOR_SELECT, MONITOR_REDACTED_SELECT, SUPPORT_SELECT, ANALYTICS_SELECT],
4401}
4402});
4403
4404pub static MZ_STATEMENT_LIFECYCLE_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| {
4405 BuiltinSource {
4406 name: "mz_statement_lifecycle_history",
4407 schema: MZ_INTERNAL_SCHEMA,
4408 oid: oid::SOURCE_MZ_STATEMENT_LIFECYCLE_HISTORY_OID,
4409 desc: RelationDesc::builder()
4410 .with_column("statement_id", SqlScalarType::Uuid.nullable(false))
4411 .with_column("event_type", SqlScalarType::String.nullable(false))
4412 .with_column(
4413 "occurred_at",
4414 SqlScalarType::TimestampTz { precision: None }.nullable(false),
4415 )
4416 .finish(),
4417 data_source: IntrospectionType::StatementLifecycleHistory.into(),
4418 column_comments: BTreeMap::from_iter([
4419 (
4420 "statement_id",
4421 "The ID of the execution event. Corresponds to `mz_recent_activity_log.execution_id`",
4422 ),
4423 (
4424 "event_type",
4425 "The type of lifecycle event, e.g. `'execution-began'`, `'storage-dependencies-finished'`, `'compute-dependencies-finished'`, or `'execution-finished'`",
4426 ),
4427 ("occurred_at", "The time at which the event took place."),
4428 ]),
4429 is_retained_metrics_object: false,
4430 access: vec![
4434 SUPPORT_SELECT,
4435 ANALYTICS_SELECT,
4436 MONITOR_REDACTED_SELECT,
4437 MONITOR_SELECT,
4438 ],
4439 }
4440});
4441
4442pub static MZ_SOURCE_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
4443 name: "mz_source_statuses",
4444 schema: MZ_INTERNAL_SCHEMA,
4445 oid: oid::VIEW_MZ_SOURCE_STATUSES_OID,
4446 desc: RelationDesc::builder()
4447 .with_column("id", SqlScalarType::String.nullable(false))
4448 .with_column("name", SqlScalarType::String.nullable(false))
4449 .with_column("type", SqlScalarType::String.nullable(false))
4450 .with_column(
4451 "last_status_change_at",
4452 SqlScalarType::TimestampTz { precision: None }.nullable(true),
4453 )
4454 .with_column("status", SqlScalarType::String.nullable(false))
4455 .with_column("error", SqlScalarType::String.nullable(true))
4456 .with_column("details", SqlScalarType::Jsonb.nullable(true))
4457 .finish(),
4458 column_comments: BTreeMap::from_iter([
4459 (
4460 "id",
4461 "The ID of the source. Corresponds to `mz_catalog.mz_sources.id`.",
4462 ),
4463 ("name", "The name of the source."),
4464 ("type", "The type of the source."),
4465 (
4466 "last_status_change_at",
4467 "Wall-clock timestamp of the source status change.",
4468 ),
4469 (
4470 "status",
4471 "The status of the source: one of `created`, `starting`, `running`, `paused`, `stalled`, `failed`, or `dropped`.",
4472 ),
4473 (
4474 "error",
4475 "If the source is in an error state, the error message.",
4476 ),
4477 (
4478 "details",
4479 "Additional metadata provided by the source. In case of error, may contain a `hint` field with helpful suggestions.",
4480 ),
4481 ]),
4482 sql: "
4483 WITH
4484 -- The status history contains per-replica events and source-global events.
4485 -- For the latter, replica_id is NULL. We turn these into '<source>', so that
4486 -- we can treat them uniformly below.
4487 uniform_status_history AS
4488 (
4489 SELECT
4490 s.source_id,
4491 COALESCE(s.replica_id, '<source>') as replica_id,
4492 s.occurred_at,
4493 s.status,
4494 s.error,
4495 s.details
4496 FROM mz_internal.mz_source_status_history s
4497 ),
4498 -- For getting the latest events, we first determine the latest per-replica
4499 -- events here and then apply precedence rules below.
4500 latest_per_replica_events AS
4501 (
4502 SELECT DISTINCT ON (source_id, replica_id)
4503 occurred_at, source_id, replica_id, status, error, details
4504 FROM uniform_status_history
4505 ORDER BY source_id, replica_id, occurred_at DESC
4506 ),
4507 -- We have a precedence list that determines the overall status in case
4508 -- there is differing per-replica (including source-global) statuses. If
4509 -- there is no 'dropped' status, and any replica reports 'running', the
4510 -- overall status is 'running' even if there might be some replica that has
4511 -- errors or is paused.
4512 latest_events AS
4513 (
4514 SELECT DISTINCT ON (source_id)
4515 source_id,
4516 occurred_at,
4517 status,
4518 error,
4519 details
4520 FROM latest_per_replica_events
4521 ORDER BY source_id, CASE status
4522 WHEN 'dropped' THEN 1
4523 WHEN 'running' THEN 2
4524 WHEN 'stalled' THEN 3
4525 WHEN 'starting' THEN 4
4526 WHEN 'paused' THEN 5
4527 WHEN 'ceased' THEN 6
4528 ELSE 7 -- For any other status values
4529 END
4530 ),
4531 -- Determine which sources are subsources and which are parent sources
4532 subsources AS
4533 (
4534 SELECT subsources.id AS self, sources.id AS parent
4535 FROM
4536 mz_catalog.mz_sources AS subsources
4537 JOIN
4538 mz_internal.mz_object_dependencies AS deps
4539 ON subsources.id = deps.object_id
4540 JOIN mz_catalog.mz_sources AS sources ON sources.id = deps.referenced_object_id
4541 ),
4542 -- Determine which sources are source tables
4543 tables AS
4544 (
4545 SELECT tables.id AS self, tables.source_id AS parent, tables.name
4546 FROM mz_catalog.mz_tables AS tables
4547 WHERE tables.source_id IS NOT NULL
4548 ),
4549 -- Determine which collection's ID to use for the status
4550 id_of_status_to_use AS
4551 (
4552 SELECT
4553 self_events.source_id,
4554 -- If self not errored, but parent is, use parent; else self
4555 CASE
4556 WHEN
4557 self_events.status <> 'ceased' AND
4558 parent_events.status = 'stalled'
4559 THEN parent_events.source_id
4560 ELSE self_events.source_id
4561 END AS id_to_use
4562 FROM
4563 latest_events AS self_events
4564 LEFT JOIN subsources ON self_events.source_id = subsources.self
4565 LEFT JOIN tables ON self_events.source_id = tables.self
4566 LEFT JOIN
4567 latest_events AS parent_events
4568 ON parent_events.source_id = COALESCE(subsources.parent, tables.parent)
4569 ),
4570 -- Swap out events for the ID of the event we plan to use instead
4571 latest_events_to_use AS
4572 (
4573 SELECT occurred_at, s.source_id, status, error, details
4574 FROM
4575 id_of_status_to_use AS s
4576 JOIN latest_events AS e ON e.source_id = s.id_to_use
4577 ),
4578 combined AS (
4579 SELECT
4580 mz_sources.id,
4581 mz_sources.name,
4582 mz_sources.type,
4583 occurred_at,
4584 status,
4585 error,
4586 details
4587 FROM
4588 mz_catalog.mz_sources
4589 LEFT JOIN latest_events_to_use AS e ON mz_sources.id = e.source_id
4590 UNION ALL
4591 SELECT
4592 tables.self AS id,
4593 tables.name,
4594 'table' AS type,
4595 occurred_at,
4596 status,
4597 error,
4598 details
4599 FROM
4600 tables
4601 LEFT JOIN latest_events_to_use AS e ON tables.self = e.source_id
4602 )
4603SELECT
4604 id,
4605 name,
4606 type,
4607 occurred_at AS last_status_change_at,
4608 -- TODO(parkmycar): Report status of webhook source once database-issues#5986 is closed.
4609 CASE
4610 WHEN
4611 type = 'webhook' OR
4612 type = 'progress'
4613 THEN 'running'
4614 ELSE COALESCE(status, 'created')
4615 END AS status,
4616 error,
4617 details
4618FROM combined
4619WHERE id NOT LIKE 's%';",
4620 access: vec![PUBLIC_SELECT],
4621});
4622
4623pub static MZ_SINK_STATUS_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
4624 name: "mz_sink_status_history",
4625 schema: MZ_INTERNAL_SCHEMA,
4626 oid: oid::SOURCE_MZ_SINK_STATUS_HISTORY_OID,
4627 data_source: IntrospectionType::SinkStatusHistory.into(),
4628 desc: MZ_SINK_STATUS_HISTORY_DESC.clone(),
4629 column_comments: BTreeMap::from_iter([
4630 (
4631 "occurred_at",
4632 "Wall-clock timestamp of the sink status change.",
4633 ),
4634 (
4635 "sink_id",
4636 "The ID of the sink. Corresponds to `mz_catalog.mz_sinks.id`.",
4637 ),
4638 (
4639 "status",
4640 "The status of the sink: one of `created`, `starting`, `running`, `stalled`, `failed`, or `dropped`.",
4641 ),
4642 (
4643 "error",
4644 "If the sink is in an error state, the error message.",
4645 ),
4646 (
4647 "details",
4648 "Additional metadata provided by the sink. In case of error, may contain a `hint` field with helpful suggestions.",
4649 ),
4650 (
4651 "replica_id",
4652 "The ID of the replica that an instance of a sink is running on.",
4653 ),
4654 ]),
4655 is_retained_metrics_object: false,
4656 access: vec![PUBLIC_SELECT],
4657});
4658
4659pub static MZ_SINK_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
4660 name: "mz_sink_statuses",
4661 schema: MZ_INTERNAL_SCHEMA,
4662 oid: oid::VIEW_MZ_SINK_STATUSES_OID,
4663 desc: RelationDesc::builder()
4664 .with_column("id", SqlScalarType::String.nullable(false))
4665 .with_column("name", SqlScalarType::String.nullable(false))
4666 .with_column("type", SqlScalarType::String.nullable(false))
4667 .with_column(
4668 "last_status_change_at",
4669 SqlScalarType::TimestampTz { precision: None }.nullable(true),
4670 )
4671 .with_column("status", SqlScalarType::String.nullable(false))
4672 .with_column("error", SqlScalarType::String.nullable(true))
4673 .with_column("details", SqlScalarType::Jsonb.nullable(true))
4674 .finish(),
4675 column_comments: BTreeMap::from_iter([
4676 (
4677 "id",
4678 "The ID of the sink. Corresponds to `mz_catalog.mz_sinks.id`.",
4679 ),
4680 ("name", "The name of the sink."),
4681 ("type", "The type of the sink."),
4682 (
4683 "last_status_change_at",
4684 "Wall-clock timestamp of the sink status change.",
4685 ),
4686 (
4687 "status",
4688 "The status of the sink: one of `created`, `starting`, `running`, `stalled`, `failed`, or `dropped`.",
4689 ),
4690 (
4691 "error",
4692 "If the sink is in an error state, the error message.",
4693 ),
4694 (
4695 "details",
4696 "Additional metadata provided by the sink. In case of error, may contain a `hint` field with helpful suggestions.",
4697 ),
4698 ]),
4699 sql: "
4700WITH
4701-- The status history contains per-replica events and sink-global events.
4702-- For the latter, replica_id is NULL. We turn these into '<sink>', so that
4703-- we can treat them uniformly below.
4704uniform_status_history AS
4705(
4706 SELECT
4707 s.sink_id,
4708 COALESCE(s.replica_id, '<sink>') as replica_id,
4709 s.occurred_at,
4710 s.status,
4711 s.error,
4712 s.details
4713 FROM mz_internal.mz_sink_status_history s
4714),
4715-- For getting the latest events, we first determine the latest per-replica
4716-- events here and then apply precedence rules below.
4717latest_per_replica_events AS
4718(
4719 SELECT DISTINCT ON (sink_id, replica_id)
4720 occurred_at, sink_id, replica_id, status, error, details
4721 FROM uniform_status_history
4722 ORDER BY sink_id, replica_id, occurred_at DESC
4723),
4724-- We have a precedence list that determines the overall status in case
4725-- there is differing per-replica (including sink-global) statuses. If
4726-- there is no 'dropped' status, and any replica reports 'running', the
4727-- overall status is 'running' even if there might be some replica that has
4728-- errors or is paused.
4729latest_events AS
4730(
4731 SELECT DISTINCT ON (sink_id)
4732 sink_id,
4733 occurred_at,
4734 status,
4735 error,
4736 details
4737 FROM latest_per_replica_events
4738 ORDER BY sink_id, CASE status
4739 WHEN 'dropped' THEN 1
4740 WHEN 'running' THEN 2
4741 WHEN 'stalled' THEN 3
4742 WHEN 'starting' THEN 4
4743 WHEN 'paused' THEN 5
4744 WHEN 'ceased' THEN 6
4745 ELSE 7 -- For any other status values
4746 END
4747)
4748SELECT
4749 mz_sinks.id,
4750 name,
4751 mz_sinks.type,
4752 occurred_at as last_status_change_at,
4753 coalesce(status, 'created') as status,
4754 error,
4755 details
4756FROM mz_catalog.mz_sinks
4757LEFT JOIN latest_events ON mz_sinks.id = latest_events.sink_id
4758WHERE
4759 -- This is a convenient way to filter out system sinks, like the status_history table itself.
4760 mz_sinks.id NOT LIKE 's%'",
4761 access: vec![PUBLIC_SELECT],
4762});
4763
4764pub static MZ_STORAGE_USAGE_BY_SHARD_DESCRIPTION: LazyLock<SystemObjectDescription> =
4765 LazyLock::new(|| SystemObjectDescription {
4766 schema_name: MZ_STORAGE_USAGE_BY_SHARD.schema.to_string(),
4767 object_type: CatalogItemType::Table,
4768 object_name: MZ_STORAGE_USAGE_BY_SHARD.name.to_string(),
4769 });
4770
4771pub static MZ_STORAGE_USAGE_BY_SHARD: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
4772 name: "mz_storage_usage_by_shard",
4773 schema: MZ_INTERNAL_SCHEMA,
4774 oid: oid::TABLE_MZ_STORAGE_USAGE_BY_SHARD_OID,
4775 desc: RelationDesc::builder()
4776 .with_column("id", SqlScalarType::UInt64.nullable(false))
4777 .with_column("shard_id", SqlScalarType::String.nullable(true))
4778 .with_column("size_bytes", SqlScalarType::UInt64.nullable(false))
4779 .with_column(
4780 "collection_timestamp",
4781 SqlScalarType::TimestampTz { precision: None }.nullable(false),
4782 )
4783 .finish(),
4784 column_comments: BTreeMap::new(),
4785 is_retained_metrics_object: false,
4786 access: vec![PUBLIC_SELECT],
4787});
4788
4789pub static MZ_EGRESS_IPS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
4790 name: "mz_egress_ips",
4791 schema: MZ_CATALOG_SCHEMA,
4792 oid: oid::TABLE_MZ_EGRESS_IPS_OID,
4793 desc: RelationDesc::builder()
4794 .with_column("egress_ip", SqlScalarType::String.nullable(false))
4795 .with_column("prefix_length", SqlScalarType::Int32.nullable(false))
4796 .with_column("cidr", SqlScalarType::String.nullable(false))
4797 .finish(),
4798 column_comments: BTreeMap::from_iter([
4799 ("egress_ip", "The start of the range of IP addresses."),
4800 (
4801 "prefix_length",
4802 "The number of leading bits in the CIDR netmask.",
4803 ),
4804 ("cidr", "The CIDR representation."),
4805 ]),
4806 is_retained_metrics_object: false,
4807 access: vec![PUBLIC_SELECT],
4808});
4809
4810pub static MZ_AWS_PRIVATELINK_CONNECTIONS: LazyLock<BuiltinTable> =
4811 LazyLock::new(|| BuiltinTable {
4812 name: "mz_aws_privatelink_connections",
4813 schema: MZ_CATALOG_SCHEMA,
4814 oid: oid::TABLE_MZ_AWS_PRIVATELINK_CONNECTIONS_OID,
4815 desc: RelationDesc::builder()
4816 .with_column("id", SqlScalarType::String.nullable(false))
4817 .with_column("principal", SqlScalarType::String.nullable(false))
4818 .finish(),
4819 column_comments: BTreeMap::from_iter([
4820 ("id", "The ID of the connection."),
4821 (
4822 "principal",
4823 "The AWS Principal that Materialize will use to connect to the VPC endpoint.",
4824 ),
4825 ]),
4826 is_retained_metrics_object: false,
4827 access: vec![PUBLIC_SELECT],
4828 });
4829
4830pub static MZ_AWS_CONNECTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
4831 name: "mz_aws_connections",
4832 schema: MZ_INTERNAL_SCHEMA,
4833 oid: oid::TABLE_MZ_AWS_CONNECTIONS_OID,
4834 desc: RelationDesc::builder()
4835 .with_column("id", SqlScalarType::String.nullable(false))
4836 .with_column("endpoint", SqlScalarType::String.nullable(true))
4837 .with_column("region", SqlScalarType::String.nullable(true))
4838 .with_column("access_key_id", SqlScalarType::String.nullable(true))
4839 .with_column(
4840 "access_key_id_secret_id",
4841 SqlScalarType::String.nullable(true),
4842 )
4843 .with_column(
4844 "secret_access_key_secret_id",
4845 SqlScalarType::String.nullable(true),
4846 )
4847 .with_column("session_token", SqlScalarType::String.nullable(true))
4848 .with_column(
4849 "session_token_secret_id",
4850 SqlScalarType::String.nullable(true),
4851 )
4852 .with_column("assume_role_arn", SqlScalarType::String.nullable(true))
4853 .with_column(
4854 "assume_role_session_name",
4855 SqlScalarType::String.nullable(true),
4856 )
4857 .with_column("principal", SqlScalarType::String.nullable(true))
4858 .with_column("external_id", SqlScalarType::String.nullable(true))
4859 .with_column("example_trust_policy", SqlScalarType::Jsonb.nullable(true))
4860 .finish(),
4861 column_comments: BTreeMap::from_iter([
4862 ("id", "The ID of the connection."),
4863 ("endpoint", "The value of the `ENDPOINT` option, if set."),
4864 ("region", "The value of the `REGION` option, if set."),
4865 (
4866 "access_key_id",
4867 "The value of the `ACCESS KEY ID` option, if provided in line.",
4868 ),
4869 (
4870 "access_key_id_secret_id",
4871 "The ID of the secret referenced by the `ACCESS KEY ID` option, if provided via a secret.",
4872 ),
4873 (
4874 "secret_access_key_secret_id",
4875 "The ID of the secret referenced by the `SECRET ACCESS KEY` option, if set.",
4876 ),
4877 (
4878 "session_token",
4879 "The value of the `SESSION TOKEN` option, if provided in line.",
4880 ),
4881 (
4882 "session_token_secret_id",
4883 "The ID of the secret referenced by the `SESSION TOKEN` option, if provided via a secret.",
4884 ),
4885 (
4886 "assume_role_arn",
4887 "The value of the `ASSUME ROLE ARN` option, if set.",
4888 ),
4889 (
4890 "assume_role_session_name",
4891 "The value of the `ASSUME ROLE SESSION NAME` option, if set.",
4892 ),
4893 (
4894 "principal",
4895 "The ARN of the AWS principal Materialize will use when assuming the provided role, if the connection is configured to use role assumption.",
4896 ),
4897 (
4898 "external_id",
4899 "The external ID Materialize will use when assuming the provided role, if the connection is configured to use role assumption.",
4900 ),
4901 (
4902 "example_trust_policy",
4903 "An example of an IAM role trust policy that allows this connection's principal and external ID to assume the role.",
4904 ),
4905 ]),
4906 is_retained_metrics_object: false,
4907 access: vec![PUBLIC_SELECT],
4908});
4909
4910pub static MZ_CLUSTER_REPLICA_METRICS_HISTORY: LazyLock<BuiltinSource> =
4911 LazyLock::new(|| BuiltinSource {
4912 name: "mz_cluster_replica_metrics_history",
4913 schema: MZ_INTERNAL_SCHEMA,
4914 oid: oid::SOURCE_MZ_CLUSTER_REPLICA_METRICS_HISTORY_OID,
4915 data_source: IntrospectionType::ReplicaMetricsHistory.into(),
4916 desc: REPLICA_METRICS_HISTORY_DESC.clone(),
4917 column_comments: BTreeMap::from_iter([
4918 ("replica_id", "The ID of a cluster replica."),
4919 ("process_id", "The ID of a process within the replica."),
4920 (
4921 "cpu_nano_cores",
4922 "Approximate CPU usage, in billionths of a vCPU core.",
4923 ),
4924 ("memory_bytes", "Approximate memory usage, in bytes."),
4925 ("disk_bytes", "Approximate disk usage, in bytes."),
4926 (
4927 "occurred_at",
4928 "Wall-clock timestamp at which the event occurred.",
4929 ),
4930 (
4931 "heap_bytes",
4932 "Approximate heap (RAM + swap) usage, in bytes.",
4933 ),
4934 ("heap_limit", "Available heap (RAM + swap) space, in bytes."),
4935 ]),
4936 is_retained_metrics_object: false,
4937 access: vec![PUBLIC_SELECT],
4938 });
4939
4940pub static MZ_CLUSTER_REPLICA_METRICS_HISTORY_CT: LazyLock<BuiltinContinualTask> = LazyLock::new(
4941 || {
4942 BuiltinContinualTask {
4943 name: "mz_cluster_replica_metrics_history_ct",
4944 schema: MZ_INTERNAL_SCHEMA,
4945 oid: oid::CT_MZ_CLUSTER_REPLICA_METRICS_HISTORY_OID,
4946 desc: REPLICA_METRICS_HISTORY_DESC.clone(),
4947 sql: "
4948IN CLUSTER mz_catalog_server
4949ON INPUT mz_internal.mz_cluster_replica_metrics_history AS (
4950 DELETE FROM mz_internal.mz_cluster_replica_metrics_history_ct WHERE occurred_at + '30d' < mz_now();
4951 INSERT INTO mz_internal.mz_cluster_replica_metrics_history_ct SELECT * FROM mz_internal.mz_cluster_replica_metrics_history;
4952)",
4953 access: vec![PUBLIC_SELECT],
4954 }
4955 },
4956);
4957
4958pub static MZ_CLUSTER_REPLICA_METRICS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
4959 name: "mz_cluster_replica_metrics",
4960 schema: MZ_INTERNAL_SCHEMA,
4961 oid: oid::VIEW_MZ_CLUSTER_REPLICA_METRICS_OID,
4962 desc: RelationDesc::builder()
4963 .with_column("replica_id", SqlScalarType::String.nullable(false))
4964 .with_column("process_id", SqlScalarType::UInt64.nullable(false))
4965 .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(true))
4966 .with_column("memory_bytes", SqlScalarType::UInt64.nullable(true))
4967 .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
4968 .with_column("heap_bytes", SqlScalarType::UInt64.nullable(true))
4969 .with_column("heap_limit", SqlScalarType::UInt64.nullable(true))
4970 .with_key(vec![0, 1])
4971 .finish(),
4972 column_comments: BTreeMap::from_iter([
4973 ("replica_id", "The ID of a cluster replica."),
4974 ("process_id", "The ID of a process within the replica."),
4975 (
4976 "cpu_nano_cores",
4977 "Approximate CPU usage, in billionths of a vCPU core.",
4978 ),
4979 ("memory_bytes", "Approximate RAM usage, in bytes."),
4980 ("disk_bytes", "Approximate disk usage, in bytes."),
4981 (
4982 "heap_bytes",
4983 "Approximate heap (RAM + swap) usage, in bytes.",
4984 ),
4985 ("heap_limit", "Available heap (RAM + swap) space, in bytes."),
4986 ]),
4987 sql: "
4988SELECT
4989 DISTINCT ON (replica_id, process_id)
4990 replica_id,
4991 process_id,
4992 cpu_nano_cores,
4993 memory_bytes,
4994 disk_bytes,
4995 heap_bytes,
4996 heap_limit
4997FROM mz_internal.mz_cluster_replica_metrics_history
4998JOIN mz_cluster_replicas r ON r.id = replica_id
4999ORDER BY replica_id, process_id, occurred_at DESC",
5000 access: vec![PUBLIC_SELECT],
5001});
5002
5003pub static MZ_CLUSTER_REPLICA_FRONTIERS: LazyLock<BuiltinSource> =
5004 LazyLock::new(|| BuiltinSource {
5005 name: "mz_cluster_replica_frontiers",
5006 schema: MZ_CATALOG_SCHEMA,
5007 oid: oid::SOURCE_MZ_CLUSTER_REPLICA_FRONTIERS_OID,
5008 data_source: IntrospectionType::ReplicaFrontiers.into(),
5009 desc: RelationDesc::builder()
5010 .with_column("object_id", SqlScalarType::String.nullable(false))
5011 .with_column("replica_id", SqlScalarType::String.nullable(false))
5012 .with_column("write_frontier", SqlScalarType::MzTimestamp.nullable(true))
5013 .finish(),
5014 column_comments: BTreeMap::from_iter([
5015 (
5016 "object_id",
5017 "The ID of the source, sink, index, materialized view, or subscription.",
5018 ),
5019 ("replica_id", "The ID of a cluster replica."),
5020 (
5021 "write_frontier",
5022 "The next timestamp at which the output may change.",
5023 ),
5024 ]),
5025 is_retained_metrics_object: false,
5026 access: vec![PUBLIC_SELECT],
5027 });
5028
5029pub static MZ_CLUSTER_REPLICA_FRONTIERS_IND: LazyLock<BuiltinIndex> =
5030 LazyLock::new(|| BuiltinIndex {
5031 name: "mz_cluster_replica_frontiers_ind",
5032 schema: MZ_CATALOG_SCHEMA,
5033 oid: oid::INDEX_MZ_CLUSTER_REPLICA_FRONTIERS_IND_OID,
5034 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_cluster_replica_frontiers (object_id)",
5035 is_retained_metrics_object: false,
5036 });
5037
5038pub static MZ_FRONTIERS: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
5039 name: "mz_frontiers",
5040 schema: MZ_INTERNAL_SCHEMA,
5041 oid: oid::SOURCE_MZ_FRONTIERS_OID,
5042 data_source: IntrospectionType::Frontiers.into(),
5043 desc: RelationDesc::builder()
5044 .with_column("object_id", SqlScalarType::String.nullable(false))
5045 .with_column("read_frontier", SqlScalarType::MzTimestamp.nullable(true))
5046 .with_column("write_frontier", SqlScalarType::MzTimestamp.nullable(true))
5047 .finish(),
5048 column_comments: BTreeMap::from_iter([
5049 (
5050 "object_id",
5051 "The ID of the source, sink, table, index, materialized view, or subscription.",
5052 ),
5053 (
5054 "read_frontier",
5055 "The earliest timestamp at which the output is still readable.",
5056 ),
5057 (
5058 "write_frontier",
5059 "The next timestamp at which the output may change.",
5060 ),
5061 ]),
5062 is_retained_metrics_object: false,
5063 access: vec![PUBLIC_SELECT],
5064});
5065
5066pub static MZ_GLOBAL_FRONTIERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5068 name: "mz_global_frontiers",
5069 schema: MZ_INTERNAL_SCHEMA,
5070 oid: oid::VIEW_MZ_GLOBAL_FRONTIERS_OID,
5071 desc: RelationDesc::builder()
5072 .with_column("object_id", SqlScalarType::String.nullable(false))
5073 .with_column("time", SqlScalarType::MzTimestamp.nullable(false))
5074 .finish(),
5075 column_comments: BTreeMap::new(),
5076 sql: "
5077SELECT object_id, write_frontier AS time
5078FROM mz_internal.mz_frontiers
5079WHERE write_frontier IS NOT NULL",
5080 access: vec![PUBLIC_SELECT],
5081});
5082
5083pub static MZ_WALLCLOCK_LAG_HISTORY: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
5084 name: "mz_wallclock_lag_history",
5085 schema: MZ_INTERNAL_SCHEMA,
5086 oid: oid::SOURCE_MZ_WALLCLOCK_LAG_HISTORY_OID,
5087 desc: WALLCLOCK_LAG_HISTORY_DESC.clone(),
5088 data_source: IntrospectionType::WallclockLagHistory.into(),
5089 column_comments: BTreeMap::from_iter([
5090 (
5091 "object_id",
5092 "The ID of the table, source, materialized view, index, or sink. Corresponds to `mz_objects.id`.",
5093 ),
5094 (
5095 "replica_id",
5096 "The ID of a replica computing the object, or `NULL` for persistent objects. Corresponds to `mz_cluster_replicas.id`.",
5097 ),
5098 (
5099 "lag",
5100 "The amount of time the object's write frontier lags behind wallclock time.",
5101 ),
5102 (
5103 "occurred_at",
5104 "Wall-clock timestamp at which the event occurred.",
5105 ),
5106 ]),
5107 is_retained_metrics_object: false,
5108 access: vec![PUBLIC_SELECT],
5109});
5110
5111pub static MZ_WALLCLOCK_LAG_HISTORY_CT: LazyLock<BuiltinContinualTask> = LazyLock::new(|| {
5112 BuiltinContinualTask {
5113 name: "mz_wallclock_lag_history_ct",
5114 schema: MZ_INTERNAL_SCHEMA,
5115 oid: oid::CT_MZ_WALLCLOCK_LAG_HISTORY_OID,
5116 desc: WALLCLOCK_LAG_HISTORY_DESC.clone(),
5117 sql: "
5118IN CLUSTER mz_catalog_server
5119ON INPUT mz_internal.mz_wallclock_lag_history AS (
5120 DELETE FROM mz_internal.mz_wallclock_lag_history_ct WHERE occurred_at + '30d' < mz_now();
5121 INSERT INTO mz_internal.mz_wallclock_lag_history_ct SELECT * FROM mz_internal.mz_wallclock_lag_history;
5122)",
5123 access: vec![PUBLIC_SELECT],
5124 }
5125});
5126
5127pub static MZ_WALLCLOCK_GLOBAL_LAG_HISTORY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5128 name: "mz_wallclock_global_lag_history",
5129 schema: MZ_INTERNAL_SCHEMA,
5130 oid: oid::VIEW_MZ_WALLCLOCK_GLOBAL_LAG_HISTORY_OID,
5131 desc: RelationDesc::builder()
5132 .with_column("object_id", SqlScalarType::String.nullable(false))
5133 .with_column("lag", SqlScalarType::Interval.nullable(true))
5134 .with_column(
5135 "occurred_at",
5136 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5137 )
5138 .with_key(vec![0, 2])
5139 .finish(),
5140 column_comments: BTreeMap::new(),
5141 sql: "
5142WITH times_binned AS (
5143 SELECT
5144 object_id,
5145 lag,
5146 date_trunc('minute', occurred_at) AS occurred_at
5147 FROM mz_internal.mz_wallclock_lag_history
5148)
5149SELECT
5150 object_id,
5151 min(lag) AS lag,
5152 occurred_at
5153FROM times_binned
5154GROUP BY object_id, occurred_at
5155OPTIONS (AGGREGATE INPUT GROUP SIZE = 1)",
5156 access: vec![PUBLIC_SELECT],
5157});
5158
5159pub static MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY: LazyLock<BuiltinView> =
5160 LazyLock::new(|| BuiltinView {
5161 name: "mz_wallclock_global_lag_recent_history",
5162 schema: MZ_INTERNAL_SCHEMA,
5163 oid: oid::VIEW_MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY_OID,
5164 desc: RelationDesc::builder()
5165 .with_column("object_id", SqlScalarType::String.nullable(false))
5166 .with_column("lag", SqlScalarType::Interval.nullable(true))
5167 .with_column(
5168 "occurred_at",
5169 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5170 )
5171 .with_key(vec![0, 2])
5172 .finish(),
5173 column_comments: BTreeMap::new(),
5174 sql: "
5175SELECT object_id, lag, occurred_at
5176FROM mz_internal.mz_wallclock_global_lag_history
5177WHERE occurred_at + '1 day' > mz_now()",
5178 access: vec![PUBLIC_SELECT],
5179 });
5180
5181pub static MZ_WALLCLOCK_GLOBAL_LAG: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5182 name: "mz_wallclock_global_lag",
5183 schema: MZ_INTERNAL_SCHEMA,
5184 oid: oid::VIEW_MZ_WALLCLOCK_GLOBAL_LAG_OID,
5185 desc: RelationDesc::builder()
5186 .with_column("object_id", SqlScalarType::String.nullable(false))
5187 .with_column("lag", SqlScalarType::Interval.nullable(true))
5188 .with_key(vec![0])
5189 .finish(),
5190 column_comments: BTreeMap::from_iter([
5191 (
5192 "object_id",
5193 "The ID of the table, source, materialized view, index, or sink. Corresponds to `mz_objects.id`.",
5194 ),
5195 (
5196 "lag",
5197 "The amount of time the object's write frontier lags behind wallclock time.",
5198 ),
5199 ]),
5200 sql: "
5201SELECT DISTINCT ON (object_id) object_id, lag
5202FROM mz_internal.mz_wallclock_global_lag_recent_history
5203WHERE occurred_at + '5 minutes' > mz_now()
5204ORDER BY object_id, occurred_at DESC",
5205 access: vec![PUBLIC_SELECT],
5206});
5207
5208pub static MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW: LazyLock<BuiltinSource> =
5209 LazyLock::new(|| BuiltinSource {
5210 name: "mz_wallclock_global_lag_histogram_raw",
5211 schema: MZ_INTERNAL_SCHEMA,
5212 oid: oid::SOURCE_MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW_OID,
5213 desc: WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW_DESC.clone(),
5214 column_comments: BTreeMap::new(),
5215 data_source: IntrospectionType::WallclockLagHistogram.into(),
5216 is_retained_metrics_object: false,
5217 access: vec![PUBLIC_SELECT],
5218 });
5219
5220pub static MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM: LazyLock<BuiltinView> =
5221 LazyLock::new(|| BuiltinView {
5222 name: "mz_wallclock_global_lag_histogram",
5223 schema: MZ_INTERNAL_SCHEMA,
5224 oid: oid::VIEW_MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM_OID,
5225 desc: RelationDesc::builder()
5226 .with_column(
5227 "period_start",
5228 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5229 )
5230 .with_column(
5231 "period_end",
5232 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5233 )
5234 .with_column("object_id", SqlScalarType::String.nullable(false))
5235 .with_column("lag_seconds", SqlScalarType::UInt64.nullable(true))
5236 .with_column("labels", SqlScalarType::Jsonb.nullable(false))
5237 .with_column("count", SqlScalarType::Int64.nullable(false))
5238 .with_key(vec![0, 1, 2, 3, 4])
5239 .finish(),
5240 column_comments: BTreeMap::new(),
5241 sql: "
5242SELECT *, count(*) AS count
5243FROM mz_internal.mz_wallclock_global_lag_histogram_raw
5244GROUP BY period_start, period_end, object_id, lag_seconds, labels",
5245 access: vec![PUBLIC_SELECT],
5246 });
5247
5248pub static MZ_MATERIALIZED_VIEW_REFRESHES: LazyLock<BuiltinSource> = LazyLock::new(|| {
5249 BuiltinSource {
5250 name: "mz_materialized_view_refreshes",
5251 schema: MZ_INTERNAL_SCHEMA,
5252 oid: oid::SOURCE_MZ_MATERIALIZED_VIEW_REFRESHES_OID,
5253 data_source: DataSourceDesc::Introspection(
5254 IntrospectionType::ComputeMaterializedViewRefreshes,
5255 ),
5256 desc: RelationDesc::builder()
5257 .with_column(
5258 "materialized_view_id",
5259 SqlScalarType::String.nullable(false),
5260 )
5261 .with_column(
5262 "last_completed_refresh",
5263 SqlScalarType::MzTimestamp.nullable(true),
5264 )
5265 .with_column("next_refresh", SqlScalarType::MzTimestamp.nullable(true))
5266 .finish(),
5267 column_comments: BTreeMap::from_iter([
5268 (
5269 "materialized_view_id",
5270 "The ID of the materialized view. Corresponds to `mz_catalog.mz_materialized_views.id`",
5271 ),
5272 (
5273 "last_completed_refresh",
5274 "The time of the last successfully completed refresh. `NULL` if the materialized view hasn't completed any refreshes yet.",
5275 ),
5276 (
5277 "next_refresh",
5278 "The time of the next scheduled refresh. `NULL` if the materialized view has no future scheduled refreshes.",
5279 ),
5280 ]),
5281 is_retained_metrics_object: false,
5282 access: vec![PUBLIC_SELECT],
5283 }
5284});
5285
5286pub static MZ_SUBSCRIPTIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5287 name: "mz_subscriptions",
5288 schema: MZ_INTERNAL_SCHEMA,
5289 oid: oid::TABLE_MZ_SUBSCRIPTIONS_OID,
5290 desc: RelationDesc::builder()
5291 .with_column("id", SqlScalarType::String.nullable(false))
5292 .with_column("session_id", SqlScalarType::Uuid.nullable(false))
5293 .with_column("cluster_id", SqlScalarType::String.nullable(false))
5294 .with_column(
5295 "created_at",
5296 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5297 )
5298 .with_column(
5299 "referenced_object_ids",
5300 SqlScalarType::List {
5301 element_type: Box::new(SqlScalarType::String),
5302 custom_id: None,
5303 }
5304 .nullable(false),
5305 )
5306 .finish(),
5307 column_comments: BTreeMap::from_iter([
5308 ("id", "The ID of the subscription."),
5309 (
5310 "session_id",
5311 "The ID of the session that runs the subscription. Corresponds to `mz_sessions.id`.",
5312 ),
5313 (
5314 "cluster_id",
5315 "The ID of the cluster on which the subscription is running. Corresponds to `mz_clusters.id`.",
5316 ),
5317 (
5318 "created_at",
5319 "The time at which the subscription was created.",
5320 ),
5321 (
5322 "referenced_object_ids",
5323 "The IDs of objects referenced by the subscription. Corresponds to `mz_objects.id`",
5324 ),
5325 ]),
5326 is_retained_metrics_object: false,
5327 access: vec![PUBLIC_SELECT],
5328});
5329
5330pub static MZ_SESSIONS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5331 name: "mz_sessions",
5332 schema: MZ_INTERNAL_SCHEMA,
5333 oid: oid::TABLE_MZ_SESSIONS_OID,
5334 desc: RelationDesc::builder()
5335 .with_column("id", SqlScalarType::Uuid.nullable(false))
5336 .with_column("connection_id", SqlScalarType::UInt32.nullable(false))
5337 .with_column("role_id", SqlScalarType::String.nullable(false))
5338 .with_column("client_ip", SqlScalarType::String.nullable(true))
5339 .with_column(
5340 "connected_at",
5341 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5342 )
5343 .finish(),
5344 column_comments: BTreeMap::from_iter([
5345 ("id", "The globally unique ID of the session."),
5346 (
5347 "connection_id",
5348 "The connection ID of the session. Unique only for active sessions and can be recycled. Corresponds to `pg_backend_pid()`.",
5349 ),
5350 (
5351 "role_id",
5352 "The role ID of the role that the session is logged in as. Corresponds to `mz_catalog.mz_roles`.",
5353 ),
5354 (
5355 "client_ip",
5356 "The IP address of the client that initiated the session.",
5357 ),
5358 (
5359 "connected_at",
5360 "The time at which the session connected to the system.",
5361 ),
5362 ]),
5363 is_retained_metrics_object: false,
5364 access: vec![PUBLIC_SELECT],
5365});
5366
5367pub static MZ_DEFAULT_PRIVILEGES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5368 name: "mz_default_privileges",
5369 schema: MZ_CATALOG_SCHEMA,
5370 oid: oid::TABLE_MZ_DEFAULT_PRIVILEGES_OID,
5371 desc: RelationDesc::builder()
5372 .with_column("role_id", SqlScalarType::String.nullable(false))
5373 .with_column("database_id", SqlScalarType::String.nullable(true))
5374 .with_column("schema_id", SqlScalarType::String.nullable(true))
5375 .with_column("object_type", SqlScalarType::String.nullable(false))
5376 .with_column("grantee", SqlScalarType::String.nullable(false))
5377 .with_column("privileges", SqlScalarType::String.nullable(false))
5378 .finish(),
5379 column_comments: BTreeMap::from_iter([
5380 (
5381 "role_id",
5382 "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.",
5383 ),
5384 (
5385 "database_id",
5386 "Privileges described in this row will be granted only on objects in the database identified by `database_id` if non-null.",
5387 ),
5388 (
5389 "schema_id",
5390 "Privileges described in this row will be granted only on objects in the schema identified by `schema_id` if non-null.",
5391 ),
5392 (
5393 "object_type",
5394 "Privileges described in this row will be granted only on objects of type `object_type`.",
5395 ),
5396 (
5397 "grantee",
5398 "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.",
5399 ),
5400 ("privileges", "The set of privileges that will be granted."),
5401 ]),
5402 is_retained_metrics_object: false,
5403 access: vec![PUBLIC_SELECT],
5404});
5405
5406pub static MZ_SYSTEM_PRIVILEGES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5407 name: "mz_system_privileges",
5408 schema: MZ_CATALOG_SCHEMA,
5409 oid: oid::TABLE_MZ_SYSTEM_PRIVILEGES_OID,
5410 desc: RelationDesc::builder()
5411 .with_column("privileges", SqlScalarType::MzAclItem.nullable(false))
5412 .finish(),
5413 column_comments: BTreeMap::from_iter([(
5414 "privileges",
5415 "The privileges belonging to the system.",
5416 )]),
5417 is_retained_metrics_object: false,
5418 access: vec![PUBLIC_SELECT],
5419});
5420
5421pub static MZ_COMMENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5422 name: "mz_comments",
5423 schema: MZ_INTERNAL_SCHEMA,
5424 oid: oid::TABLE_MZ_COMMENTS_OID,
5425 desc: RelationDesc::builder()
5426 .with_column("id", SqlScalarType::String.nullable(false))
5427 .with_column("object_type", SqlScalarType::String.nullable(false))
5428 .with_column("object_sub_id", SqlScalarType::Int32.nullable(true))
5429 .with_column("comment", SqlScalarType::String.nullable(false))
5430 .finish(),
5431 column_comments: BTreeMap::from_iter([
5432 (
5433 "id",
5434 "The ID of the object. Corresponds to `mz_objects.id`.",
5435 ),
5436 (
5437 "object_type",
5438 "The type of object the comment is associated with.",
5439 ),
5440 (
5441 "object_sub_id",
5442 "For a comment on a column of a relation, the column number. `NULL` for other object types.",
5443 ),
5444 ("comment", "The comment itself."),
5445 ]),
5446 is_retained_metrics_object: false,
5447 access: vec![PUBLIC_SELECT],
5448});
5449
5450pub static MZ_SOURCE_REFERENCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5451 name: "mz_source_references",
5452 schema: MZ_INTERNAL_SCHEMA,
5453 oid: oid::TABLE_MZ_SOURCE_REFERENCES_OID,
5454 desc: RelationDesc::builder()
5455 .with_column("source_id", SqlScalarType::String.nullable(false))
5456 .with_column("namespace", SqlScalarType::String.nullable(true))
5457 .with_column("name", SqlScalarType::String.nullable(false))
5458 .with_column(
5459 "updated_at",
5460 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5461 )
5462 .with_column(
5463 "columns",
5464 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
5465 )
5466 .finish(),
5467 column_comments: BTreeMap::new(),
5468 is_retained_metrics_object: false,
5469 access: vec![PUBLIC_SELECT],
5470});
5471
5472pub static MZ_WEBHOOKS_SOURCES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5473 name: "mz_webhook_sources",
5474 schema: MZ_INTERNAL_SCHEMA,
5475 oid: oid::TABLE_MZ_WEBHOOK_SOURCES_OID,
5476 desc: RelationDesc::builder()
5477 .with_column("id", SqlScalarType::String.nullable(false))
5478 .with_column("name", SqlScalarType::String.nullable(false))
5479 .with_column("url", SqlScalarType::String.nullable(false))
5480 .finish(),
5481 column_comments: BTreeMap::from_iter([
5482 (
5483 "id",
5484 "The ID of the webhook source. Corresponds to `mz_sources.id`.",
5485 ),
5486 ("name", "The name of the webhook source."),
5487 (
5488 "url",
5489 "The URL which can be used to send events to the source.",
5490 ),
5491 ]),
5492 is_retained_metrics_object: false,
5493 access: vec![PUBLIC_SELECT],
5494});
5495
5496pub static MZ_HISTORY_RETENTION_STRATEGIES: LazyLock<BuiltinTable> = LazyLock::new(|| {
5497 BuiltinTable {
5498 name: "mz_history_retention_strategies",
5499 schema: MZ_INTERNAL_SCHEMA,
5500 oid: oid::TABLE_MZ_HISTORY_RETENTION_STRATEGIES_OID,
5501 desc: RelationDesc::builder()
5502 .with_column("id", SqlScalarType::String.nullable(false))
5503 .with_column("strategy", SqlScalarType::String.nullable(false))
5504 .with_column("value", SqlScalarType::Jsonb.nullable(false))
5505 .finish(),
5506 column_comments: BTreeMap::from_iter([
5507 ("id", "The ID of the object."),
5508 (
5509 "strategy",
5510 "The strategy. `FOR` is the only strategy, and means the object's compaction window is the duration of the `value` field.",
5511 ),
5512 (
5513 "value",
5514 "The value of the strategy. For `FOR`, is a number of milliseconds.",
5515 ),
5516 ]),
5517 is_retained_metrics_object: false,
5518 access: vec![PUBLIC_SELECT],
5519 }
5520});
5521
5522pub static MZ_LICENSE_KEYS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5523 name: "mz_license_keys",
5524 schema: MZ_INTERNAL_SCHEMA,
5525 oid: oid::TABLE_MZ_LICENSE_KEYS_OID,
5526 desc: RelationDesc::builder()
5527 .with_column("id", SqlScalarType::String.nullable(false))
5528 .with_column("organization", SqlScalarType::String.nullable(false))
5529 .with_column("environment_id", SqlScalarType::String.nullable(false))
5530 .with_column(
5531 "expiration",
5532 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5533 )
5534 .with_column(
5535 "not_before",
5536 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5537 )
5538 .finish(),
5539 column_comments: BTreeMap::from_iter([
5540 ("id", "The identifier of the license key."),
5541 (
5542 "organization",
5543 "The name of the organization that this license key was issued to.",
5544 ),
5545 (
5546 "environment_id",
5547 "The environment ID that this license key was issued for.",
5548 ),
5549 (
5550 "expiration",
5551 "The date and time when this license key expires.",
5552 ),
5553 (
5554 "not_before",
5555 "The start of the validity period for this license key.",
5556 ),
5557 ]),
5558 is_retained_metrics_object: false,
5559 access: vec![PUBLIC_SELECT],
5560});
5561
5562pub static MZ_REPLACEMENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5563 name: "mz_replacements",
5564 schema: MZ_INTERNAL_SCHEMA,
5565 oid: oid::TABLE_MZ_REPLACEMENTS_OID,
5566 desc: RelationDesc::builder()
5567 .with_column("id", SqlScalarType::String.nullable(false))
5568 .with_column("target_id", SqlScalarType::String.nullable(false))
5569 .finish(),
5570 column_comments: BTreeMap::from_iter([
5571 (
5572 "id",
5573 "The ID of the replacement object. Corresponds to `mz_objects.id`.",
5574 ),
5575 (
5576 "target_id",
5577 "The ID of the replacement target. Corresponds to `mz_objects.id`.",
5578 ),
5579 ]),
5580 is_retained_metrics_object: false,
5581 access: vec![PUBLIC_SELECT],
5582});
5583
5584pub static MZ_SOURCE_STATISTICS_RAW: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
5587 name: "mz_source_statistics_raw",
5588 schema: MZ_INTERNAL_SCHEMA,
5589 oid: oid::SOURCE_MZ_SOURCE_STATISTICS_RAW_OID,
5590 data_source: IntrospectionType::StorageSourceStatistics.into(),
5591 desc: MZ_SOURCE_STATISTICS_RAW_DESC.clone(),
5592 column_comments: BTreeMap::new(),
5593 is_retained_metrics_object: true,
5594 access: vec![PUBLIC_SELECT],
5595});
5596pub static MZ_SINK_STATISTICS_RAW: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
5597 name: "mz_sink_statistics_raw",
5598 schema: MZ_INTERNAL_SCHEMA,
5599 oid: oid::SOURCE_MZ_SINK_STATISTICS_RAW_OID,
5600 data_source: IntrospectionType::StorageSinkStatistics.into(),
5601 desc: MZ_SINK_STATISTICS_RAW_DESC.clone(),
5602 column_comments: BTreeMap::new(),
5603 is_retained_metrics_object: true,
5604 access: vec![PUBLIC_SELECT],
5605});
5606
5607pub static MZ_STORAGE_SHARDS: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
5608 name: "mz_storage_shards",
5609 schema: MZ_INTERNAL_SCHEMA,
5610 oid: oid::SOURCE_MZ_STORAGE_SHARDS_OID,
5611 data_source: IntrospectionType::ShardMapping.into(),
5612 desc: RelationDesc::builder()
5613 .with_column("object_id", SqlScalarType::String.nullable(false))
5614 .with_column("shard_id", SqlScalarType::String.nullable(false))
5615 .finish(),
5616 column_comments: BTreeMap::new(),
5617 is_retained_metrics_object: false,
5618 access: vec![PUBLIC_SELECT],
5619});
5620
5621pub static MZ_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5622 name: "mz_storage_usage",
5623 schema: MZ_CATALOG_SCHEMA,
5624 oid: oid::VIEW_MZ_STORAGE_USAGE_OID,
5625 desc: RelationDesc::builder()
5626 .with_column("object_id", SqlScalarType::String.nullable(false))
5627 .with_column("size_bytes", SqlScalarType::UInt64.nullable(false))
5628 .with_column(
5629 "collection_timestamp",
5630 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5631 )
5632 .with_key(vec![0, 2])
5633 .finish(),
5634 column_comments: BTreeMap::from_iter([
5635 (
5636 "object_id",
5637 "The ID of the table, source, or materialized view.",
5638 ),
5639 (
5640 "size_bytes",
5641 "The number of storage bytes used by the object.",
5642 ),
5643 (
5644 "collection_timestamp",
5645 "The time at which storage usage of the object was assessed.",
5646 ),
5647 ]),
5648 sql: "
5649SELECT
5650 object_id,
5651 sum(size_bytes)::uint8 AS size_bytes,
5652 collection_timestamp
5653FROM
5654 mz_internal.mz_storage_shards
5655 JOIN mz_internal.mz_storage_usage_by_shard USING (shard_id)
5656GROUP BY object_id, collection_timestamp",
5657 access: vec![PUBLIC_SELECT],
5658});
5659
5660pub static MZ_RECENT_STORAGE_USAGE: LazyLock<BuiltinView> = LazyLock::new(|| {
5661 BuiltinView {
5662 name: "mz_recent_storage_usage",
5663 schema: MZ_CATALOG_SCHEMA,
5664 oid: oid::VIEW_MZ_RECENT_STORAGE_USAGE_OID,
5665 desc: RelationDesc::builder()
5666 .with_column("object_id", SqlScalarType::String.nullable(false))
5667 .with_column("size_bytes", SqlScalarType::UInt64.nullable(true))
5668 .with_key(vec![0])
5669 .finish(),
5670 column_comments: BTreeMap::from_iter([
5671 ("object_id", "The ID of the table, source, or materialized view."),
5672 ("size_bytes", "The number of storage bytes used by the object in the most recent assessment."),
5673 ]),
5674 sql: "
5675WITH
5676
5677recent_storage_usage_by_shard AS (
5678 SELECT shard_id, size_bytes, collection_timestamp
5679 FROM mz_internal.mz_storage_usage_by_shard
5680 -- Restricting to the last 6 hours makes it feasible to index the view.
5681 WHERE collection_timestamp + '6 hours' >= mz_now()
5682),
5683
5684most_recent_collection_timestamp_by_shard AS (
5685 SELECT shard_id, max(collection_timestamp) AS collection_timestamp
5686 FROM recent_storage_usage_by_shard
5687 GROUP BY shard_id
5688)
5689
5690SELECT
5691 object_id,
5692 sum(size_bytes)::uint8 AS size_bytes
5693FROM
5694 mz_internal.mz_storage_shards
5695 LEFT JOIN most_recent_collection_timestamp_by_shard
5696 ON mz_storage_shards.shard_id = most_recent_collection_timestamp_by_shard.shard_id
5697 LEFT JOIN recent_storage_usage_by_shard
5698 ON mz_storage_shards.shard_id = recent_storage_usage_by_shard.shard_id
5699 AND most_recent_collection_timestamp_by_shard.collection_timestamp = recent_storage_usage_by_shard.collection_timestamp
5700GROUP BY object_id",
5701 access: vec![PUBLIC_SELECT],
5702}
5703});
5704
5705pub static MZ_RECENT_STORAGE_USAGE_IND: LazyLock<BuiltinIndex> = LazyLock::new(|| BuiltinIndex {
5706 name: "mz_recent_storage_usage_ind",
5707 schema: MZ_CATALOG_SCHEMA,
5708 oid: oid::INDEX_MZ_RECENT_STORAGE_USAGE_IND_OID,
5709 sql: "IN CLUSTER mz_catalog_server ON mz_catalog.mz_recent_storage_usage (object_id)",
5710 is_retained_metrics_object: false,
5711});
5712
5713pub static MZ_RELATIONS: LazyLock<BuiltinView> = LazyLock::new(|| {
5714 BuiltinView {
5715 name: "mz_relations",
5716 schema: MZ_CATALOG_SCHEMA,
5717 oid: oid::VIEW_MZ_RELATIONS_OID,
5718 desc: RelationDesc::builder()
5719 .with_column("id", SqlScalarType::String.nullable(false))
5720 .with_column("oid", SqlScalarType::Oid.nullable(false))
5721 .with_column("schema_id", SqlScalarType::String.nullable(false))
5722 .with_column("name", SqlScalarType::String.nullable(false))
5723 .with_column("type", SqlScalarType::String.nullable(false))
5724 .with_column("owner_id", SqlScalarType::String.nullable(false))
5725 .with_column("cluster_id", SqlScalarType::String.nullable(true))
5726 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(false))
5727 .finish(),
5728 column_comments: BTreeMap::from_iter([
5729 ("id", "Materialize's unique ID for the relation."),
5730 ("oid", "A PostgreSQL-compatible OID for the relation."),
5731 ("schema_id", "The ID of the schema to which the relation belongs. Corresponds to `mz_schemas.id`."),
5732 ("name", "The name of the relation."),
5733 ("type", "The type of the relation: either `table`, `source`, `view`, or `materialized view`."),
5734 ("owner_id", "The role ID of the owner of the relation. Corresponds to `mz_roles.id`."),
5735 ("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."),
5736 ("privileges", "The privileges belonging to the relation."),
5737 ]),
5738 sql: "
5739 SELECT id, oid, schema_id, name, 'table' AS type, owner_id, NULL::text AS cluster_id, privileges FROM mz_catalog.mz_tables
5740UNION ALL SELECT id, oid, schema_id, name, 'source', owner_id, cluster_id, privileges FROM mz_catalog.mz_sources
5741UNION ALL SELECT id, oid, schema_id, name, 'view', owner_id, NULL::text, privileges FROM mz_catalog.mz_views
5742UNION ALL SELECT id, oid, schema_id, name, 'materialized-view', owner_id, cluster_id, privileges FROM mz_catalog.mz_materialized_views
5743UNION ALL SELECT id, oid, schema_id, name, 'continual-task', owner_id, cluster_id, privileges FROM mz_internal.mz_continual_tasks",
5744 access: vec![PUBLIC_SELECT],
5745 }
5746});
5747
5748pub static MZ_OBJECTS_ID_NAMESPACE_TYPES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5749 name: "mz_objects_id_namespace_types",
5750 schema: MZ_INTERNAL_SCHEMA,
5751 oid: oid::VIEW_MZ_OBJECTS_ID_NAMESPACE_TYPES_OID,
5752 desc: RelationDesc::builder()
5753 .with_column("object_type", SqlScalarType::String.nullable(false))
5754 .with_key(vec![0])
5755 .finish(),
5756 column_comments: BTreeMap::new(),
5757 sql: r#"SELECT *
5758 FROM (
5759 VALUES
5760 ('table'),
5761 ('view'),
5762 ('materialized-view'),
5763 ('source'),
5764 ('sink'),
5765 ('index'),
5766 ('connection'),
5767 ('type'),
5768 ('function'),
5769 ('secret')
5770 )
5771 AS _ (object_type)"#,
5772 access: vec![PUBLIC_SELECT],
5773});
5774
5775pub static MZ_OBJECT_OID_ALIAS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5776 name: "mz_object_oid_alias",
5777 schema: MZ_INTERNAL_SCHEMA,
5778 oid: oid::VIEW_MZ_OBJECT_OID_ALIAS_OID,
5779 desc: RelationDesc::builder()
5780 .with_column("object_type", SqlScalarType::String.nullable(false))
5781 .with_column("oid_alias", SqlScalarType::String.nullable(false))
5782 .with_key(vec![0])
5783 .finish(),
5784 column_comments: BTreeMap::new(),
5785 sql: "SELECT object_type, oid_alias
5786 FROM (
5787 VALUES
5788 (
5789 'table'::pg_catalog.text,
5790 'regclass'::pg_catalog.text
5791 ),
5792 ('source', 'regclass'),
5793 ('view', 'regclass'),
5794 ('materialized-view', 'regclass'),
5795 ('index', 'regclass'),
5796 ('type', 'regtype'),
5797 ('function', 'regproc')
5798 )
5799 AS _ (object_type, oid_alias);",
5800 access: vec![PUBLIC_SELECT],
5801});
5802
5803pub static MZ_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| {
5804 BuiltinView {
5805 name: "mz_objects",
5806 schema: MZ_CATALOG_SCHEMA,
5807 oid: oid::VIEW_MZ_OBJECTS_OID,
5808 desc: RelationDesc::builder()
5809 .with_column("id", SqlScalarType::String.nullable(false))
5810 .with_column("oid", SqlScalarType::Oid.nullable(false))
5811 .with_column("schema_id", SqlScalarType::String.nullable(false))
5812 .with_column("name", SqlScalarType::String.nullable(false))
5813 .with_column("type", SqlScalarType::String.nullable(false))
5814 .with_column("owner_id", SqlScalarType::String.nullable(false))
5815 .with_column("cluster_id", SqlScalarType::String.nullable(true))
5816 .with_column("privileges", SqlScalarType::Array(Box::new(SqlScalarType::MzAclItem)).nullable(true))
5817 .finish(),
5818 column_comments: BTreeMap::from_iter([
5819 ("id", "Materialize's unique ID for the object."),
5820 ("oid", "A PostgreSQL-compatible OID for the object."),
5821 ("schema_id", "The ID of the schema to which the object belongs. Corresponds to `mz_schemas.id`."),
5822 ("name", "The name of the object."),
5823 ("type", "The type of the object: one of `table`, `source`, `view`, `materialized-view`, `sink`, `index`, `connection`, `secret`, `type`, or `function`."),
5824 ("owner_id", "The role ID of the owner of the object. Corresponds to `mz_roles.id`."),
5825 ("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."),
5826 ("privileges", "The privileges belonging to the object."),
5827 ]),
5828 sql:
5829 "SELECT id, oid, schema_id, name, type, owner_id, cluster_id, privileges FROM mz_catalog.mz_relations
5830UNION ALL
5831 SELECT id, oid, schema_id, name, 'sink', owner_id, cluster_id, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_sinks
5832UNION ALL
5833 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[]
5834 FROM mz_catalog.mz_indexes
5835 JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
5836UNION ALL
5837 SELECT id, oid, schema_id, name, 'connection', owner_id, NULL::text, privileges FROM mz_catalog.mz_connections
5838UNION ALL
5839 SELECT id, oid, schema_id, name, 'type', owner_id, NULL::text, privileges FROM mz_catalog.mz_types
5840UNION ALL
5841 SELECT id, oid, schema_id, name, 'function', owner_id, NULL::text, NULL::mz_catalog.mz_aclitem[] FROM mz_catalog.mz_functions
5842UNION ALL
5843 SELECT id, oid, schema_id, name, 'secret', owner_id, NULL::text, privileges FROM mz_catalog.mz_secrets",
5844 access: vec![PUBLIC_SELECT],
5845 }
5846});
5847
5848pub static MZ_OBJECT_FULLY_QUALIFIED_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5849 name: "mz_object_fully_qualified_names",
5850 schema: MZ_INTERNAL_SCHEMA,
5851 oid: oid::VIEW_MZ_OBJECT_FULLY_QUALIFIED_NAMES_OID,
5852 desc: RelationDesc::builder()
5853 .with_column("id", SqlScalarType::String.nullable(false))
5854 .with_column("name", SqlScalarType::String.nullable(false))
5855 .with_column("object_type", SqlScalarType::String.nullable(false))
5856 .with_column("schema_id", SqlScalarType::String.nullable(false))
5857 .with_column("schema_name", SqlScalarType::String.nullable(false))
5858 .with_column("database_id", SqlScalarType::String.nullable(true))
5859 .with_column("database_name", SqlScalarType::String.nullable(true))
5860 .with_column("cluster_id", SqlScalarType::String.nullable(true))
5861 .finish(),
5862 column_comments: BTreeMap::from_iter([
5863 ("id", "Materialize's unique ID for the object."),
5864 ("name", "The name of the object."),
5865 (
5866 "object_type",
5867 "The type of the object: one of `table`, `source`, `view`, `materialized view`, `sink`, `index`, `connection`, `secret`, `type`, or `function`.",
5868 ),
5869 (
5870 "schema_id",
5871 "The ID of the schema to which the object belongs. Corresponds to `mz_schemas.id`.",
5872 ),
5873 (
5874 "schema_name",
5875 "The name of the schema to which the object belongs. Corresponds to `mz_schemas.name`.",
5876 ),
5877 (
5878 "database_id",
5879 "The ID of the database to which the object belongs. Corresponds to `mz_databases.id`.",
5880 ),
5881 (
5882 "database_name",
5883 "The name of the database to which the object belongs. Corresponds to `mz_databases.name`.",
5884 ),
5885 (
5886 "cluster_id",
5887 "The ID of the cluster maintaining the source, materialized view, index, or sink. Corresponds to `mz_clusters.id`. `NULL` for other object types.",
5888 ),
5889 ]),
5890 sql: "
5891 SELECT o.id,
5892 o.name,
5893 o.type as object_type,
5894 sc.id as schema_id,
5895 sc.name as schema_name,
5896 db.id as database_id,
5897 db.name as database_name,
5898 o.cluster_id
5899 FROM mz_catalog.mz_objects o
5900 INNER JOIN mz_catalog.mz_schemas sc ON sc.id = o.schema_id
5901 -- LEFT JOIN accounts for objects in the ambient database.
5902 LEFT JOIN mz_catalog.mz_databases db ON db.id = sc.database_id",
5903 access: vec![PUBLIC_SELECT],
5904});
5905
5906pub static MZ_OBJECT_GLOBAL_IDS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5907 name: "mz_object_global_ids",
5908 schema: MZ_INTERNAL_SCHEMA,
5909 oid: oid::VIEW_MZ_OBJECT_GLOBAL_IDS_OID,
5910 desc: RelationDesc::builder()
5911 .with_column("id", SqlScalarType::String.nullable(false))
5912 .with_column("global_id", SqlScalarType::String.nullable(false))
5913 .finish(),
5914 column_comments: BTreeMap::from_iter([
5915 (
5916 "id",
5917 "The ID of the object. Corresponds to `mz_objects.id`.",
5918 ),
5919 ("global_id", "The global ID of the object."),
5920 ]),
5921 is_retained_metrics_object: false,
5922 access: vec![PUBLIC_SELECT],
5923});
5924
5925pub static MZ_OBJECT_LIFETIMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5927 name: "mz_object_lifetimes",
5928 schema: MZ_INTERNAL_SCHEMA,
5929 oid: oid::VIEW_MZ_OBJECT_LIFETIMES_OID,
5930 desc: RelationDesc::builder()
5931 .with_column("id", SqlScalarType::String.nullable(true))
5932 .with_column("previous_id", SqlScalarType::String.nullable(true))
5933 .with_column("object_type", SqlScalarType::String.nullable(false))
5934 .with_column("event_type", SqlScalarType::String.nullable(false))
5935 .with_column(
5936 "occurred_at",
5937 SqlScalarType::TimestampTz { precision: None }.nullable(false),
5938 )
5939 .finish(),
5940 column_comments: BTreeMap::from_iter([
5941 ("id", "Materialize's unique ID for the object."),
5942 ("previous_id", "The object's previous ID, if one exists."),
5943 (
5944 "object_type",
5945 "The type of the object: one of `table`, `source`, `view`, `materialized view`, `sink`, `index`, `connection`, `secret`, `type`, or `function`.",
5946 ),
5947 (
5948 "event_type",
5949 "The lifetime event, either `create` or `drop`.",
5950 ),
5951 (
5952 "occurred_at",
5953 "Wall-clock timestamp of when the event occurred.",
5954 ),
5955 ]),
5956 sql: "
5957 SELECT
5958 CASE
5959 WHEN a.object_type = 'cluster-replica' THEN a.details ->> 'replica_id'
5960 ELSE a.details ->> 'id'
5961 END id,
5962 a.details ->> 'previous_id' as previous_id,
5963 a.object_type,
5964 a.event_type,
5965 a.occurred_at
5966 FROM mz_catalog.mz_audit_events a
5967 WHERE a.event_type = 'create' OR a.event_type = 'drop'",
5968 access: vec![PUBLIC_SELECT],
5969});
5970
5971pub static MZ_OBJECT_HISTORY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
5972 name: "mz_object_history",
5973 schema: MZ_INTERNAL_SCHEMA,
5974 oid: oid::VIEW_MZ_OBJECT_HISTORY_OID,
5975 desc: RelationDesc::builder()
5976 .with_column("id", SqlScalarType::String.nullable(true))
5977 .with_column("cluster_id", SqlScalarType::String.nullable(true))
5978 .with_column("object_type", SqlScalarType::String.nullable(false))
5979 .with_column(
5980 "created_at",
5981 SqlScalarType::TimestampTz { precision: None }.nullable(true),
5982 )
5983 .with_column(
5984 "dropped_at",
5985 SqlScalarType::TimestampTz { precision: None }.nullable(true),
5986 )
5987 .finish(),
5988 column_comments: BTreeMap::from_iter([
5989 ("id", "Materialize's unique ID for the object."),
5990 (
5991 "cluster_id",
5992 "The object's cluster ID. `NULL` if the object has no associated cluster.",
5993 ),
5994 (
5995 "object_type",
5996 "The type of the object: one of `table`, `source`, `view`, `materialized view`, `sink`, `index`, `connection`, `secret`, `type`, or `function`.",
5997 ),
5998 (
5999 "created_at",
6000 "Wall-clock timestamp of when the object was created. `NULL` for built in system objects.",
6001 ),
6002 (
6003 "dropped_at",
6004 "Wall-clock timestamp of when the object was dropped. `NULL` for built in system objects or if the object hasn't been dropped.",
6005 ),
6006 ]),
6007 sql: r#"
6008 WITH
6009 creates AS
6010 (
6011 SELECT
6012 details ->> 'id' AS id,
6013 -- We need to backfill cluster_id since older object create events don't include the cluster ID in the audit log
6014 COALESCE(details ->> 'cluster_id', objects.cluster_id) AS cluster_id,
6015 object_type,
6016 occurred_at
6017 FROM
6018 mz_catalog.mz_audit_events AS events
6019 LEFT JOIN mz_catalog.mz_objects AS objects ON details ->> 'id' = objects.id
6020 WHERE event_type = 'create' AND object_type IN ( SELECT object_type FROM mz_internal.mz_objects_id_namespace_types )
6021 ),
6022 drops AS
6023 (
6024 SELECT details ->> 'id' AS id, occurred_at
6025 FROM mz_catalog.mz_audit_events
6026 WHERE event_type = 'drop' AND object_type IN ( SELECT object_type FROM mz_internal.mz_objects_id_namespace_types )
6027 ),
6028 user_object_history AS
6029 (
6030 SELECT
6031 creates.id,
6032 creates.cluster_id,
6033 creates.object_type,
6034 creates.occurred_at AS created_at,
6035 drops.occurred_at AS dropped_at
6036 FROM creates LEFT JOIN drops ON creates.id = drops.id
6037 WHERE creates.id LIKE 'u%'
6038 ),
6039 -- We need to union built in objects since they aren't in the audit log
6040 built_in_objects AS
6041 (
6042 -- Functions that accept different arguments have different oids but the same id. We deduplicate in this case.
6043 SELECT DISTINCT ON (objects.id)
6044 objects.id,
6045 objects.cluster_id,
6046 objects.type AS object_type,
6047 NULL::timestamptz AS created_at,
6048 NULL::timestamptz AS dropped_at
6049 FROM mz_catalog.mz_objects AS objects
6050 WHERE objects.id LIKE 's%'
6051 )
6052 SELECT * FROM user_object_history UNION ALL (SELECT * FROM built_in_objects)"#,
6053 access: vec![PUBLIC_SELECT],
6054});
6055
6056pub static MZ_DATAFLOWS_PER_WORKER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6057 name: "mz_dataflows_per_worker",
6058 schema: MZ_INTROSPECTION_SCHEMA,
6059 oid: oid::VIEW_MZ_DATAFLOWS_PER_WORKER_OID,
6060 desc: RelationDesc::builder()
6061 .with_column("id", SqlScalarType::UInt64.nullable(true))
6062 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
6063 .with_column("name", SqlScalarType::String.nullable(false))
6064 .finish(),
6065 column_comments: BTreeMap::new(),
6066 sql: "SELECT
6067 addrs.address[1] AS id,
6068 ops.worker_id,
6069 ops.name
6070FROM
6071 mz_introspection.mz_dataflow_addresses_per_worker addrs,
6072 mz_introspection.mz_dataflow_operators_per_worker ops
6073WHERE
6074 addrs.id = ops.id AND
6075 addrs.worker_id = ops.worker_id AND
6076 mz_catalog.list_length(addrs.address) = 1",
6077 access: vec![PUBLIC_SELECT],
6078});
6079
6080pub static MZ_DATAFLOWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6081 name: "mz_dataflows",
6082 schema: MZ_INTROSPECTION_SCHEMA,
6083 oid: oid::VIEW_MZ_DATAFLOWS_OID,
6084 desc: RelationDesc::builder()
6085 .with_column("id", SqlScalarType::UInt64.nullable(true))
6086 .with_column("name", SqlScalarType::String.nullable(false))
6087 .finish(),
6088 column_comments: BTreeMap::from_iter([
6089 ("id", "The ID of the dataflow."),
6090 ("name", "The internal name of the dataflow."),
6091 ]),
6092 sql: "
6093SELECT id, name
6094FROM mz_introspection.mz_dataflows_per_worker
6095WHERE worker_id = 0",
6096 access: vec![PUBLIC_SELECT],
6097});
6098
6099pub static MZ_DATAFLOW_ADDRESSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6100 name: "mz_dataflow_addresses",
6101 schema: MZ_INTROSPECTION_SCHEMA,
6102 oid: oid::VIEW_MZ_DATAFLOW_ADDRESSES_OID,
6103 desc: RelationDesc::builder()
6104 .with_column("id", SqlScalarType::UInt64.nullable(false))
6105 .with_column(
6106 "address",
6107 SqlScalarType::List {
6108 element_type: Box::new(SqlScalarType::UInt64),
6109 custom_id: None,
6110 }
6111 .nullable(false),
6112 )
6113 .finish(),
6114 column_comments: BTreeMap::from_iter([
6115 (
6116 "id",
6117 "The ID of the channel or operator. Corresponds to `mz_dataflow_channels.id` or `mz_dataflow_operators.id`.",
6118 ),
6119 (
6120 "address",
6121 "A list of scope-local indexes indicating the path from the root to this channel or operator.",
6122 ),
6123 ]),
6124 sql: "
6125SELECT id, address
6126FROM mz_introspection.mz_dataflow_addresses_per_worker
6127WHERE worker_id = 0",
6128 access: vec![PUBLIC_SELECT],
6129});
6130
6131pub static MZ_DATAFLOW_CHANNELS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6132 name: "mz_dataflow_channels",
6133 schema: MZ_INTROSPECTION_SCHEMA,
6134 oid: oid::VIEW_MZ_DATAFLOW_CHANNELS_OID,
6135 desc: RelationDesc::builder()
6136 .with_column("id", SqlScalarType::UInt64.nullable(false))
6137 .with_column("from_index", SqlScalarType::UInt64.nullable(false))
6138 .with_column("from_port", SqlScalarType::UInt64.nullable(false))
6139 .with_column("to_index", SqlScalarType::UInt64.nullable(false))
6140 .with_column("to_port", SqlScalarType::UInt64.nullable(false))
6141 .with_column("type", SqlScalarType::String.nullable(false))
6142 .finish(),
6143 column_comments: BTreeMap::from_iter([
6144 ("id", "The ID of the channel."),
6145 (
6146 "from_index",
6147 "The scope-local index of the source operator. Corresponds to `mz_dataflow_addresses.address`.",
6148 ),
6149 ("from_port", "The source operator's output port."),
6150 (
6151 "to_index",
6152 "The scope-local index of the target operator. Corresponds to `mz_dataflow_addresses.address`.",
6153 ),
6154 ("to_port", "The target operator's input port."),
6155 ("type", "The container type of the channel."),
6156 ]),
6157 sql: "
6158SELECT id, from_index, from_port, to_index, to_port, type
6159FROM mz_introspection.mz_dataflow_channels_per_worker
6160WHERE worker_id = 0",
6161 access: vec![PUBLIC_SELECT],
6162});
6163
6164pub static MZ_DATAFLOW_OPERATORS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6165 name: "mz_dataflow_operators",
6166 schema: MZ_INTROSPECTION_SCHEMA,
6167 oid: oid::VIEW_MZ_DATAFLOW_OPERATORS_OID,
6168 desc: RelationDesc::builder()
6169 .with_column("id", SqlScalarType::UInt64.nullable(false))
6170 .with_column("name", SqlScalarType::String.nullable(false))
6171 .finish(),
6172 column_comments: BTreeMap::from_iter([
6173 ("id", "The ID of the operator."),
6174 ("name", "The internal name of the operator."),
6175 ]),
6176 sql: "
6177SELECT id, name
6178FROM mz_introspection.mz_dataflow_operators_per_worker
6179WHERE worker_id = 0",
6180 access: vec![PUBLIC_SELECT],
6181});
6182
6183pub static MZ_DATAFLOW_GLOBAL_IDS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6184 name: "mz_dataflow_global_ids",
6185 schema: MZ_INTROSPECTION_SCHEMA,
6186 oid: oid::VIEW_MZ_DATAFLOW_GLOBAL_IDS_OID,
6187 desc: RelationDesc::builder()
6188 .with_column("id", SqlScalarType::UInt64.nullable(false))
6189 .with_column("global_id", SqlScalarType::String.nullable(false))
6190 .finish(),
6191 column_comments: BTreeMap::from_iter([
6192 ("id", "The dataflow ID."),
6193 ("global_id", "A global ID associated with that dataflow."),
6194 ]),
6195 sql: "
6196SELECT id, global_id
6197FROM mz_introspection.mz_compute_dataflow_global_ids_per_worker
6198WHERE worker_id = 0",
6199 access: vec![PUBLIC_SELECT],
6200});
6201
6202pub static MZ_MAPPABLE_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| {
6203 BuiltinView {
6204 name: "mz_mappable_objects",
6205 schema: MZ_INTROSPECTION_SCHEMA,
6206 oid: oid::VIEW_MZ_MAPPABLE_OBJECTS_OID,
6207 desc: RelationDesc::builder()
6208 .with_column("name", SqlScalarType::String.nullable(false))
6209 .with_column("global_id", SqlScalarType::String.nullable(false))
6210 .finish(),
6211 column_comments: BTreeMap::from_iter([
6212 ("name", "The name of the object."),
6213 ("global_id", "The global ID of the object."),
6214 ]),
6215 sql: "
6216SELECT COALESCE(quote_ident(md.name) || '.', '') || quote_ident(ms.name) || '.' || quote_ident(mo.name) AS name, mgi.global_id AS global_id
6217FROM mz_catalog.mz_objects mo
6218 JOIN mz_introspection.mz_compute_exports mce ON (mo.id = mce.export_id)
6219 JOIN mz_catalog.mz_schemas ms ON (mo.schema_id = ms.id)
6220 JOIN mz_introspection.mz_dataflow_global_ids mgi ON (mce.dataflow_id = mgi.id)
6221 LEFT JOIN mz_catalog.mz_databases md ON (ms.database_id = md.id);",
6222 access: vec![PUBLIC_SELECT],
6223}
6224});
6225
6226pub static MZ_LIR_MAPPING: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6227 name: "mz_lir_mapping",
6228 schema: MZ_INTROSPECTION_SCHEMA,
6229 oid: oid::VIEW_MZ_LIR_MAPPING_OID,
6230 desc: RelationDesc::builder()
6231 .with_column("global_id", SqlScalarType::String.nullable(false))
6232 .with_column("lir_id", SqlScalarType::UInt64.nullable(false))
6233 .with_column("operator", SqlScalarType::String.nullable(false))
6234 .with_column("parent_lir_id", SqlScalarType::UInt64.nullable(true))
6235 .with_column("nesting", SqlScalarType::UInt16.nullable(false))
6236 .with_column("operator_id_start", SqlScalarType::UInt64.nullable(false))
6237 .with_column("operator_id_end", SqlScalarType::UInt64.nullable(false))
6238 .finish(),
6239 column_comments: BTreeMap::from_iter([
6240 ("global_id", "The global ID."),
6241 ("lir_id", "The LIR node ID."),
6242 (
6243 "operator",
6244 "The LIR operator, in the format `OperatorName INPUTS [OPTIONS]`.",
6245 ),
6246 (
6247 "parent_lir_id",
6248 "The parent of this LIR node. May be `NULL`.",
6249 ),
6250 ("nesting", "The nesting level of this LIR node."),
6251 (
6252 "operator_id_start",
6253 "The first dataflow operator ID implementing this LIR operator (inclusive).",
6254 ),
6255 (
6256 "operator_id_end",
6257 "The first dataflow operator ID _after_ this LIR operator (exclusive).",
6258 ),
6259 ]),
6260 sql: "
6261SELECT global_id, lir_id, operator, parent_lir_id, nesting, operator_id_start, operator_id_end
6262FROM mz_introspection.mz_compute_lir_mapping_per_worker
6263WHERE worker_id = 0",
6264 access: vec![PUBLIC_SELECT],
6265});
6266
6267pub static MZ_DATAFLOW_OPERATOR_DATAFLOWS_PER_WORKER: LazyLock<BuiltinView> =
6268 LazyLock::new(|| BuiltinView {
6269 name: "mz_dataflow_operator_dataflows_per_worker",
6270 schema: MZ_INTROSPECTION_SCHEMA,
6271 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_DATAFLOWS_PER_WORKER_OID,
6272 desc: RelationDesc::builder()
6273 .with_column("id", SqlScalarType::UInt64.nullable(false))
6274 .with_column("name", SqlScalarType::String.nullable(false))
6275 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
6276 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
6277 .with_column("dataflow_name", SqlScalarType::String.nullable(false))
6278 .finish(),
6279 column_comments: BTreeMap::new(),
6280 sql: "SELECT
6281 ops.id,
6282 ops.name,
6283 ops.worker_id,
6284 dfs.id as dataflow_id,
6285 dfs.name as dataflow_name
6286FROM
6287 mz_introspection.mz_dataflow_operators_per_worker ops,
6288 mz_introspection.mz_dataflow_addresses_per_worker addrs,
6289 mz_introspection.mz_dataflows_per_worker dfs
6290WHERE
6291 ops.id = addrs.id AND
6292 ops.worker_id = addrs.worker_id AND
6293 dfs.id = addrs.address[1] AND
6294 dfs.worker_id = addrs.worker_id",
6295 access: vec![PUBLIC_SELECT],
6296 });
6297
6298pub static MZ_DATAFLOW_OPERATOR_DATAFLOWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6299 name: "mz_dataflow_operator_dataflows",
6300 schema: MZ_INTROSPECTION_SCHEMA,
6301 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_DATAFLOWS_OID,
6302 desc: RelationDesc::builder()
6303 .with_column("id", SqlScalarType::UInt64.nullable(false))
6304 .with_column("name", SqlScalarType::String.nullable(false))
6305 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
6306 .with_column("dataflow_name", SqlScalarType::String.nullable(false))
6307 .finish(),
6308 column_comments: BTreeMap::from_iter([
6309 (
6310 "id",
6311 "The ID of the operator. Corresponds to `mz_dataflow_operators.id`.",
6312 ),
6313 ("name", "The internal name of the operator."),
6314 (
6315 "dataflow_id",
6316 "The ID of the dataflow hosting the operator. Corresponds to `mz_dataflows.id`.",
6317 ),
6318 (
6319 "dataflow_name",
6320 "The internal name of the dataflow hosting the operator.",
6321 ),
6322 ]),
6323 sql: "
6324SELECT id, name, dataflow_id, dataflow_name
6325FROM mz_introspection.mz_dataflow_operator_dataflows_per_worker
6326WHERE worker_id = 0",
6327 access: vec![PUBLIC_SELECT],
6328});
6329
6330pub static MZ_OBJECT_TRANSITIVE_DEPENDENCIES: LazyLock<BuiltinView> = LazyLock::new(|| {
6331 BuiltinView {
6332 name: "mz_object_transitive_dependencies",
6333 schema: MZ_INTERNAL_SCHEMA,
6334 oid: oid::VIEW_MZ_OBJECT_TRANSITIVE_DEPENDENCIES_OID,
6335 desc: RelationDesc::builder()
6336 .with_column("object_id", SqlScalarType::String.nullable(false))
6337 .with_column(
6338 "referenced_object_id",
6339 SqlScalarType::String.nullable(false),
6340 )
6341 .with_key(vec![0, 1])
6342 .finish(),
6343 column_comments: BTreeMap::from_iter([
6344 (
6345 "object_id",
6346 "The ID of the dependent object. Corresponds to `mz_objects.id`.",
6347 ),
6348 (
6349 "referenced_object_id",
6350 "The ID of the (possibly transitively) referenced object. Corresponds to `mz_objects.id`.",
6351 ),
6352 ]),
6353 sql: "
6354WITH MUTUALLY RECURSIVE
6355 reach(object_id text, referenced_object_id text) AS (
6356 SELECT object_id, referenced_object_id FROM mz_internal.mz_object_dependencies
6357 UNION
6358 SELECT x, z FROM reach r1(x, y) JOIN reach r2(y, z) USING(y)
6359 )
6360SELECT object_id, referenced_object_id FROM reach;",
6361 access: vec![PUBLIC_SELECT],
6362 }
6363});
6364
6365pub static MZ_COMPUTE_EXPORTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6366 name: "mz_compute_exports",
6367 schema: MZ_INTROSPECTION_SCHEMA,
6368 oid: oid::VIEW_MZ_COMPUTE_EXPORTS_OID,
6369 desc: RelationDesc::builder()
6370 .with_column("export_id", SqlScalarType::String.nullable(false))
6371 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
6372 .finish(),
6373 column_comments: BTreeMap::from_iter([
6374 (
6375 "export_id",
6376 "The ID of the index, materialized view, or subscription exported by the dataflow. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, or `mz_internal.mz_subscriptions`.",
6377 ),
6378 (
6379 "dataflow_id",
6380 "The ID of the dataflow. Corresponds to `mz_dataflows.id`.",
6381 ),
6382 ]),
6383 sql: "
6384SELECT export_id, dataflow_id
6385FROM mz_introspection.mz_compute_exports_per_worker
6386WHERE worker_id = 0",
6387 access: vec![PUBLIC_SELECT],
6388});
6389
6390pub static MZ_COMPUTE_FRONTIERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6391 name: "mz_compute_frontiers",
6392 schema: MZ_INTROSPECTION_SCHEMA,
6393 oid: oid::VIEW_MZ_COMPUTE_FRONTIERS_OID,
6394 desc: RelationDesc::builder()
6395 .with_column("export_id", SqlScalarType::String.nullable(false))
6396 .with_column("time", SqlScalarType::MzTimestamp.nullable(false))
6397 .with_key(vec![0])
6398 .finish(),
6399 column_comments: BTreeMap::from_iter([
6400 (
6401 "export_id",
6402 "The ID of the dataflow export. Corresponds to `mz_compute_exports.export_id`.",
6403 ),
6404 (
6405 "time",
6406 "The next timestamp at which the dataflow output may change.",
6407 ),
6408 ]),
6409 sql: "SELECT
6410 export_id, pg_catalog.min(time) AS time
6411FROM mz_introspection.mz_compute_frontiers_per_worker
6412GROUP BY export_id",
6413 access: vec![PUBLIC_SELECT],
6414});
6415
6416pub static MZ_DATAFLOW_CHANNEL_OPERATORS_PER_WORKER: LazyLock<BuiltinView> =
6417 LazyLock::new(|| BuiltinView {
6418 name: "mz_dataflow_channel_operators_per_worker",
6419 schema: MZ_INTROSPECTION_SCHEMA,
6420 oid: oid::VIEW_MZ_DATAFLOW_CHANNEL_OPERATORS_PER_WORKER_OID,
6421 desc: RelationDesc::builder()
6422 .with_column("id", SqlScalarType::UInt64.nullable(false))
6423 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
6424 .with_column("from_operator_id", SqlScalarType::UInt64.nullable(true))
6425 .with_column(
6426 "from_operator_address",
6427 SqlScalarType::List {
6428 element_type: Box::new(SqlScalarType::UInt64),
6429 custom_id: None,
6430 }
6431 .nullable(true),
6432 )
6433 .with_column("to_operator_id", SqlScalarType::UInt64.nullable(true))
6434 .with_column(
6435 "to_operator_address",
6436 SqlScalarType::List {
6437 element_type: Box::new(SqlScalarType::UInt64),
6438 custom_id: None,
6439 }
6440 .nullable(true),
6441 )
6442 .with_column("type", SqlScalarType::String.nullable(false))
6443 .finish(),
6444 column_comments: BTreeMap::new(),
6445 sql: "
6446WITH
6447channel_addresses(id, worker_id, address, from_index, to_index, type) AS (
6448 SELECT id, worker_id, address, from_index, to_index, type
6449 FROM mz_introspection.mz_dataflow_channels_per_worker mdc
6450 INNER JOIN mz_introspection.mz_dataflow_addresses_per_worker mda
6451 USING (id, worker_id)
6452),
6453channel_operator_addresses(id, worker_id, from_address, to_address, type) AS (
6454 SELECT id, worker_id,
6455 address || from_index AS from_address,
6456 address || to_index AS to_address,
6457 type
6458 FROM channel_addresses
6459),
6460operator_addresses(id, worker_id, address) AS (
6461 SELECT id, worker_id, address
6462 FROM mz_introspection.mz_dataflow_addresses_per_worker mda
6463 INNER JOIN mz_introspection.mz_dataflow_operators_per_worker mdo
6464 USING (id, worker_id)
6465)
6466SELECT coa.id,
6467 coa.worker_id,
6468 from_ops.id AS from_operator_id,
6469 coa.from_address AS from_operator_address,
6470 to_ops.id AS to_operator_id,
6471 coa.to_address AS to_operator_address,
6472 coa.type
6473FROM channel_operator_addresses coa
6474 LEFT OUTER JOIN operator_addresses from_ops
6475 ON coa.from_address = from_ops.address AND
6476 coa.worker_id = from_ops.worker_id
6477 LEFT OUTER JOIN operator_addresses to_ops
6478 ON coa.to_address = to_ops.address AND
6479 coa.worker_id = to_ops.worker_id
6480",
6481 access: vec![PUBLIC_SELECT],
6482 });
6483
6484pub static MZ_DATAFLOW_CHANNEL_OPERATORS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6485 name: "mz_dataflow_channel_operators",
6486 schema: MZ_INTROSPECTION_SCHEMA,
6487 oid: oid::VIEW_MZ_DATAFLOW_CHANNEL_OPERATORS_OID,
6488 desc: RelationDesc::builder()
6489 .with_column("id", SqlScalarType::UInt64.nullable(false))
6490 .with_column("from_operator_id", SqlScalarType::UInt64.nullable(true))
6491 .with_column(
6492 "from_operator_address",
6493 SqlScalarType::List {
6494 element_type: Box::new(SqlScalarType::UInt64),
6495 custom_id: None,
6496 }
6497 .nullable(true),
6498 )
6499 .with_column("to_operator_id", SqlScalarType::UInt64.nullable(true))
6500 .with_column(
6501 "to_operator_address",
6502 SqlScalarType::List {
6503 element_type: Box::new(SqlScalarType::UInt64),
6504 custom_id: None,
6505 }
6506 .nullable(true),
6507 )
6508 .with_column("type", SqlScalarType::String.nullable(false))
6509 .finish(),
6510 column_comments: BTreeMap::from_iter([
6511 (
6512 "id",
6513 "The ID of the channel. Corresponds to `mz_dataflow_channels.id`.",
6514 ),
6515 (
6516 "from_operator_id",
6517 "The ID of the source of the channel. Corresponds to `mz_dataflow_operators.id`.",
6518 ),
6519 (
6520 "from_operator_address",
6521 "The address of the source of the channel. Corresponds to `mz_dataflow_addresses.address`.",
6522 ),
6523 (
6524 "to_operator_id",
6525 "The ID of the target of the channel. Corresponds to `mz_dataflow_operators.id`.",
6526 ),
6527 (
6528 "to_operator_address",
6529 "The address of the target of the channel. Corresponds to `mz_dataflow_addresses.address`.",
6530 ),
6531 ("type", "The container type of the channel."),
6532 ]),
6533 sql: "
6534SELECT id, from_operator_id, from_operator_address, to_operator_id, to_operator_address, type
6535FROM mz_introspection.mz_dataflow_channel_operators_per_worker
6536WHERE worker_id = 0",
6537 access: vec![PUBLIC_SELECT],
6538});
6539
6540pub static MZ_COMPUTE_IMPORT_FRONTIERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6541 name: "mz_compute_import_frontiers",
6542 schema: MZ_INTROSPECTION_SCHEMA,
6543 oid: oid::VIEW_MZ_COMPUTE_IMPORT_FRONTIERS_OID,
6544 desc: RelationDesc::builder()
6545 .with_column("export_id", SqlScalarType::String.nullable(false))
6546 .with_column("import_id", SqlScalarType::String.nullable(false))
6547 .with_column("time", SqlScalarType::MzTimestamp.nullable(false))
6548 .with_key(vec![0, 1])
6549 .finish(),
6550 column_comments: BTreeMap::from_iter([
6551 (
6552 "export_id",
6553 "The ID of the dataflow export. Corresponds to `mz_compute_exports.export_id`.",
6554 ),
6555 (
6556 "import_id",
6557 "The ID of the dataflow import. Corresponds to `mz_catalog.mz_sources.id` or `mz_catalog.mz_tables.id` or `mz_compute_exports.export_id`.",
6558 ),
6559 (
6560 "time",
6561 "The next timestamp at which the dataflow input may change.",
6562 ),
6563 ]),
6564 sql: "SELECT
6565 export_id, import_id, pg_catalog.min(time) AS time
6566FROM mz_introspection.mz_compute_import_frontiers_per_worker
6567GROUP BY export_id, import_id",
6568 access: vec![PUBLIC_SELECT],
6569});
6570
6571pub static MZ_RECORDS_PER_DATAFLOW_OPERATOR_PER_WORKER: LazyLock<BuiltinView> =
6572 LazyLock::new(|| BuiltinView {
6573 name: "mz_records_per_dataflow_operator_per_worker",
6574 schema: MZ_INTROSPECTION_SCHEMA,
6575 oid: oid::VIEW_MZ_RECORDS_PER_DATAFLOW_OPERATOR_PER_WORKER_OID,
6576 desc: RelationDesc::builder()
6577 .with_column("id", SqlScalarType::UInt64.nullable(false))
6578 .with_column("name", SqlScalarType::String.nullable(false))
6579 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
6580 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
6581 .with_column("records", SqlScalarType::Int64.nullable(true))
6582 .with_column("batches", SqlScalarType::Int64.nullable(true))
6583 .with_column("size", SqlScalarType::Int64.nullable(true))
6584 .with_column("capacity", SqlScalarType::Int64.nullable(true))
6585 .with_column("allocations", SqlScalarType::Int64.nullable(true))
6586 .finish(),
6587 column_comments: BTreeMap::new(),
6588 sql: "
6589SELECT
6590 dod.id,
6591 dod.name,
6592 dod.worker_id,
6593 dod.dataflow_id,
6594 ar_size.records AS records,
6595 ar_size.batches AS batches,
6596 ar_size.size AS size,
6597 ar_size.capacity AS capacity,
6598 ar_size.allocations AS allocations
6599FROM
6600 mz_introspection.mz_dataflow_operator_dataflows_per_worker dod
6601 LEFT OUTER JOIN mz_introspection.mz_arrangement_sizes_per_worker ar_size ON
6602 dod.id = ar_size.operator_id AND
6603 dod.worker_id = ar_size.worker_id",
6604 access: vec![PUBLIC_SELECT],
6605 });
6606
6607pub static MZ_RECORDS_PER_DATAFLOW_OPERATOR: LazyLock<BuiltinView> =
6608 LazyLock::new(|| BuiltinView {
6609 name: "mz_records_per_dataflow_operator",
6610 schema: MZ_INTROSPECTION_SCHEMA,
6611 oid: oid::VIEW_MZ_RECORDS_PER_DATAFLOW_OPERATOR_OID,
6612 desc: RelationDesc::builder()
6613 .with_column("id", SqlScalarType::UInt64.nullable(false))
6614 .with_column("name", SqlScalarType::String.nullable(false))
6615 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
6616 .with_column("records", SqlScalarType::Int64.nullable(true))
6617 .with_column("batches", SqlScalarType::Int64.nullable(true))
6618 .with_column("size", SqlScalarType::Int64.nullable(true))
6619 .with_column("capacity", SqlScalarType::Int64.nullable(true))
6620 .with_column("allocations", SqlScalarType::Int64.nullable(true))
6621 .with_key(vec![0, 1, 2])
6622 .finish(),
6623 column_comments: BTreeMap::from_iter([
6624 (
6625 "id",
6626 "The ID of the operator. Corresponds to `mz_dataflow_operators.id`.",
6627 ),
6628 ("name", "The internal name of the operator."),
6629 (
6630 "dataflow_id",
6631 "The ID of the dataflow. Corresponds to `mz_dataflows.id`.",
6632 ),
6633 ("records", "The number of records in the operator."),
6634 ("batches", "The number of batches in the dataflow."),
6635 ("size", "The utilized size in bytes of the arrangement."),
6636 (
6637 "capacity",
6638 "The capacity in bytes of the arrangement. Can be larger than the size.",
6639 ),
6640 (
6641 "allocations",
6642 "The number of separate memory allocations backing the arrangement.",
6643 ),
6644 ]),
6645 sql: "
6646SELECT
6647 id,
6648 name,
6649 dataflow_id,
6650 SUM(records)::int8 AS records,
6651 SUM(batches)::int8 AS batches,
6652 SUM(size)::int8 AS size,
6653 SUM(capacity)::int8 AS capacity,
6654 SUM(allocations)::int8 AS allocations
6655FROM mz_introspection.mz_records_per_dataflow_operator_per_worker
6656GROUP BY id, name, dataflow_id",
6657 access: vec![PUBLIC_SELECT],
6658 });
6659
6660pub static MZ_RECORDS_PER_DATAFLOW_PER_WORKER: LazyLock<BuiltinView> =
6661 LazyLock::new(|| BuiltinView {
6662 name: "mz_records_per_dataflow_per_worker",
6663 schema: MZ_INTROSPECTION_SCHEMA,
6664 oid: oid::VIEW_MZ_RECORDS_PER_DATAFLOW_PER_WORKER_OID,
6665 desc: RelationDesc::builder()
6666 .with_column("id", SqlScalarType::UInt64.nullable(false))
6667 .with_column("name", SqlScalarType::String.nullable(false))
6668 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
6669 .with_column("records", SqlScalarType::Int64.nullable(true))
6670 .with_column("batches", SqlScalarType::Int64.nullable(true))
6671 .with_column("size", SqlScalarType::Int64.nullable(true))
6672 .with_column("capacity", SqlScalarType::Int64.nullable(true))
6673 .with_column("allocations", SqlScalarType::Int64.nullable(true))
6674 .with_key(vec![0, 1, 2])
6675 .finish(),
6676 column_comments: BTreeMap::new(),
6677 sql: "
6678SELECT
6679 rdo.dataflow_id as id,
6680 dfs.name,
6681 rdo.worker_id,
6682 SUM(rdo.records)::int8 as records,
6683 SUM(rdo.batches)::int8 as batches,
6684 SUM(rdo.size)::int8 as size,
6685 SUM(rdo.capacity)::int8 as capacity,
6686 SUM(rdo.allocations)::int8 as allocations
6687FROM
6688 mz_introspection.mz_records_per_dataflow_operator_per_worker rdo,
6689 mz_introspection.mz_dataflows_per_worker dfs
6690WHERE
6691 rdo.dataflow_id = dfs.id AND
6692 rdo.worker_id = dfs.worker_id
6693GROUP BY
6694 rdo.dataflow_id,
6695 dfs.name,
6696 rdo.worker_id",
6697 access: vec![PUBLIC_SELECT],
6698 });
6699
6700pub static MZ_RECORDS_PER_DATAFLOW: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6701 name: "mz_records_per_dataflow",
6702 schema: MZ_INTROSPECTION_SCHEMA,
6703 oid: oid::VIEW_MZ_RECORDS_PER_DATAFLOW_OID,
6704 desc: RelationDesc::builder()
6705 .with_column("id", SqlScalarType::UInt64.nullable(false))
6706 .with_column("name", SqlScalarType::String.nullable(false))
6707 .with_column("records", SqlScalarType::Int64.nullable(true))
6708 .with_column("batches", SqlScalarType::Int64.nullable(true))
6709 .with_column("size", SqlScalarType::Int64.nullable(true))
6710 .with_column("capacity", SqlScalarType::Int64.nullable(true))
6711 .with_column("allocations", SqlScalarType::Int64.nullable(true))
6712 .with_key(vec![0, 1])
6713 .finish(),
6714 column_comments: BTreeMap::from_iter([
6715 (
6716 "id",
6717 "The ID of the dataflow. Corresponds to `mz_dataflows.id`.",
6718 ),
6719 ("name", "The internal name of the dataflow."),
6720 ("records", "The number of records in the dataflow."),
6721 ("batches", "The number of batches in the dataflow."),
6722 ("size", "The utilized size in bytes of the arrangements."),
6723 (
6724 "capacity",
6725 "The capacity in bytes of the arrangements. Can be larger than the size.",
6726 ),
6727 (
6728 "allocations",
6729 "The number of separate memory allocations backing the arrangements.",
6730 ),
6731 ]),
6732 sql: "
6733SELECT
6734 id,
6735 name,
6736 SUM(records)::int8 as records,
6737 SUM(batches)::int8 as batches,
6738 SUM(size)::int8 as size,
6739 SUM(capacity)::int8 as capacity,
6740 SUM(allocations)::int8 as allocations
6741FROM
6742 mz_introspection.mz_records_per_dataflow_per_worker
6743GROUP BY
6744 id,
6745 name",
6746 access: vec![PUBLIC_SELECT],
6747});
6748
6749pub static PG_NAMESPACE_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6755 name: "pg_namespace_all_databases",
6756 schema: MZ_INTERNAL_SCHEMA,
6757 oid: oid::VIEW_PG_NAMESPACE_ALL_DATABASES_OID,
6758 desc: RelationDesc::builder()
6759 .with_column("oid", SqlScalarType::Oid.nullable(false))
6760 .with_column("nspname", SqlScalarType::String.nullable(false))
6761 .with_column("nspowner", SqlScalarType::Oid.nullable(false))
6762 .with_column(
6763 "nspacl",
6764 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
6765 )
6766 .with_column("database_name", SqlScalarType::String.nullable(true))
6767 .finish(),
6768 column_comments: BTreeMap::new(),
6769 sql: "
6770SELECT
6771 s.oid AS oid,
6772 s.name AS nspname,
6773 role_owner.oid AS nspowner,
6774 NULL::pg_catalog.text[] AS nspacl,
6775 d.name as database_name
6776FROM mz_catalog.mz_schemas s
6777LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
6778JOIN mz_catalog.mz_roles role_owner ON role_owner.id = s.owner_id",
6779 access: vec![PUBLIC_SELECT],
6780});
6781
6782pub const PG_NAMESPACE_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
6783 name: "pg_namespace_all_databases_ind",
6784 schema: MZ_INTERNAL_SCHEMA,
6785 oid: oid::INDEX_PG_NAMESPACE_ALL_DATABASES_IND_OID,
6786 sql: "IN CLUSTER mz_catalog_server
6787ON mz_internal.pg_namespace_all_databases (nspname)",
6788 is_retained_metrics_object: false,
6789};
6790
6791pub static PG_NAMESPACE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6792 name: "pg_namespace",
6793 schema: PG_CATALOG_SCHEMA,
6794 oid: oid::VIEW_PG_NAMESPACE_OID,
6795 desc: RelationDesc::builder()
6796 .with_column("oid", SqlScalarType::Oid.nullable(false))
6797 .with_column("nspname", SqlScalarType::String.nullable(false))
6798 .with_column("nspowner", SqlScalarType::Oid.nullable(false))
6799 .with_column(
6800 "nspacl",
6801 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
6802 )
6803 .finish(),
6804 column_comments: BTreeMap::new(),
6805 sql: "
6806SELECT
6807 oid, nspname, nspowner, nspacl
6808FROM mz_internal.pg_namespace_all_databases
6809WHERE database_name IS NULL OR database_name = pg_catalog.current_database();",
6810 access: vec![PUBLIC_SELECT],
6811});
6812
6813pub static PG_CLASS_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| {
6819 BuiltinView {
6820 name: "pg_class_all_databases",
6821 schema: MZ_INTERNAL_SCHEMA,
6822 oid: oid::VIEW_PG_CLASS_ALL_DATABASES_OID,
6823 desc: RelationDesc::builder()
6824 .with_column("oid", SqlScalarType::Oid.nullable(false))
6825 .with_column("relname", SqlScalarType::String.nullable(false))
6826 .with_column("relnamespace", SqlScalarType::Oid.nullable(false))
6827 .with_column("reloftype", SqlScalarType::Oid.nullable(false))
6828 .with_column("relowner", SqlScalarType::Oid.nullable(false))
6829 .with_column("relam", SqlScalarType::Oid.nullable(false))
6830 .with_column("reltablespace", SqlScalarType::Oid.nullable(false))
6831 .with_column("reltuples", SqlScalarType::Float32.nullable(false))
6832 .with_column("reltoastrelid", SqlScalarType::Oid.nullable(false))
6833 .with_column("relhasindex", SqlScalarType::Bool.nullable(false))
6834 .with_column("relpersistence", SqlScalarType::PgLegacyChar.nullable(false))
6835 .with_column("relkind", SqlScalarType::String.nullable(true))
6836 .with_column("relnatts", SqlScalarType::Int16.nullable(false))
6837 .with_column("relchecks", SqlScalarType::Int16.nullable(false))
6838 .with_column("relhasrules", SqlScalarType::Bool.nullable(false))
6839 .with_column("relhastriggers", SqlScalarType::Bool.nullable(false))
6840 .with_column("relhassubclass", SqlScalarType::Bool.nullable(false))
6841 .with_column("relrowsecurity", SqlScalarType::Bool.nullable(false))
6842 .with_column("relforcerowsecurity", SqlScalarType::Bool.nullable(false))
6843 .with_column("relreplident", SqlScalarType::PgLegacyChar.nullable(false))
6844 .with_column("relispartition", SqlScalarType::Bool.nullable(false))
6845 .with_column("relhasoids", SqlScalarType::Bool.nullable(false))
6846 .with_column("reloptions", SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true))
6847 .with_column("database_name", SqlScalarType::String.nullable(true))
6848 .finish(),
6849 column_comments: BTreeMap::new(),
6850 sql: "
6851SELECT
6852 class_objects.oid,
6853 class_objects.name AS relname,
6854 mz_schemas.oid AS relnamespace,
6855 -- MZ doesn't support typed tables so reloftype is filled with 0
6856 0::pg_catalog.oid AS reloftype,
6857 role_owner.oid AS relowner,
6858 0::pg_catalog.oid AS relam,
6859 -- MZ doesn't have tablespaces so reltablespace is filled in with 0 implying the default tablespace
6860 0::pg_catalog.oid AS reltablespace,
6861 -- MZ doesn't support (estimated) row counts currently.
6862 -- Postgres defines a value of -1 as unknown.
6863 -1::float4 as reltuples,
6864 -- MZ doesn't use TOAST tables so reltoastrelid is filled with 0
6865 0::pg_catalog.oid AS reltoastrelid,
6866 EXISTS (SELECT id, oid, name, on_id, cluster_id FROM mz_catalog.mz_indexes where mz_indexes.on_id = class_objects.id) AS relhasindex,
6867 -- MZ doesn't have unlogged tables and because of (https://github.com/MaterializeInc/database-issues/issues/2689)
6868 -- temporary objects don't show up here, so relpersistence is filled with 'p' for permanent.
6869 -- TODO(jkosh44): update this column when issue is resolved.
6870 'p'::pg_catalog.\"char\" AS relpersistence,
6871 CASE
6872 WHEN class_objects.type = 'table' THEN 'r'
6873 WHEN class_objects.type = 'source' THEN 'r'
6874 WHEN class_objects.type = 'index' THEN 'i'
6875 WHEN class_objects.type = 'view' THEN 'v'
6876 WHEN class_objects.type = 'materialized-view' THEN 'm'
6877 END relkind,
6878 COALESCE(
6879 (
6880 SELECT count(*)::pg_catalog.int2
6881 FROM mz_catalog.mz_columns
6882 WHERE mz_columns.id = class_objects.id
6883 ),
6884 0::pg_catalog.int2
6885 ) AS relnatts,
6886 -- MZ doesn't support CHECK constraints so relchecks is filled with 0
6887 0::pg_catalog.int2 AS relchecks,
6888 -- MZ doesn't support creating rules so relhasrules is filled with false
6889 false AS relhasrules,
6890 -- MZ doesn't support creating triggers so relhastriggers is filled with false
6891 false AS relhastriggers,
6892 -- MZ doesn't support table inheritance or partitions so relhassubclass is filled with false
6893 false AS relhassubclass,
6894 -- MZ doesn't have row level security so relrowsecurity and relforcerowsecurity is filled with false
6895 false AS relrowsecurity,
6896 false AS relforcerowsecurity,
6897 -- MZ doesn't support replication so relreplident is filled with 'd' for default
6898 'd'::pg_catalog.\"char\" AS relreplident,
6899 -- MZ doesn't support table partitioning so relispartition is filled with false
6900 false AS relispartition,
6901 -- PG removed relhasoids in v12 so it's filled with false
6902 false AS relhasoids,
6903 -- MZ doesn't support options for relations
6904 NULL::pg_catalog.text[] as reloptions,
6905 d.name as database_name
6906FROM (
6907 -- pg_class catalogs relations and indexes
6908 SELECT id, oid, schema_id, name, type, owner_id FROM mz_catalog.mz_relations
6909 UNION ALL
6910 SELECT mz_indexes.id, mz_indexes.oid, mz_relations.schema_id, mz_indexes.name, 'index' AS type, mz_indexes.owner_id
6911 FROM mz_catalog.mz_indexes
6912 JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
6913) AS class_objects
6914JOIN mz_catalog.mz_schemas ON mz_schemas.id = class_objects.schema_id
6915LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
6916JOIN mz_catalog.mz_roles role_owner ON role_owner.id = class_objects.owner_id",
6917 access: vec![PUBLIC_SELECT],
6918 }
6919});
6920
6921pub const PG_CLASS_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
6922 name: "pg_class_all_databases_ind",
6923 schema: MZ_INTERNAL_SCHEMA,
6924 oid: oid::INDEX_PG_CLASS_ALL_DATABASES_IND_OID,
6925 sql: "IN CLUSTER mz_catalog_server
6926ON mz_internal.pg_class_all_databases (relname)",
6927 is_retained_metrics_object: false,
6928};
6929
6930pub static PG_CLASS: LazyLock<BuiltinView> = LazyLock::new(|| {
6931 BuiltinView {
6932 name: "pg_class",
6933 schema: PG_CATALOG_SCHEMA,
6934 oid: oid::VIEW_PG_CLASS_OID,
6935 desc: RelationDesc::builder()
6936 .with_column("oid", SqlScalarType::Oid.nullable(false))
6937 .with_column("relname", SqlScalarType::String.nullable(false))
6938 .with_column("relnamespace", SqlScalarType::Oid.nullable(false))
6939 .with_column("reloftype", SqlScalarType::Oid.nullable(false))
6940 .with_column("relowner", SqlScalarType::Oid.nullable(false))
6941 .with_column("relam", SqlScalarType::Oid.nullable(false))
6942 .with_column("reltablespace", SqlScalarType::Oid.nullable(false))
6943 .with_column("reltuples", SqlScalarType::Float32.nullable(false))
6944 .with_column("reltoastrelid", SqlScalarType::Oid.nullable(false))
6945 .with_column("relhasindex", SqlScalarType::Bool.nullable(false))
6946 .with_column("relpersistence", SqlScalarType::PgLegacyChar.nullable(false))
6947 .with_column("relkind", SqlScalarType::String.nullable(true))
6948 .with_column("relnatts", SqlScalarType::Int16.nullable(false))
6949 .with_column("relchecks", SqlScalarType::Int16.nullable(false))
6950 .with_column("relhasrules", SqlScalarType::Bool.nullable(false))
6951 .with_column("relhastriggers", SqlScalarType::Bool.nullable(false))
6952 .with_column("relhassubclass", SqlScalarType::Bool.nullable(false))
6953 .with_column("relrowsecurity", SqlScalarType::Bool.nullable(false))
6954 .with_column("relforcerowsecurity", SqlScalarType::Bool.nullable(false))
6955 .with_column("relreplident", SqlScalarType::PgLegacyChar.nullable(false))
6956 .with_column("relispartition", SqlScalarType::Bool.nullable(false))
6957 .with_column("relhasoids", SqlScalarType::Bool.nullable(false))
6958 .with_column(
6959 "reloptions",
6960 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
6961 )
6962 .finish(),
6963 column_comments: BTreeMap::new(),
6964 sql: "
6965SELECT
6966 oid, relname, relnamespace, reloftype, relowner, relam, reltablespace, reltuples, reltoastrelid,
6967 relhasindex, relpersistence, relkind, relnatts, relchecks, relhasrules, relhastriggers, relhassubclass,
6968 relrowsecurity, relforcerowsecurity, relreplident, relispartition, relhasoids, reloptions
6969FROM mz_internal.pg_class_all_databases
6970WHERE database_name IS NULL OR database_name = pg_catalog.current_database();
6971",
6972 access: vec![PUBLIC_SELECT],
6973}
6974});
6975
6976pub static PG_DEPEND: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
6977 name: "pg_depend",
6978 schema: PG_CATALOG_SCHEMA,
6979 oid: oid::VIEW_PG_DEPEND_OID,
6980 desc: RelationDesc::builder()
6981 .with_column("classid", SqlScalarType::Oid.nullable(true))
6982 .with_column("objid", SqlScalarType::Oid.nullable(false))
6983 .with_column("objsubid", SqlScalarType::Int32.nullable(false))
6984 .with_column("refclassid", SqlScalarType::Oid.nullable(true))
6985 .with_column("refobjid", SqlScalarType::Oid.nullable(false))
6986 .with_column("refobjsubid", SqlScalarType::Int32.nullable(false))
6987 .with_column("deptype", SqlScalarType::PgLegacyChar.nullable(false))
6988 .finish(),
6989 column_comments: BTreeMap::new(),
6990 sql: "
6991WITH class_objects AS (
6992 SELECT
6993 CASE
6994 WHEN type = 'table' THEN 'pg_tables'::pg_catalog.regclass::pg_catalog.oid
6995 WHEN type = 'source' THEN 'pg_tables'::pg_catalog.regclass::pg_catalog.oid
6996 WHEN type = 'view' THEN 'pg_views'::pg_catalog.regclass::pg_catalog.oid
6997 WHEN type = 'materialized-view' THEN 'pg_matviews'::pg_catalog.regclass::pg_catalog.oid
6998 END classid,
6999 id,
7000 oid,
7001 schema_id
7002 FROM mz_catalog.mz_relations
7003 UNION ALL
7004 SELECT
7005 'pg_index'::pg_catalog.regclass::pg_catalog.oid AS classid,
7006 i.id,
7007 i.oid,
7008 r.schema_id
7009 FROM mz_catalog.mz_indexes i
7010 JOIN mz_catalog.mz_relations r ON i.on_id = r.id
7011),
7012
7013current_objects AS (
7014 SELECT class_objects.*
7015 FROM class_objects
7016 JOIN mz_catalog.mz_schemas ON mz_schemas.id = class_objects.schema_id
7017 LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
7018 -- This filter is tricky, as it filters out not just objects outside the
7019 -- database, but *dependencies* on objects outside this database. It's not
7020 -- clear that this is the right choice, but because PostgreSQL doesn't
7021 -- support cross-database references, it's not clear that the other choice
7022 -- is better.
7023 WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()
7024)
7025
7026SELECT
7027 objects.classid::pg_catalog.oid,
7028 objects.oid::pg_catalog.oid AS objid,
7029 0::pg_catalog.int4 AS objsubid,
7030 dependents.classid::pg_catalog.oid AS refclassid,
7031 dependents.oid::pg_catalog.oid AS refobjid,
7032 0::pg_catalog.int4 AS refobjsubid,
7033 'n'::pg_catalog.char AS deptype
7034FROM mz_internal.mz_object_dependencies
7035JOIN current_objects objects ON object_id = objects.id
7036JOIN current_objects dependents ON referenced_object_id = dependents.id",
7037 access: vec![PUBLIC_SELECT],
7038});
7039
7040pub static PG_DATABASE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7041 name: "pg_database",
7042 schema: PG_CATALOG_SCHEMA,
7043 oid: oid::VIEW_PG_DATABASE_OID,
7044 desc: RelationDesc::builder()
7045 .with_column("oid", SqlScalarType::Oid.nullable(false))
7046 .with_column("datname", SqlScalarType::String.nullable(false))
7047 .with_column("datdba", SqlScalarType::Oid.nullable(false))
7048 .with_column("encoding", SqlScalarType::Int32.nullable(false))
7049 .with_column("datistemplate", SqlScalarType::Bool.nullable(false))
7050 .with_column("datallowconn", SqlScalarType::Bool.nullable(false))
7051 .with_column("datcollate", SqlScalarType::String.nullable(false))
7052 .with_column("datctype", SqlScalarType::String.nullable(false))
7053 .with_column(
7054 "datacl",
7055 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
7056 )
7057 .with_key(vec![0])
7058 .finish(),
7059 column_comments: BTreeMap::new(),
7060 sql: "SELECT
7061 d.oid as oid,
7062 d.name as datname,
7063 role_owner.oid as datdba,
7064 6 as encoding,
7065 -- Materialize doesn't support database cloning.
7066 FALSE AS datistemplate,
7067 TRUE AS datallowconn,
7068 'C' as datcollate,
7069 'C' as datctype,
7070 NULL::pg_catalog.text[] as datacl
7071FROM mz_catalog.mz_databases d
7072JOIN mz_catalog.mz_roles role_owner ON role_owner.id = d.owner_id",
7073 access: vec![PUBLIC_SELECT],
7074});
7075
7076pub static PG_INDEX: LazyLock<BuiltinView> = LazyLock::new(|| {
7077 BuiltinView {
7078 name: "pg_index",
7079 schema: PG_CATALOG_SCHEMA,
7080 oid: oid::VIEW_PG_INDEX_OID,
7081 desc: RelationDesc::builder()
7082 .with_column("indexrelid", SqlScalarType::Oid.nullable(false))
7083 .with_column("indrelid", SqlScalarType::Oid.nullable(false))
7084 .with_column("indnatts", SqlScalarType::Int16.nullable(false))
7085 .with_column("indisunique", SqlScalarType::Bool.nullable(false))
7086 .with_column("indisprimary", SqlScalarType::Bool.nullable(false))
7087 .with_column("indimmediate", SqlScalarType::Bool.nullable(false))
7088 .with_column("indisclustered", SqlScalarType::Bool.nullable(false))
7089 .with_column("indisvalid", SqlScalarType::Bool.nullable(false))
7090 .with_column("indisreplident", SqlScalarType::Bool.nullable(false))
7091 .with_column("indkey", SqlScalarType::Int2Vector.nullable(false))
7092 .with_column("indoption", SqlScalarType::Int2Vector.nullable(false))
7093 .with_column("indexprs", SqlScalarType::String.nullable(true))
7094 .with_column("indpred", SqlScalarType::String.nullable(true))
7095 .with_key(vec![0, 1])
7096 .finish(),
7097 column_comments: BTreeMap::new(),
7098 sql: "SELECT
7099 mz_indexes.oid AS indexrelid,
7100 mz_relations.oid AS indrelid,
7101 COALESCE(
7102 (
7103 SELECT count(*)::pg_catalog.int2
7104 FROM mz_catalog.mz_columns
7105 JOIN mz_catalog.mz_relations mri ON mz_columns.id = mri.id
7106 WHERE mri.oid = mz_catalog.mz_relations.oid
7107 ),
7108 0::pg_catalog.int2
7109 ) AS indnatts,
7110 -- MZ doesn't support creating unique indexes so indisunique is filled with false
7111 false::pg_catalog.bool AS indisunique,
7112 false::pg_catalog.bool AS indisprimary,
7113 -- MZ doesn't support unique indexes so indimmediate is filled with false
7114 false::pg_catalog.bool AS indimmediate,
7115 -- MZ doesn't support CLUSTER so indisclustered is filled with false
7116 false::pg_catalog.bool AS indisclustered,
7117 -- MZ never creates invalid indexes so indisvalid is filled with true
7118 true::pg_catalog.bool AS indisvalid,
7119 -- MZ doesn't support replication so indisreplident is filled with false
7120 false::pg_catalog.bool AS indisreplident,
7121 -- Return zero if the index attribute is not a simple column reference, column position otherwise
7122 pg_catalog.string_agg(coalesce(mz_index_columns.on_position::int8, 0)::pg_catalog.text, ' ' ORDER BY mz_index_columns.index_position::int8)::pg_catalog.int2vector AS indkey,
7123 -- MZ doesn't have per-column flags, so returning a 0 for each column in the index
7124 pg_catalog.string_agg('0', ' ')::pg_catalog.int2vector AS indoption,
7125 -- Index expressions are returned in MZ format
7126 CASE pg_catalog.string_agg(mz_index_columns.on_expression, ' ' ORDER BY mz_index_columns.index_position::int8)
7127 WHEN NULL THEN NULL
7128 ELSE '{' || pg_catalog.string_agg(mz_index_columns.on_expression, '}, {' ORDER BY mz_index_columns.index_position::int8) || '}'
7129 END AS indexprs,
7130 -- MZ doesn't support indexes with predicates
7131 NULL::pg_catalog.text AS indpred
7132FROM mz_catalog.mz_indexes
7133JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
7134JOIN mz_catalog.mz_index_columns ON mz_index_columns.index_id = mz_indexes.id
7135JOIN mz_catalog.mz_schemas ON mz_schemas.id = mz_relations.schema_id
7136LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
7137WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()
7138GROUP BY mz_indexes.oid, mz_relations.oid",
7139 access: vec![PUBLIC_SELECT],
7140 }
7141});
7142
7143pub static PG_INDEXES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7144 name: "pg_indexes",
7145 schema: PG_CATALOG_SCHEMA,
7146 oid: oid::VIEW_PG_INDEXES_OID,
7147 desc: RelationDesc::builder()
7148 .with_column("table_catalog", SqlScalarType::String.nullable(false))
7149 .with_column("schemaname", SqlScalarType::String.nullable(false))
7150 .with_column("tablename", SqlScalarType::String.nullable(false))
7151 .with_column("indexname", SqlScalarType::String.nullable(false))
7152 .with_column("tablespace", SqlScalarType::String.nullable(true))
7153 .with_column("indexdef", SqlScalarType::String.nullable(true))
7154 .finish(),
7155 column_comments: BTreeMap::new(),
7156 sql: "SELECT
7157 current_database() as table_catalog,
7158 s.name AS schemaname,
7159 r.name AS tablename,
7160 i.name AS indexname,
7161 NULL::text AS tablespace,
7162 -- TODO(jkosh44) Fill in with actual index definition.
7163 NULL::text AS indexdef
7164FROM mz_catalog.mz_indexes i
7165JOIN mz_catalog.mz_relations r ON i.on_id = r.id
7166JOIN mz_catalog.mz_schemas s ON s.id = r.schema_id
7167LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
7168WHERE s.database_id IS NULL OR d.name = current_database()",
7169 access: vec![PUBLIC_SELECT],
7170});
7171
7172pub static PG_DESCRIPTION_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| {
7178 BuiltinView {
7179 name: "pg_description_all_databases",
7180 schema: MZ_INTERNAL_SCHEMA,
7181 oid: oid::VIEW_PG_DESCRIPTION_ALL_DATABASES_OID,
7182 desc: RelationDesc::builder()
7183 .with_column("objoid", SqlScalarType::Oid.nullable(false))
7184 .with_column("classoid", SqlScalarType::Oid.nullable(true))
7185 .with_column("objsubid", SqlScalarType::Int32.nullable(false))
7186 .with_column("description", SqlScalarType::String.nullable(false))
7187 .with_column("oid_database_name", SqlScalarType::String.nullable(true))
7188 .with_column("class_database_name", SqlScalarType::String.nullable(true))
7189 .finish(),
7190 column_comments: BTreeMap::new(),
7191 sql: "
7192(
7193 -- Gather all of the class oid's for objects that can have comments.
7194 WITH pg_classoids AS (
7195 SELECT oid, database_name as oid_database_name,
7196 (SELECT oid FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_class') AS classoid,
7197 (SELECT database_name FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_class') AS class_database_name
7198 FROM mz_internal.pg_class_all_databases
7199 UNION ALL
7200 SELECT oid, database_name as oid_database_name,
7201 (SELECT oid FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_type') AS classoid,
7202 (SELECT database_name FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_type') AS class_database_name
7203 FROM mz_internal.pg_type_all_databases
7204 UNION ALL
7205 SELECT oid, database_name as oid_database_name,
7206 (SELECT oid FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_namespace') AS classoid,
7207 (SELECT database_name FROM mz_internal.pg_class_all_databases WHERE relname = 'pg_namespace') AS class_database_name
7208 FROM mz_internal.pg_namespace_all_databases
7209 ),
7210
7211 -- Gather all of the MZ ids for objects that can have comments.
7212 mz_objects AS (
7213 SELECT id, oid, type FROM mz_catalog.mz_objects
7214 UNION ALL
7215 SELECT id, oid, 'schema' AS type FROM mz_catalog.mz_schemas
7216 )
7217 SELECT
7218 pg_classoids.oid AS objoid,
7219 pg_classoids.classoid as classoid,
7220 COALESCE(cmt.object_sub_id, 0) AS objsubid,
7221 cmt.comment AS description,
7222 -- Columns added because of the peeling. (Note that there are 2 of these here.)
7223 oid_database_name,
7224 class_database_name
7225 FROM
7226 pg_classoids
7227 JOIN
7228 mz_objects ON pg_classoids.oid = mz_objects.oid
7229 JOIN
7230 mz_internal.mz_comments AS cmt ON mz_objects.id = cmt.id AND lower(mz_objects.type) = lower(cmt.object_type)
7231)",
7232 access: vec![PUBLIC_SELECT],
7233 }
7234});
7235
7236pub const PG_DESCRIPTION_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
7237 name: "pg_description_all_databases_ind",
7238 schema: MZ_INTERNAL_SCHEMA,
7239 oid: oid::INDEX_PG_DESCRIPTION_ALL_DATABASES_IND_OID,
7240 sql: "IN CLUSTER mz_catalog_server
7241ON mz_internal.pg_description_all_databases (objoid, classoid, objsubid, description, oid_database_name, class_database_name)",
7242 is_retained_metrics_object: false,
7243};
7244
7245pub static PG_DESCRIPTION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7249 name: "pg_description",
7250 schema: PG_CATALOG_SCHEMA,
7251 oid: oid::VIEW_PG_DESCRIPTION_OID,
7252 desc: RelationDesc::builder()
7253 .with_column("objoid", SqlScalarType::Oid.nullable(false))
7254 .with_column("classoid", SqlScalarType::Oid.nullable(true))
7255 .with_column("objsubid", SqlScalarType::Int32.nullable(false))
7256 .with_column("description", SqlScalarType::String.nullable(false))
7257 .finish(),
7258 column_comments: BTreeMap::new(),
7259 sql: "
7260SELECT
7261 objoid,
7262 classoid,
7263 objsubid,
7264 description
7265FROM
7266 mz_internal.pg_description_all_databases
7267WHERE
7268 (oid_database_name IS NULL OR oid_database_name = pg_catalog.current_database()) AND
7269 (class_database_name IS NULL OR class_database_name = pg_catalog.current_database());",
7270 access: vec![PUBLIC_SELECT],
7271});
7272
7273pub static PG_TYPE_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| {
7279 BuiltinView {
7280 name: "pg_type_all_databases",
7281 schema: MZ_INTERNAL_SCHEMA,
7282 oid: oid::VIEW_PG_TYPE_ALL_DATABASES_OID,
7283 desc: RelationDesc::builder()
7284 .with_column("oid", SqlScalarType::Oid.nullable(false))
7285 .with_column("typname", SqlScalarType::String.nullable(false))
7286 .with_column("typnamespace", SqlScalarType::Oid.nullable(false))
7287 .with_column("typowner", SqlScalarType::Oid.nullable(false))
7288 .with_column("typlen", SqlScalarType::Int16.nullable(true))
7289 .with_column("typtype", SqlScalarType::PgLegacyChar.nullable(false))
7290 .with_column("typcategory", SqlScalarType::PgLegacyChar.nullable(true))
7291 .with_column("typdelim", SqlScalarType::PgLegacyChar.nullable(false))
7292 .with_column("typrelid", SqlScalarType::Oid.nullable(false))
7293 .with_column("typelem", SqlScalarType::Oid.nullable(false))
7294 .with_column("typarray", SqlScalarType::Oid.nullable(false))
7295 .with_column("typinput", SqlScalarType::RegProc.nullable(true))
7296 .with_column("typreceive", SqlScalarType::Oid.nullable(false))
7297 .with_column("typnotnull", SqlScalarType::Bool.nullable(false))
7298 .with_column("typbasetype", SqlScalarType::Oid.nullable(false))
7299 .with_column("typtypmod", SqlScalarType::Int32.nullable(false))
7300 .with_column("typcollation", SqlScalarType::Oid.nullable(false))
7301 .with_column("typdefault", SqlScalarType::String.nullable(true))
7302 .with_column("database_name", SqlScalarType::String.nullable(true))
7303 .finish(),
7304 column_comments: BTreeMap::new(),
7305 sql: "
7306SELECT
7307 mz_types.oid,
7308 mz_types.name AS typname,
7309 mz_schemas.oid AS typnamespace,
7310 role_owner.oid AS typowner,
7311 NULL::pg_catalog.int2 AS typlen,
7312 -- 'a' is used internally to denote an array type, but in postgres they show up
7313 -- as 'b'.
7314 (CASE mztype WHEN 'a' THEN 'b' ELSE mztype END)::pg_catalog.char AS typtype,
7315 (CASE category
7316 WHEN 'array' THEN 'A'
7317 WHEN 'bit-string' THEN 'V'
7318 WHEN 'boolean' THEN 'B'
7319 WHEN 'composite' THEN 'C'
7320 WHEN 'date-time' THEN 'D'
7321 WHEN 'enum' THEN 'E'
7322 WHEN 'geometric' THEN 'G'
7323 WHEN 'list' THEN 'U' -- List types are user-defined from PostgreSQL's perspective.
7324 WHEN 'network-address' THEN 'I'
7325 WHEN 'numeric' THEN 'N'
7326 WHEN 'pseudo' THEN 'P'
7327 WHEN 'string' THEN 'S'
7328 WHEN 'timespan' THEN 'T'
7329 WHEN 'user-defined' THEN 'U'
7330 WHEN 'unknown' THEN 'X'
7331 END)::pg_catalog.char AS typcategory,
7332 -- In pg only the 'box' type is not ','.
7333 ','::pg_catalog.char AS typdelim,
7334 0::pg_catalog.oid AS typrelid,
7335 coalesce(
7336 (
7337 SELECT t.oid
7338 FROM mz_catalog.mz_array_types a
7339 JOIN mz_catalog.mz_types t ON a.element_id = t.id
7340 WHERE a.id = mz_types.id
7341 ),
7342 (
7343 SELECT t.oid
7344 FROM mz_catalog.mz_list_types l
7345 JOIN mz_catalog.mz_types t ON l.element_id = t.id
7346 WHERE l.id = mz_types.id
7347 ),
7348 0
7349 ) AS typelem,
7350 coalesce(
7351 (
7352 SELECT
7353 t.oid
7354 FROM
7355 mz_catalog.mz_array_types AS a
7356 JOIN mz_catalog.mz_types AS t ON a.id = t.id
7357 WHERE
7358 a.element_id = mz_types.id
7359 ),
7360 0
7361 )
7362 AS typarray,
7363 mz_internal.mz_type_pg_metadata.typinput::pg_catalog.regproc AS typinput,
7364 COALESCE(mz_internal.mz_type_pg_metadata.typreceive, 0) AS typreceive,
7365 false::pg_catalog.bool AS typnotnull,
7366 0::pg_catalog.oid AS typbasetype,
7367 -1::pg_catalog.int4 AS typtypmod,
7368 -- MZ doesn't support COLLATE so typcollation is filled with 0
7369 0::pg_catalog.oid AS typcollation,
7370 NULL::pg_catalog.text AS typdefault,
7371 d.name as database_name
7372FROM
7373 mz_catalog.mz_types
7374 LEFT JOIN mz_internal.mz_type_pg_metadata ON mz_catalog.mz_types.id = mz_internal.mz_type_pg_metadata.id
7375 JOIN mz_catalog.mz_schemas ON mz_schemas.id = mz_types.schema_id
7376 JOIN (
7377 -- 'a' is not a supported typtype, but we use it to denote an array. It is
7378 -- converted to the correct value above.
7379 SELECT id, 'a' AS mztype FROM mz_catalog.mz_array_types
7380 UNION ALL SELECT id, 'b' FROM mz_catalog.mz_base_types
7381 UNION ALL SELECT id, 'l' FROM mz_catalog.mz_list_types
7382 UNION ALL SELECT id, 'm' FROM mz_catalog.mz_map_types
7383 UNION ALL SELECT id, 'p' FROM mz_catalog.mz_pseudo_types
7384 )
7385 AS t ON mz_types.id = t.id
7386 LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
7387 JOIN mz_catalog.mz_roles role_owner ON role_owner.id = mz_types.owner_id",
7388 access: vec![PUBLIC_SELECT],
7389 }
7390});
7391
7392pub const PG_TYPE_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
7393 name: "pg_type_all_databases_ind",
7394 schema: MZ_INTERNAL_SCHEMA,
7395 oid: oid::INDEX_PG_TYPE_ALL_DATABASES_IND_OID,
7396 sql: "IN CLUSTER mz_catalog_server
7397ON mz_internal.pg_type_all_databases (oid)",
7398 is_retained_metrics_object: false,
7399};
7400
7401pub static PG_TYPE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7402 name: "pg_type",
7403 schema: PG_CATALOG_SCHEMA,
7404 oid: oid::VIEW_PG_TYPE_OID,
7405 desc: RelationDesc::builder()
7406 .with_column("oid", SqlScalarType::Oid.nullable(false))
7407 .with_column("typname", SqlScalarType::String.nullable(false))
7408 .with_column("typnamespace", SqlScalarType::Oid.nullable(false))
7409 .with_column("typowner", SqlScalarType::Oid.nullable(false))
7410 .with_column("typlen", SqlScalarType::Int16.nullable(true))
7411 .with_column("typtype", SqlScalarType::PgLegacyChar.nullable(false))
7412 .with_column("typcategory", SqlScalarType::PgLegacyChar.nullable(true))
7413 .with_column("typdelim", SqlScalarType::PgLegacyChar.nullable(false))
7414 .with_column("typrelid", SqlScalarType::Oid.nullable(false))
7415 .with_column("typelem", SqlScalarType::Oid.nullable(false))
7416 .with_column("typarray", SqlScalarType::Oid.nullable(false))
7417 .with_column("typinput", SqlScalarType::RegProc.nullable(true))
7418 .with_column("typreceive", SqlScalarType::Oid.nullable(false))
7419 .with_column("typnotnull", SqlScalarType::Bool.nullable(false))
7420 .with_column("typbasetype", SqlScalarType::Oid.nullable(false))
7421 .with_column("typtypmod", SqlScalarType::Int32.nullable(false))
7422 .with_column("typcollation", SqlScalarType::Oid.nullable(false))
7423 .with_column("typdefault", SqlScalarType::String.nullable(true))
7424 .finish(),
7425 column_comments: BTreeMap::new(),
7426 sql: "SELECT
7427 oid, typname, typnamespace, typowner, typlen, typtype, typcategory, typdelim, typrelid, typelem,
7428 typarray, typinput, typreceive, typnotnull, typbasetype, typtypmod, typcollation, typdefault
7429FROM mz_internal.pg_type_all_databases
7430WHERE database_name IS NULL OR database_name = pg_catalog.current_database();",
7431 access: vec![PUBLIC_SELECT],
7432});
7433
7434pub static PG_ATTRIBUTE_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| {
7440 BuiltinView {
7441 name: "pg_attribute_all_databases",
7442 schema: MZ_INTERNAL_SCHEMA,
7443 oid: oid::VIEW_PG_ATTRIBUTE_ALL_DATABASES_OID,
7444 desc: RelationDesc::builder()
7445 .with_column("attrelid", SqlScalarType::Oid.nullable(false))
7446 .with_column("attname", SqlScalarType::String.nullable(false))
7447 .with_column("atttypid", SqlScalarType::Oid.nullable(false))
7448 .with_column("attlen", SqlScalarType::Int16.nullable(true))
7449 .with_column("attnum", SqlScalarType::Int16.nullable(false))
7450 .with_column("atttypmod", SqlScalarType::Int32.nullable(false))
7451 .with_column("attndims", SqlScalarType::Int16.nullable(false))
7452 .with_column("attnotnull", SqlScalarType::Bool.nullable(false))
7453 .with_column("atthasdef", SqlScalarType::Bool.nullable(false))
7454 .with_column("attidentity", SqlScalarType::PgLegacyChar.nullable(false))
7455 .with_column("attgenerated", SqlScalarType::PgLegacyChar.nullable(false))
7456 .with_column("attisdropped", SqlScalarType::Bool.nullable(false))
7457 .with_column("attcollation", SqlScalarType::Oid.nullable(false))
7458 .with_column("database_name", SqlScalarType::String.nullable(true))
7459 .with_column("pg_type_database_name", SqlScalarType::String.nullable(true))
7460 .finish(),
7461 column_comments: BTreeMap::new(),
7462 sql: "
7463SELECT
7464 class_objects.oid as attrelid,
7465 mz_columns.name as attname,
7466 mz_columns.type_oid AS atttypid,
7467 pg_type_all_databases.typlen AS attlen,
7468 position::int8::int2 as attnum,
7469 mz_columns.type_mod as atttypmod,
7470 -- dummy value, just to make go-jet's workaround work for now. Discussion:
7471 -- https://github.com/MaterializeInc/materialize/pull/34649#issuecomment-3714291409
7472 0::int2 as attndims,
7473 NOT nullable as attnotnull,
7474 mz_columns.default IS NOT NULL as atthasdef,
7475 ''::pg_catalog.\"char\" as attidentity,
7476 -- MZ doesn't support generated columns so attgenerated is filled with ''
7477 ''::pg_catalog.\"char\" as attgenerated,
7478 FALSE as attisdropped,
7479 -- MZ doesn't support COLLATE so attcollation is filled with 0
7480 0::pg_catalog.oid as attcollation,
7481 -- Columns added because of the peeling. (Note that there are 2 of these here.)
7482 d.name as database_name,
7483 pg_type_all_databases.database_name as pg_type_database_name
7484FROM (
7485 -- pg_attribute catalogs columns on relations and indexes
7486 SELECT id, oid, schema_id, name, type FROM mz_catalog.mz_relations
7487 UNION ALL
7488 SELECT mz_indexes.id, mz_indexes.oid, mz_relations.schema_id, mz_indexes.name, 'index' AS type
7489 FROM mz_catalog.mz_indexes
7490 JOIN mz_catalog.mz_relations ON mz_indexes.on_id = mz_relations.id
7491) AS class_objects
7492JOIN mz_catalog.mz_columns ON class_objects.id = mz_columns.id
7493JOIN mz_internal.pg_type_all_databases ON pg_type_all_databases.oid = mz_columns.type_oid
7494JOIN mz_catalog.mz_schemas ON mz_schemas.id = class_objects.schema_id
7495LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id",
7496 access: vec![PUBLIC_SELECT],
7499 }
7500});
7501
7502pub const PG_ATTRIBUTE_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
7503 name: "pg_attribute_all_databases_ind",
7504 schema: MZ_INTERNAL_SCHEMA,
7505 oid: oid::INDEX_PG_ATTRIBUTE_ALL_DATABASES_IND_OID,
7506 sql: "IN CLUSTER mz_catalog_server
7507ON mz_internal.pg_attribute_all_databases (
7508 attrelid, attname, atttypid, attlen, attnum, atttypmod, attnotnull, atthasdef, attidentity,
7509 attgenerated, attisdropped, attcollation, database_name, pg_type_database_name
7510)",
7511 is_retained_metrics_object: false,
7512};
7513
7514pub static PG_ATTRIBUTE: LazyLock<BuiltinView> = LazyLock::new(|| {
7516 BuiltinView {
7517 name: "pg_attribute",
7518 schema: PG_CATALOG_SCHEMA,
7519 oid: oid::VIEW_PG_ATTRIBUTE_OID,
7520 desc: RelationDesc::builder()
7521 .with_column("attrelid", SqlScalarType::Oid.nullable(false))
7522 .with_column("attname", SqlScalarType::String.nullable(false))
7523 .with_column("atttypid", SqlScalarType::Oid.nullable(false))
7524 .with_column("attlen", SqlScalarType::Int16.nullable(true))
7525 .with_column("attnum", SqlScalarType::Int16.nullable(false))
7526 .with_column("atttypmod", SqlScalarType::Int32.nullable(false))
7527 .with_column("attndims", SqlScalarType::Int16.nullable(false))
7528 .with_column("attnotnull", SqlScalarType::Bool.nullable(false))
7529 .with_column("atthasdef", SqlScalarType::Bool.nullable(false))
7530 .with_column("attidentity", SqlScalarType::PgLegacyChar.nullable(false))
7531 .with_column("attgenerated", SqlScalarType::PgLegacyChar.nullable(false))
7532 .with_column("attisdropped", SqlScalarType::Bool.nullable(false))
7533 .with_column("attcollation", SqlScalarType::Oid.nullable(false))
7534 .finish(),
7535 column_comments: BTreeMap::new(),
7536 sql: "
7537SELECT
7538 attrelid, attname, atttypid, attlen, attnum, atttypmod, attndims, attnotnull, atthasdef,
7539 attidentity, attgenerated, attisdropped, attcollation
7540FROM mz_internal.pg_attribute_all_databases
7541WHERE
7542 (database_name IS NULL OR database_name = pg_catalog.current_database()) AND
7543 (pg_type_database_name IS NULL OR pg_type_database_name = pg_catalog.current_database());",
7544 access: vec![PUBLIC_SELECT],
7547 }
7548});
7549
7550pub static PG_PROC: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7551 name: "pg_proc",
7552 schema: PG_CATALOG_SCHEMA,
7553 oid: oid::VIEW_PG_PROC_OID,
7554 desc: RelationDesc::builder()
7555 .with_column("oid", SqlScalarType::Oid.nullable(false))
7556 .with_column("proname", SqlScalarType::String.nullable(false))
7557 .with_column("pronamespace", SqlScalarType::Oid.nullable(false))
7558 .with_column("proowner", SqlScalarType::Oid.nullable(false))
7559 .with_column("proargdefaults", SqlScalarType::String.nullable(true))
7560 .with_column("prorettype", SqlScalarType::Oid.nullable(false))
7561 .finish(),
7562 column_comments: BTreeMap::new(),
7563 sql: "SELECT
7564 mz_functions.oid,
7565 mz_functions.name AS proname,
7566 mz_schemas.oid AS pronamespace,
7567 role_owner.oid AS proowner,
7568 NULL::pg_catalog.text AS proargdefaults,
7569 ret_type.oid AS prorettype
7570FROM mz_catalog.mz_functions
7571JOIN mz_catalog.mz_schemas ON mz_functions.schema_id = mz_schemas.id
7572LEFT JOIN mz_catalog.mz_databases d ON d.id = mz_schemas.database_id
7573JOIN mz_catalog.mz_types AS ret_type ON mz_functions.return_type_id = ret_type.id
7574JOIN mz_catalog.mz_roles role_owner ON role_owner.id = mz_functions.owner_id
7575WHERE mz_schemas.database_id IS NULL OR d.name = pg_catalog.current_database()",
7576 access: vec![PUBLIC_SELECT],
7577});
7578
7579pub static PG_OPERATOR: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7580 name: "pg_operator",
7581 schema: PG_CATALOG_SCHEMA,
7582 oid: oid::VIEW_PG_OPERATOR_OID,
7583 desc: RelationDesc::builder()
7584 .with_column("oid", SqlScalarType::Oid.nullable(false))
7585 .with_column("oprname", SqlScalarType::String.nullable(false))
7586 .with_column("oprresult", SqlScalarType::Oid.nullable(false))
7587 .with_column("oprleft", SqlScalarType::Oid.nullable(false))
7588 .with_column("oprright", SqlScalarType::Oid.nullable(false))
7589 .with_key(vec![0, 1, 2, 3, 4])
7590 .finish(),
7591 column_comments: BTreeMap::new(),
7592 sql: "SELECT
7593 mz_operators.oid,
7594 mz_operators.name AS oprname,
7595 ret_type.oid AS oprresult,
7596 left_type.oid as oprleft,
7597 right_type.oid as oprright
7598FROM mz_catalog.mz_operators
7599JOIN mz_catalog.mz_types AS ret_type ON mz_operators.return_type_id = ret_type.id
7600JOIN mz_catalog.mz_types AS left_type ON mz_operators.argument_type_ids[1] = left_type.id
7601JOIN mz_catalog.mz_types AS right_type ON mz_operators.argument_type_ids[2] = right_type.id
7602WHERE array_length(mz_operators.argument_type_ids, 1) = 2
7603UNION SELECT
7604 mz_operators.oid,
7605 mz_operators.name AS oprname,
7606 ret_type.oid AS oprresult,
7607 0 as oprleft,
7608 right_type.oid as oprright
7609FROM mz_catalog.mz_operators
7610JOIN mz_catalog.mz_types AS ret_type ON mz_operators.return_type_id = ret_type.id
7611JOIN mz_catalog.mz_types AS right_type ON mz_operators.argument_type_ids[1] = right_type.id
7612WHERE array_length(mz_operators.argument_type_ids, 1) = 1",
7613 access: vec![PUBLIC_SELECT],
7614});
7615
7616pub static PG_RANGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7617 name: "pg_range",
7618 schema: PG_CATALOG_SCHEMA,
7619 oid: oid::VIEW_PG_RANGE_OID,
7620 desc: RelationDesc::builder()
7621 .with_column("rngtypid", SqlScalarType::Oid.nullable(false))
7622 .with_column("rngsubtype", SqlScalarType::Oid.nullable(false))
7623 .with_key(vec![])
7624 .finish(),
7625 column_comments: BTreeMap::new(),
7626 sql: "SELECT
7627 NULL::pg_catalog.oid AS rngtypid,
7628 NULL::pg_catalog.oid AS rngsubtype
7629WHERE false",
7630 access: vec![PUBLIC_SELECT],
7631});
7632
7633pub static PG_ENUM: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7634 name: "pg_enum",
7635 schema: PG_CATALOG_SCHEMA,
7636 oid: oid::VIEW_PG_ENUM_OID,
7637 desc: RelationDesc::builder()
7638 .with_column("oid", SqlScalarType::Oid.nullable(false))
7639 .with_column("enumtypid", SqlScalarType::Oid.nullable(false))
7640 .with_column("enumsortorder", SqlScalarType::Float32.nullable(false))
7641 .with_column("enumlabel", SqlScalarType::String.nullable(false))
7642 .with_key(vec![])
7643 .finish(),
7644 column_comments: BTreeMap::new(),
7645 sql: "SELECT
7646 NULL::pg_catalog.oid AS oid,
7647 NULL::pg_catalog.oid AS enumtypid,
7648 NULL::pg_catalog.float4 AS enumsortorder,
7649 NULL::pg_catalog.text AS enumlabel
7650WHERE false",
7651 access: vec![PUBLIC_SELECT],
7652});
7653
7654pub static PG_ATTRDEF_ALL_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7658 name: "pg_attrdef_all_databases",
7659 schema: MZ_INTERNAL_SCHEMA,
7660 oid: oid::VIEW_PG_ATTRDEF_ALL_DATABASES_OID,
7661 desc: RelationDesc::builder()
7662 .with_column("oid", SqlScalarType::Oid.nullable(true))
7663 .with_column("adrelid", SqlScalarType::Oid.nullable(false))
7664 .with_column("adnum", SqlScalarType::Int64.nullable(false))
7665 .with_column("adbin", SqlScalarType::String.nullable(false))
7666 .with_column("adsrc", SqlScalarType::String.nullable(false))
7667 .finish(),
7668 column_comments: BTreeMap::new(),
7669 sql: "
7670SELECT
7671 NULL::pg_catalog.oid AS oid,
7672 mz_objects.oid AS adrelid,
7673 mz_columns.position::int8 AS adnum,
7674 mz_columns.default AS adbin,
7675 mz_columns.default AS adsrc
7676FROM mz_catalog.mz_columns
7677 JOIN mz_catalog.mz_objects ON mz_columns.id = mz_objects.id
7678WHERE default IS NOT NULL",
7679 access: vec![PUBLIC_SELECT],
7680});
7681
7682pub const PG_ATTRDEF_ALL_DATABASES_IND: BuiltinIndex = BuiltinIndex {
7683 name: "pg_attrdef_all_databases_ind",
7684 schema: MZ_INTERNAL_SCHEMA,
7685 oid: oid::INDEX_PG_ATTRDEF_ALL_DATABASES_IND_OID,
7686 sql: "IN CLUSTER mz_catalog_server
7687ON mz_internal.pg_attrdef_all_databases (oid, adrelid, adnum, adbin, adsrc)",
7688 is_retained_metrics_object: false,
7689};
7690
7691pub static PG_ATTRDEF: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7692 name: "pg_attrdef",
7693 schema: PG_CATALOG_SCHEMA,
7694 oid: oid::VIEW_PG_ATTRDEF_OID,
7695 desc: RelationDesc::builder()
7696 .with_column("oid", SqlScalarType::Oid.nullable(true))
7697 .with_column("adrelid", SqlScalarType::Oid.nullable(false))
7698 .with_column("adnum", SqlScalarType::Int64.nullable(false))
7699 .with_column("adbin", SqlScalarType::String.nullable(false))
7700 .with_column("adsrc", SqlScalarType::String.nullable(false))
7701 .finish(),
7702 column_comments: BTreeMap::new(),
7703 sql: "
7704SELECT
7705 pg_attrdef_all_databases.oid as oid,
7706 adrelid,
7707 adnum,
7708 adbin,
7709 adsrc
7710FROM mz_internal.pg_attrdef_all_databases
7711 JOIN mz_catalog.mz_databases d ON (d.id IS NULL OR d.name = pg_catalog.current_database());",
7712 access: vec![PUBLIC_SELECT],
7713});
7714
7715pub static PG_SETTINGS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7716 name: "pg_settings",
7717 schema: PG_CATALOG_SCHEMA,
7718 oid: oid::VIEW_PG_SETTINGS_OID,
7719 desc: RelationDesc::builder()
7720 .with_column("name", SqlScalarType::String.nullable(false))
7721 .with_column("setting", SqlScalarType::String.nullable(false))
7722 .with_key(vec![])
7723 .finish(),
7724 column_comments: BTreeMap::new(),
7725 sql: "SELECT
7726 name, setting
7727FROM (VALUES
7728 ('max_index_keys'::pg_catalog.text, '1000'::pg_catalog.text)
7729) AS _ (name, setting)",
7730 access: vec![PUBLIC_SELECT],
7731});
7732
7733pub static PG_AUTH_MEMBERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7734 name: "pg_auth_members",
7735 schema: PG_CATALOG_SCHEMA,
7736 oid: oid::VIEW_PG_AUTH_MEMBERS_OID,
7737 desc: RelationDesc::builder()
7738 .with_column("roleid", SqlScalarType::Oid.nullable(false))
7739 .with_column("member", SqlScalarType::Oid.nullable(false))
7740 .with_column("grantor", SqlScalarType::Oid.nullable(false))
7741 .with_column("admin_option", SqlScalarType::Bool.nullable(false))
7742 .finish(),
7743 column_comments: BTreeMap::new(),
7744 sql: "SELECT
7745 role.oid AS roleid,
7746 member.oid AS member,
7747 grantor.oid AS grantor,
7748 -- Materialize hasn't implemented admin_option.
7749 false as admin_option
7750FROM mz_catalog.mz_role_members membership
7751JOIN mz_catalog.mz_roles role ON membership.role_id = role.id
7752JOIN mz_catalog.mz_roles member ON membership.member = member.id
7753JOIN mz_catalog.mz_roles grantor ON membership.grantor = grantor.id",
7754 access: vec![PUBLIC_SELECT],
7755});
7756
7757pub static PG_EVENT_TRIGGER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7758 name: "pg_event_trigger",
7759 schema: PG_CATALOG_SCHEMA,
7760 oid: oid::VIEW_PG_EVENT_TRIGGER_OID,
7761 desc: RelationDesc::builder()
7762 .with_column("oid", SqlScalarType::Oid.nullable(false))
7763 .with_column("evtname", SqlScalarType::String.nullable(false))
7764 .with_column("evtevent", SqlScalarType::String.nullable(false))
7765 .with_column("evtowner", SqlScalarType::Oid.nullable(false))
7766 .with_column("evtfoid", SqlScalarType::Oid.nullable(false))
7767 .with_column("evtenabled", SqlScalarType::PgLegacyChar.nullable(false))
7768 .with_column(
7769 "evttags",
7770 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
7771 )
7772 .with_key(vec![])
7773 .finish(),
7774 column_comments: BTreeMap::new(),
7775 sql: "SELECT
7776 NULL::pg_catalog.oid AS oid,
7777 NULL::pg_catalog.text AS evtname,
7778 NULL::pg_catalog.text AS evtevent,
7779 NULL::pg_catalog.oid AS evtowner,
7780 NULL::pg_catalog.oid AS evtfoid,
7781 NULL::pg_catalog.char AS evtenabled,
7782 NULL::pg_catalog.text[] AS evttags
7783 WHERE false",
7784 access: vec![PUBLIC_SELECT],
7785});
7786
7787pub static PG_LANGUAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7788 name: "pg_language",
7789 schema: PG_CATALOG_SCHEMA,
7790 oid: oid::VIEW_PG_LANGUAGE_OID,
7791 desc: RelationDesc::builder()
7792 .with_column("oid", SqlScalarType::Oid.nullable(false))
7793 .with_column("lanname", SqlScalarType::String.nullable(false))
7794 .with_column("lanowner", SqlScalarType::Oid.nullable(false))
7795 .with_column("lanispl", SqlScalarType::Bool.nullable(false))
7796 .with_column("lanpltrusted", SqlScalarType::Bool.nullable(false))
7797 .with_column("lanplcallfoid", SqlScalarType::Oid.nullable(false))
7798 .with_column("laninline", SqlScalarType::Oid.nullable(false))
7799 .with_column("lanvalidator", SqlScalarType::Oid.nullable(false))
7800 .with_column(
7801 "lanacl",
7802 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
7803 )
7804 .with_key(vec![])
7805 .finish(),
7806 column_comments: BTreeMap::new(),
7807 sql: "SELECT
7808 NULL::pg_catalog.oid AS oid,
7809 NULL::pg_catalog.text AS lanname,
7810 NULL::pg_catalog.oid AS lanowner,
7811 NULL::pg_catalog.bool AS lanispl,
7812 NULL::pg_catalog.bool AS lanpltrusted,
7813 NULL::pg_catalog.oid AS lanplcallfoid,
7814 NULL::pg_catalog.oid AS laninline,
7815 NULL::pg_catalog.oid AS lanvalidator,
7816 NULL::pg_catalog.text[] AS lanacl
7817 WHERE false",
7818 access: vec![PUBLIC_SELECT],
7819});
7820
7821pub static PG_SHDESCRIPTION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7822 name: "pg_shdescription",
7823 schema: PG_CATALOG_SCHEMA,
7824 oid: oid::VIEW_PG_SHDESCRIPTION_OID,
7825 desc: RelationDesc::builder()
7826 .with_column("objoid", SqlScalarType::Oid.nullable(false))
7827 .with_column("classoid", SqlScalarType::Oid.nullable(false))
7828 .with_column("description", SqlScalarType::String.nullable(false))
7829 .with_key(vec![])
7830 .finish(),
7831 column_comments: BTreeMap::new(),
7832 sql: "SELECT
7833 NULL::pg_catalog.oid AS objoid,
7834 NULL::pg_catalog.oid AS classoid,
7835 NULL::pg_catalog.text AS description
7836 WHERE false",
7837 access: vec![PUBLIC_SELECT],
7838});
7839
7840pub static PG_TIMEZONE_ABBREVS: LazyLock<BuiltinView> = LazyLock::new(|| {
7841 BuiltinView {
7842 name: "pg_timezone_abbrevs",
7843 schema: PG_CATALOG_SCHEMA,
7844 oid: oid::VIEW_PG_TIMEZONE_ABBREVS_OID,
7845 desc: RelationDesc::builder()
7846 .with_column("abbrev", SqlScalarType::String.nullable(false))
7847 .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
7848 .with_column("is_dst", SqlScalarType::Bool.nullable(true))
7849 .with_key(vec![0])
7850 .finish(),
7851 column_comments: BTreeMap::new(),
7852 sql: "SELECT
7853 abbreviation AS abbrev,
7854 COALESCE(utc_offset, timezone_offset(timezone_name, now()).base_utc_offset + timezone_offset(timezone_name, now()).dst_offset)
7855 AS utc_offset,
7856 COALESCE(dst, timezone_offset(timezone_name, now()).dst_offset <> INTERVAL '0')
7857 AS is_dst
7858FROM mz_catalog.mz_timezone_abbreviations",
7859 access: vec![PUBLIC_SELECT],
7860 }
7861});
7862
7863pub static PG_TIMEZONE_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7864 name: "pg_timezone_names",
7865 schema: PG_CATALOG_SCHEMA,
7866 oid: oid::VIEW_PG_TIMEZONE_NAMES_OID,
7867 desc: RelationDesc::builder()
7868 .with_column("name", SqlScalarType::String.nullable(false))
7869 .with_column("abbrev", SqlScalarType::String.nullable(true))
7870 .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
7871 .with_column("is_dst", SqlScalarType::Bool.nullable(true))
7872 .with_key(vec![0])
7873 .finish(),
7874 column_comments: BTreeMap::new(),
7875 sql: "SELECT
7876 name,
7877 timezone_offset(name, now()).abbrev AS abbrev,
7878 timezone_offset(name, now()).base_utc_offset + timezone_offset(name, now()).dst_offset
7879 AS utc_offset,
7880 timezone_offset(name, now()).dst_offset <> INTERVAL '0'
7881 AS is_dst
7882FROM mz_catalog.mz_timezone_names",
7883 access: vec![PUBLIC_SELECT],
7884});
7885
7886pub static MZ_TIMEZONE_ABBREVIATIONS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7887 name: "mz_timezone_abbreviations",
7888 schema: MZ_CATALOG_SCHEMA,
7889 oid: oid::VIEW_MZ_TIMEZONE_ABBREVIATIONS_OID,
7890 desc: RelationDesc::builder()
7891 .with_column("abbreviation", SqlScalarType::String.nullable(false))
7892 .with_column("utc_offset", SqlScalarType::Interval.nullable(true))
7893 .with_column("dst", SqlScalarType::Bool.nullable(true))
7894 .with_column("timezone_name", SqlScalarType::String.nullable(true))
7895 .with_key(vec![0])
7896 .finish(),
7897 column_comments: BTreeMap::from_iter([
7898 ("abbreviation", "The timezone abbreviation."),
7899 (
7900 "utc_offset",
7901 "The UTC offset of the timezone or `NULL` if fixed.",
7902 ),
7903 (
7904 "dst",
7905 "Whether the timezone is in daylight savings or `NULL` if fixed.",
7906 ),
7907 (
7908 "timezone_name",
7909 "The full name of the non-fixed timezone or `NULL` if not fixed.",
7910 ),
7911 ]),
7912 sql: format!(
7913 "SELECT * FROM ({}) _ (abbreviation, utc_offset, dst, timezone_name)",
7914 mz_pgtz::abbrev::MZ_CATALOG_TIMEZONE_ABBREVIATIONS_SQL,
7915 )
7916 .leak(),
7917 access: vec![PUBLIC_SELECT],
7918});
7919
7920pub static MZ_TIMEZONE_NAMES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7921 name: "mz_timezone_names",
7922 schema: MZ_CATALOG_SCHEMA,
7923 oid: oid::VIEW_MZ_TIMEZONE_NAMES_OID,
7924 desc: RelationDesc::builder()
7925 .with_column("name", SqlScalarType::String.nullable(false))
7926 .with_key(vec![0])
7927 .finish(),
7928 column_comments: BTreeMap::from_iter([("name", "The timezone name.")]),
7929 sql: format!(
7930 "SELECT * FROM ({}) _ (name)",
7931 mz_pgtz::timezone::MZ_CATALOG_TIMEZONE_NAMES_SQL,
7932 )
7933 .leak(),
7934 access: vec![PUBLIC_SELECT],
7935});
7936
7937pub static MZ_PEEK_DURATIONS_HISTOGRAM_PER_WORKER: LazyLock<BuiltinView> =
7938 LazyLock::new(|| BuiltinView {
7939 name: "mz_peek_durations_histogram_per_worker",
7940 schema: MZ_INTROSPECTION_SCHEMA,
7941 oid: oid::VIEW_MZ_PEEK_DURATIONS_HISTOGRAM_PER_WORKER_OID,
7942 desc: RelationDesc::builder()
7943 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
7944 .with_column("type", SqlScalarType::String.nullable(false))
7945 .with_column("duration_ns", SqlScalarType::UInt64.nullable(false))
7946 .with_column("count", SqlScalarType::Int64.nullable(false))
7947 .with_key(vec![0, 1, 2])
7948 .finish(),
7949 column_comments: BTreeMap::new(),
7950 sql: "SELECT
7951 worker_id, type, duration_ns, pg_catalog.count(*) AS count
7952FROM
7953 mz_introspection.mz_peek_durations_histogram_raw
7954GROUP BY
7955 worker_id, type, duration_ns",
7956 access: vec![PUBLIC_SELECT],
7957 });
7958
7959pub static MZ_PEEK_DURATIONS_HISTOGRAM: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
7960 name: "mz_peek_durations_histogram",
7961 schema: MZ_INTROSPECTION_SCHEMA,
7962 oid: oid::VIEW_MZ_PEEK_DURATIONS_HISTOGRAM_OID,
7963 desc: RelationDesc::builder()
7964 .with_column("type", SqlScalarType::String.nullable(false))
7965 .with_column("duration_ns", SqlScalarType::UInt64.nullable(false))
7966 .with_column(
7967 "count",
7968 SqlScalarType::Numeric {
7969 max_scale: Some(NumericMaxScale::ZERO),
7970 }
7971 .nullable(false),
7972 )
7973 .with_key(vec![0, 1])
7974 .finish(),
7975 column_comments: BTreeMap::from_iter([
7976 ("type", "The peek variant: `index` or `persist`."),
7977 (
7978 "duration_ns",
7979 "The upper bound of the bucket in nanoseconds.",
7980 ),
7981 (
7982 "count",
7983 "The (noncumulative) count of peeks in this bucket.",
7984 ),
7985 ]),
7986 sql: "
7987SELECT
7988 type, duration_ns,
7989 pg_catalog.sum(count) AS count
7990FROM mz_introspection.mz_peek_durations_histogram_per_worker
7991GROUP BY type, duration_ns",
7992 access: vec![PUBLIC_SELECT],
7993});
7994
7995pub static MZ_SCHEDULING_ELAPSED_PER_WORKER: LazyLock<BuiltinView> =
7996 LazyLock::new(|| BuiltinView {
7997 name: "mz_scheduling_elapsed_per_worker",
7998 schema: MZ_INTROSPECTION_SCHEMA,
7999 oid: oid::VIEW_MZ_SCHEDULING_ELAPSED_PER_WORKER_OID,
8000 desc: RelationDesc::builder()
8001 .with_column("id", SqlScalarType::UInt64.nullable(false))
8002 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8003 .with_column("elapsed_ns", SqlScalarType::Int64.nullable(false))
8004 .with_key(vec![0, 1])
8005 .finish(),
8006 column_comments: BTreeMap::new(),
8007 sql: "SELECT
8008 id, worker_id, pg_catalog.count(*) AS elapsed_ns
8009FROM
8010 mz_introspection.mz_scheduling_elapsed_raw
8011GROUP BY
8012 id, worker_id",
8013 access: vec![PUBLIC_SELECT],
8014 });
8015
8016pub static MZ_SCHEDULING_ELAPSED: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8017 name: "mz_scheduling_elapsed",
8018 schema: MZ_INTROSPECTION_SCHEMA,
8019 oid: oid::VIEW_MZ_SCHEDULING_ELAPSED_OID,
8020 desc: RelationDesc::builder()
8021 .with_column("id", SqlScalarType::UInt64.nullable(false))
8022 .with_column(
8023 "elapsed_ns",
8024 SqlScalarType::Numeric {
8025 max_scale: Some(NumericMaxScale::ZERO),
8026 }
8027 .nullable(false),
8028 )
8029 .with_key(vec![0])
8030 .finish(),
8031 column_comments: BTreeMap::from_iter([
8032 (
8033 "id",
8034 "The ID of the operator. Corresponds to `mz_dataflow_operators.id`.",
8035 ),
8036 (
8037 "elapsed_ns",
8038 "The total elapsed time spent in the operator in nanoseconds.",
8039 ),
8040 ]),
8041 sql: "
8042SELECT
8043 id,
8044 pg_catalog.sum(elapsed_ns) AS elapsed_ns
8045FROM mz_introspection.mz_scheduling_elapsed_per_worker
8046GROUP BY id",
8047 access: vec![PUBLIC_SELECT],
8048});
8049
8050pub static MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_PER_WORKER: LazyLock<BuiltinView> =
8051 LazyLock::new(|| BuiltinView {
8052 name: "mz_compute_operator_durations_histogram_per_worker",
8053 schema: MZ_INTROSPECTION_SCHEMA,
8054 oid: oid::VIEW_MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_PER_WORKER_OID,
8055 desc: RelationDesc::builder()
8056 .with_column("id", SqlScalarType::UInt64.nullable(false))
8057 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8058 .with_column("duration_ns", SqlScalarType::UInt64.nullable(false))
8059 .with_column("count", SqlScalarType::Int64.nullable(false))
8060 .with_key(vec![0, 1, 2])
8061 .finish(),
8062 column_comments: BTreeMap::new(),
8063 sql: "SELECT
8064 id, worker_id, duration_ns, pg_catalog.count(*) AS count
8065FROM
8066 mz_introspection.mz_compute_operator_durations_histogram_raw
8067GROUP BY
8068 id, worker_id, duration_ns",
8069 access: vec![PUBLIC_SELECT],
8070 });
8071
8072pub static MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM: LazyLock<BuiltinView> =
8073 LazyLock::new(|| BuiltinView {
8074 name: "mz_compute_operator_durations_histogram",
8075 schema: MZ_INTROSPECTION_SCHEMA,
8076 oid: oid::VIEW_MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_OID,
8077 desc: RelationDesc::builder()
8078 .with_column("id", SqlScalarType::UInt64.nullable(false))
8079 .with_column("duration_ns", SqlScalarType::UInt64.nullable(false))
8080 .with_column(
8081 "count",
8082 SqlScalarType::Numeric {
8083 max_scale: Some(NumericMaxScale::ZERO),
8084 }
8085 .nullable(false),
8086 )
8087 .with_key(vec![0, 1])
8088 .finish(),
8089 column_comments: BTreeMap::from_iter([
8090 (
8091 "id",
8092 "The ID of the operator. Corresponds to `mz_dataflow_operators.id`.",
8093 ),
8094 (
8095 "duration_ns",
8096 "The upper bound of the duration bucket in nanoseconds.",
8097 ),
8098 (
8099 "count",
8100 "The (noncumulative) count of invocations in the bucket.",
8101 ),
8102 ]),
8103 sql: "
8104SELECT
8105 id,
8106 duration_ns,
8107 pg_catalog.sum(count) AS count
8108FROM mz_introspection.mz_compute_operator_durations_histogram_per_worker
8109GROUP BY id, duration_ns",
8110 access: vec![PUBLIC_SELECT],
8111 });
8112
8113pub static MZ_SCHEDULING_PARKS_HISTOGRAM_PER_WORKER: LazyLock<BuiltinView> =
8114 LazyLock::new(|| BuiltinView {
8115 name: "mz_scheduling_parks_histogram_per_worker",
8116 schema: MZ_INTROSPECTION_SCHEMA,
8117 oid: oid::VIEW_MZ_SCHEDULING_PARKS_HISTOGRAM_PER_WORKER_OID,
8118 desc: RelationDesc::builder()
8119 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8120 .with_column("slept_for_ns", SqlScalarType::UInt64.nullable(false))
8121 .with_column("requested_ns", SqlScalarType::UInt64.nullable(false))
8122 .with_column("count", SqlScalarType::Int64.nullable(false))
8123 .with_key(vec![0, 1, 2])
8124 .finish(),
8125 column_comments: BTreeMap::new(),
8126 sql: "SELECT
8127 worker_id, slept_for_ns, requested_ns, pg_catalog.count(*) AS count
8128FROM
8129 mz_introspection.mz_scheduling_parks_histogram_raw
8130GROUP BY
8131 worker_id, slept_for_ns, requested_ns",
8132 access: vec![PUBLIC_SELECT],
8133 });
8134
8135pub static MZ_SCHEDULING_PARKS_HISTOGRAM: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8136 name: "mz_scheduling_parks_histogram",
8137 schema: MZ_INTROSPECTION_SCHEMA,
8138 oid: oid::VIEW_MZ_SCHEDULING_PARKS_HISTOGRAM_OID,
8139 desc: RelationDesc::builder()
8140 .with_column("slept_for_ns", SqlScalarType::UInt64.nullable(false))
8141 .with_column("requested_ns", SqlScalarType::UInt64.nullable(false))
8142 .with_column(
8143 "count",
8144 SqlScalarType::Numeric {
8145 max_scale: Some(NumericMaxScale::ZERO),
8146 }
8147 .nullable(false),
8148 )
8149 .with_key(vec![0, 1])
8150 .finish(),
8151 column_comments: BTreeMap::from_iter([
8152 (
8153 "slept_for_ns",
8154 "The actual length of the park event in nanoseconds.",
8155 ),
8156 (
8157 "requested_ns",
8158 "The requested length of the park event in nanoseconds.",
8159 ),
8160 (
8161 "count",
8162 "The (noncumulative) count of park events in this bucket.",
8163 ),
8164 ]),
8165 sql: "
8166SELECT
8167 slept_for_ns,
8168 requested_ns,
8169 pg_catalog.sum(count) AS count
8170FROM mz_introspection.mz_scheduling_parks_histogram_per_worker
8171GROUP BY slept_for_ns, requested_ns",
8172 access: vec![PUBLIC_SELECT],
8173});
8174
8175pub static MZ_COMPUTE_ERROR_COUNTS_PER_WORKER: LazyLock<BuiltinView> =
8176 LazyLock::new(|| BuiltinView {
8177 name: "mz_compute_error_counts_per_worker",
8178 schema: MZ_INTROSPECTION_SCHEMA,
8179 oid: oid::VIEW_MZ_COMPUTE_ERROR_COUNTS_PER_WORKER_OID,
8180 desc: RelationDesc::builder()
8181 .with_column("export_id", SqlScalarType::String.nullable(false))
8182 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8183 .with_column("count", SqlScalarType::Int64.nullable(false))
8184 .with_key(vec![0, 1, 2])
8185 .finish(),
8186 column_comments: BTreeMap::new(),
8187 sql: "
8188WITH MUTUALLY RECURSIVE
8189 -- Indexes that reuse existing indexes rather than maintaining separate dataflows.
8190 -- For these we don't log error counts separately, so we need to forward the error counts from
8191 -- their dependencies instead.
8192 index_reuses(reuse_id text, index_id text) AS (
8193 SELECT d.object_id, d.dependency_id
8194 FROM mz_internal.mz_compute_dependencies d
8195 JOIN mz_introspection.mz_compute_exports e ON (e.export_id = d.object_id)
8196 WHERE NOT EXISTS (
8197 SELECT 1 FROM mz_introspection.mz_dataflows
8198 WHERE id = e.dataflow_id
8199 )
8200 ),
8201 -- Error counts that were directly logged on compute exports.
8202 direct_errors(export_id text, worker_id uint8, count int8) AS (
8203 SELECT export_id, worker_id, count
8204 FROM mz_introspection.mz_compute_error_counts_raw
8205 ),
8206 -- Error counts propagated to index reused.
8207 all_errors(export_id text, worker_id uint8, count int8) AS (
8208 SELECT * FROM direct_errors
8209 UNION
8210 SELECT r.reuse_id, e.worker_id, e.count
8211 FROM all_errors e
8212 JOIN index_reuses r ON (r.index_id = e.export_id)
8213 )
8214SELECT * FROM all_errors",
8215 access: vec![PUBLIC_SELECT],
8216 });
8217
8218pub static MZ_COMPUTE_ERROR_COUNTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8219 name: "mz_compute_error_counts",
8220 schema: MZ_INTROSPECTION_SCHEMA,
8221 oid: oid::VIEW_MZ_COMPUTE_ERROR_COUNTS_OID,
8222 desc: RelationDesc::builder()
8223 .with_column("export_id", SqlScalarType::String.nullable(false))
8224 .with_column(
8225 "count",
8226 SqlScalarType::Numeric {
8227 max_scale: Some(NumericMaxScale::ZERO),
8228 }
8229 .nullable(false),
8230 )
8231 .with_key(vec![0])
8232 .finish(),
8233 column_comments: BTreeMap::from_iter([
8234 (
8235 "export_id",
8236 "The ID of the dataflow export. Corresponds to `mz_compute_exports.export_id`.",
8237 ),
8238 (
8239 "count",
8240 "The count of errors present in this dataflow export.",
8241 ),
8242 ]),
8243 sql: "
8244SELECT
8245 export_id,
8246 pg_catalog.sum(count) AS count
8247FROM mz_introspection.mz_compute_error_counts_per_worker
8248GROUP BY export_id
8249HAVING pg_catalog.sum(count) != 0",
8250 access: vec![PUBLIC_SELECT],
8251});
8252
8253pub static MZ_COMPUTE_ERROR_COUNTS_RAW_UNIFIED: LazyLock<BuiltinSource> =
8254 LazyLock::new(|| BuiltinSource {
8255 name: "mz_compute_error_counts_raw_unified",
8259 schema: MZ_INTERNAL_SCHEMA,
8260 oid: oid::SOURCE_MZ_COMPUTE_ERROR_COUNTS_RAW_UNIFIED_OID,
8261 desc: RelationDesc::builder()
8262 .with_column("replica_id", SqlScalarType::String.nullable(false))
8263 .with_column("object_id", SqlScalarType::String.nullable(false))
8264 .with_column(
8265 "count",
8266 SqlScalarType::Numeric { max_scale: None }.nullable(false),
8267 )
8268 .finish(),
8269 data_source: IntrospectionType::ComputeErrorCounts.into(),
8270 column_comments: BTreeMap::new(),
8271 is_retained_metrics_object: false,
8272 access: vec![PUBLIC_SELECT],
8273 });
8274
8275pub static MZ_COMPUTE_HYDRATION_TIMES: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
8276 name: "mz_compute_hydration_times",
8277 schema: MZ_INTERNAL_SCHEMA,
8278 oid: oid::SOURCE_MZ_COMPUTE_HYDRATION_TIMES_OID,
8279 desc: RelationDesc::builder()
8280 .with_column("replica_id", SqlScalarType::String.nullable(false))
8281 .with_column("object_id", SqlScalarType::String.nullable(false))
8282 .with_column("time_ns", SqlScalarType::UInt64.nullable(true))
8283 .finish(),
8284 data_source: IntrospectionType::ComputeHydrationTimes.into(),
8285 column_comments: BTreeMap::new(),
8286 is_retained_metrics_object: true,
8287 access: vec![PUBLIC_SELECT],
8288});
8289
8290pub static MZ_COMPUTE_HYDRATION_TIMES_IND: LazyLock<BuiltinIndex> =
8291 LazyLock::new(|| BuiltinIndex {
8292 name: "mz_compute_hydration_times_ind",
8293 schema: MZ_INTERNAL_SCHEMA,
8294 oid: oid::INDEX_MZ_COMPUTE_HYDRATION_TIMES_IND_OID,
8295 sql: "IN CLUSTER mz_catalog_server
8296 ON mz_internal.mz_compute_hydration_times (replica_id)",
8297 is_retained_metrics_object: true,
8298 });
8299
8300pub static MZ_COMPUTE_HYDRATION_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8301 name: "mz_compute_hydration_statuses",
8302 schema: MZ_INTERNAL_SCHEMA,
8303 oid: oid::SOURCE_MZ_COMPUTE_HYDRATION_STATUSES_OID,
8304 desc: RelationDesc::builder()
8305 .with_column("object_id", SqlScalarType::String.nullable(false))
8306 .with_column("replica_id", SqlScalarType::String.nullable(false))
8307 .with_column("hydrated", SqlScalarType::Bool.nullable(false))
8308 .with_column("hydration_time", SqlScalarType::Interval.nullable(true))
8309 .finish(),
8310 column_comments: BTreeMap::from_iter([
8311 (
8312 "object_id",
8313 "The ID of a compute object. Corresponds to `mz_catalog.mz_indexes.id` or `mz_catalog.mz_materialized_views.id`",
8314 ),
8315 ("replica_id", "The ID of a cluster replica."),
8316 (
8317 "hydrated",
8318 "Whether the compute object is hydrated on the replica.",
8319 ),
8320 (
8321 "hydration_time",
8322 "The amount of time it took for the replica to hydrate the compute object.",
8323 ),
8324 ]),
8325 sql: "
8326WITH
8327 dataflows AS (
8328 SELECT
8329 object_id,
8330 replica_id,
8331 time_ns IS NOT NULL AS hydrated,
8332 ((time_ns / 1000) || 'microseconds')::interval AS hydration_time
8333 FROM mz_internal.mz_compute_hydration_times
8334 ),
8335 -- MVs that have advanced to the empty frontier don't have a dataflow installed anymore and
8336 -- therefore don't show up in `mz_compute_hydration_times`. We still want to show them here to
8337 -- avoid surprises for people joining `mz_materialized_views` against this relation (like the
8338 -- blue-green readiness query does), so we include them as 'hydrated'.
8339 complete_mvs AS (
8340 SELECT
8341 mv.id,
8342 f.replica_id,
8343 true AS hydrated,
8344 NULL::interval AS hydration_time
8345 FROM mz_materialized_views mv
8346 JOIN mz_catalog.mz_cluster_replica_frontiers f ON f.object_id = mv.id
8347 WHERE f.write_frontier IS NULL
8348 ),
8349 -- Ditto CTs
8350 complete_cts AS (
8351 SELECT
8352 ct.id,
8353 f.replica_id,
8354 true AS hydrated,
8355 NULL::interval AS hydration_time
8356 FROM mz_internal.mz_continual_tasks ct
8357 JOIN mz_catalog.mz_cluster_replica_frontiers f ON f.object_id = ct.id
8358 WHERE f.write_frontier IS NULL
8359 )
8360SELECT * FROM dataflows
8361UNION ALL
8362SELECT * FROM complete_mvs
8363UNION ALL
8364SELECT * FROM complete_cts",
8365 access: vec![PUBLIC_SELECT],
8366});
8367
8368pub static MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES: LazyLock<BuiltinSource> = LazyLock::new(|| {
8369 BuiltinSource {
8370 name: "mz_compute_operator_hydration_statuses",
8371 schema: MZ_INTERNAL_SCHEMA,
8372 oid: oid::SOURCE_MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES_OID,
8373 desc: RelationDesc::builder()
8374 .with_column("replica_id", SqlScalarType::String.nullable(false))
8375 .with_column("object_id", SqlScalarType::String.nullable(false))
8376 .with_column(
8377 "physical_plan_node_id",
8378 SqlScalarType::UInt64.nullable(false),
8379 )
8380 .with_column("hydrated", SqlScalarType::Bool.nullable(false))
8381 .with_key(vec![0, 1, 2])
8382 .finish(),
8383 data_source: IntrospectionType::ComputeOperatorHydrationStatus.into(),
8384 column_comments: BTreeMap::from_iter([
8385 ("replica_id", "The ID of a cluster replica."),
8386 (
8387 "object_id",
8388 "The ID of a compute object. Corresponds to `mz_catalog.mz_indexes.id` or `mz_catalog.mz_materialized_views.id`.",
8389 ),
8390 (
8391 "physical_plan_node_id",
8392 "The ID of a node in the physical plan of the compute object. Corresponds to a `node_id` displayed in the output of `EXPLAIN PHYSICAL PLAN WITH (node identifiers)`.",
8393 ),
8394 ("hydrated", "Whether the node is hydrated on the replica."),
8395 ]),
8396 is_retained_metrics_object: false,
8397 access: vec![PUBLIC_SELECT],
8398 }
8399});
8400
8401pub static MZ_MESSAGE_COUNTS_PER_WORKER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8402 name: "mz_message_counts_per_worker",
8403 schema: MZ_INTROSPECTION_SCHEMA,
8404 oid: oid::VIEW_MZ_MESSAGE_COUNTS_PER_WORKER_OID,
8405 desc: RelationDesc::builder()
8406 .with_column("channel_id", SqlScalarType::UInt64.nullable(false))
8407 .with_column("from_worker_id", SqlScalarType::UInt64.nullable(false))
8408 .with_column("to_worker_id", SqlScalarType::UInt64.nullable(false))
8409 .with_column("sent", SqlScalarType::Int64.nullable(false))
8410 .with_column("received", SqlScalarType::Int64.nullable(false))
8411 .with_column("batch_sent", SqlScalarType::Int64.nullable(false))
8412 .with_column("batch_received", SqlScalarType::Int64.nullable(false))
8413 .with_key(vec![0, 1, 2])
8414 .finish(),
8415 column_comments: BTreeMap::new(),
8416 sql: "
8417WITH batch_sent_cte AS (
8418 SELECT
8419 channel_id,
8420 from_worker_id,
8421 to_worker_id,
8422 pg_catalog.count(*) AS sent
8423 FROM
8424 mz_introspection.mz_message_batch_counts_sent_raw
8425 GROUP BY
8426 channel_id, from_worker_id, to_worker_id
8427),
8428batch_received_cte AS (
8429 SELECT
8430 channel_id,
8431 from_worker_id,
8432 to_worker_id,
8433 pg_catalog.count(*) AS received
8434 FROM
8435 mz_introspection.mz_message_batch_counts_received_raw
8436 GROUP BY
8437 channel_id, from_worker_id, to_worker_id
8438),
8439sent_cte AS (
8440 SELECT
8441 channel_id,
8442 from_worker_id,
8443 to_worker_id,
8444 pg_catalog.count(*) AS sent
8445 FROM
8446 mz_introspection.mz_message_counts_sent_raw
8447 GROUP BY
8448 channel_id, from_worker_id, to_worker_id
8449),
8450received_cte AS (
8451 SELECT
8452 channel_id,
8453 from_worker_id,
8454 to_worker_id,
8455 pg_catalog.count(*) AS received
8456 FROM
8457 mz_introspection.mz_message_counts_received_raw
8458 GROUP BY
8459 channel_id, from_worker_id, to_worker_id
8460)
8461SELECT
8462 sent_cte.channel_id,
8463 sent_cte.from_worker_id,
8464 sent_cte.to_worker_id,
8465 sent_cte.sent,
8466 received_cte.received,
8467 batch_sent_cte.sent AS batch_sent,
8468 batch_received_cte.received AS batch_received
8469FROM sent_cte
8470JOIN received_cte USING (channel_id, from_worker_id, to_worker_id)
8471JOIN batch_sent_cte USING (channel_id, from_worker_id, to_worker_id)
8472JOIN batch_received_cte USING (channel_id, from_worker_id, to_worker_id)",
8473 access: vec![PUBLIC_SELECT],
8474});
8475
8476pub static MZ_MESSAGE_COUNTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8477 name: "mz_message_counts",
8478 schema: MZ_INTROSPECTION_SCHEMA,
8479 oid: oid::VIEW_MZ_MESSAGE_COUNTS_OID,
8480 desc: RelationDesc::builder()
8481 .with_column("channel_id", SqlScalarType::UInt64.nullable(false))
8482 .with_column(
8483 "sent",
8484 SqlScalarType::Numeric {
8485 max_scale: Some(NumericMaxScale::ZERO),
8486 }
8487 .nullable(false),
8488 )
8489 .with_column(
8490 "received",
8491 SqlScalarType::Numeric {
8492 max_scale: Some(NumericMaxScale::ZERO),
8493 }
8494 .nullable(false),
8495 )
8496 .with_column(
8497 "batch_sent",
8498 SqlScalarType::Numeric {
8499 max_scale: Some(NumericMaxScale::ZERO),
8500 }
8501 .nullable(false),
8502 )
8503 .with_column(
8504 "batch_received",
8505 SqlScalarType::Numeric {
8506 max_scale: Some(NumericMaxScale::ZERO),
8507 }
8508 .nullable(false),
8509 )
8510 .with_key(vec![0])
8511 .finish(),
8512 column_comments: BTreeMap::from_iter([
8513 (
8514 "channel_id",
8515 "The ID of the channel. Corresponds to `mz_dataflow_channels.id`.",
8516 ),
8517 ("sent", "The number of messages sent."),
8518 ("received", "The number of messages received."),
8519 ("batch_sent", "The number of batches sent."),
8520 ("batch_received", "The number of batches received."),
8521 ]),
8522 sql: "
8523SELECT
8524 channel_id,
8525 pg_catalog.sum(sent) AS sent,
8526 pg_catalog.sum(received) AS received,
8527 pg_catalog.sum(batch_sent) AS batch_sent,
8528 pg_catalog.sum(batch_received) AS batch_received
8529FROM mz_introspection.mz_message_counts_per_worker
8530GROUP BY channel_id",
8531 access: vec![PUBLIC_SELECT],
8532});
8533
8534pub static MZ_ACTIVE_PEEKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8535 name: "mz_active_peeks",
8536 schema: MZ_INTROSPECTION_SCHEMA,
8537 oid: oid::VIEW_MZ_ACTIVE_PEEKS_OID,
8538 desc: RelationDesc::builder()
8539 .with_column("id", SqlScalarType::Uuid.nullable(false))
8540 .with_column("object_id", SqlScalarType::String.nullable(false))
8541 .with_column("type", SqlScalarType::String.nullable(false))
8542 .with_column("time", SqlScalarType::MzTimestamp.nullable(false))
8543 .finish(),
8544 column_comments: BTreeMap::from_iter([
8545 ("id", "The ID of the peek request."),
8546 (
8547 "object_id",
8548 "The ID of the collection the peek is targeting. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, `mz_catalog.mz_sources.id`, or `mz_catalog.mz_tables.id`.",
8549 ),
8550 (
8551 "type",
8552 "The type of the corresponding peek: `index` if targeting an index or temporary dataflow; `persist` for a source, materialized view, or table.",
8553 ),
8554 ("time", "The timestamp the peek has requested."),
8555 ]),
8556 sql: "
8557SELECT id, object_id, type, time
8558FROM mz_introspection.mz_active_peeks_per_worker
8559WHERE worker_id = 0",
8560 access: vec![PUBLIC_SELECT],
8561});
8562
8563pub static MZ_DATAFLOW_OPERATOR_REACHABILITY_PER_WORKER: LazyLock<BuiltinView> =
8564 LazyLock::new(|| BuiltinView {
8565 name: "mz_dataflow_operator_reachability_per_worker",
8566 schema: MZ_INTROSPECTION_SCHEMA,
8567 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_REACHABILITY_PER_WORKER_OID,
8568 desc: RelationDesc::builder()
8569 .with_column("id", SqlScalarType::UInt64.nullable(false))
8570 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8571 .with_column("port", SqlScalarType::UInt64.nullable(false))
8572 .with_column("update_type", SqlScalarType::String.nullable(false))
8573 .with_column("time", SqlScalarType::MzTimestamp.nullable(true))
8574 .with_column("count", SqlScalarType::Int64.nullable(false))
8575 .with_key(vec![0, 1, 2, 3, 4])
8576 .finish(),
8577 column_comments: BTreeMap::new(),
8578 sql: "SELECT
8579 addr2.id,
8580 reachability.worker_id,
8581 port,
8582 update_type,
8583 time,
8584 pg_catalog.count(*) as count
8585FROM
8586 mz_introspection.mz_dataflow_operator_reachability_raw reachability,
8587 mz_introspection.mz_dataflow_addresses_per_worker addr1,
8588 mz_introspection.mz_dataflow_addresses_per_worker addr2
8589WHERE
8590 addr2.address =
8591 CASE
8592 WHEN source = 0 THEN addr1.address
8593 ELSE addr1.address || reachability.source
8594 END
8595 AND addr1.id = reachability.id
8596 AND addr1.worker_id = reachability.worker_id
8597 AND addr2.worker_id = reachability.worker_id
8598GROUP BY addr2.id, reachability.worker_id, port, update_type, time",
8599 access: vec![PUBLIC_SELECT],
8600 });
8601
8602pub static MZ_DATAFLOW_OPERATOR_REACHABILITY: LazyLock<BuiltinView> =
8603 LazyLock::new(|| BuiltinView {
8604 name: "mz_dataflow_operator_reachability",
8605 schema: MZ_INTROSPECTION_SCHEMA,
8606 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_REACHABILITY_OID,
8607 desc: RelationDesc::builder()
8608 .with_column("id", SqlScalarType::UInt64.nullable(false))
8609 .with_column("port", SqlScalarType::UInt64.nullable(false))
8610 .with_column("update_type", SqlScalarType::String.nullable(false))
8611 .with_column("time", SqlScalarType::MzTimestamp.nullable(true))
8612 .with_column(
8613 "count",
8614 SqlScalarType::Numeric {
8615 max_scale: Some(NumericMaxScale::ZERO),
8616 }
8617 .nullable(false),
8618 )
8619 .with_key(vec![0, 1, 2, 3])
8620 .finish(),
8621 column_comments: BTreeMap::new(),
8622 sql: "
8623SELECT
8624 id,
8625 port,
8626 update_type,
8627 time,
8628 pg_catalog.sum(count) as count
8629FROM mz_introspection.mz_dataflow_operator_reachability_per_worker
8630GROUP BY id, port, update_type, time",
8631 access: vec![PUBLIC_SELECT],
8632 });
8633
8634pub static MZ_ARRANGEMENT_SIZES_PER_WORKER: LazyLock<BuiltinView> = LazyLock::new(|| {
8635 BuiltinView {
8636 name: "mz_arrangement_sizes_per_worker",
8637 schema: MZ_INTROSPECTION_SCHEMA,
8638 oid: oid::VIEW_MZ_ARRANGEMENT_SIZES_PER_WORKER_OID,
8639 desc: RelationDesc::builder()
8640 .with_column("operator_id", SqlScalarType::UInt64.nullable(false))
8641 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8642 .with_column("records", SqlScalarType::Int64.nullable(true))
8643 .with_column("batches", SqlScalarType::Int64.nullable(true))
8644 .with_column("size", SqlScalarType::Int64.nullable(true))
8645 .with_column("capacity", SqlScalarType::Int64.nullable(true))
8646 .with_column("allocations", SqlScalarType::Int64.nullable(true))
8647 .finish(),
8648 column_comments: BTreeMap::new(),
8649 sql: "
8650WITH operators_per_worker_cte AS (
8651 SELECT
8652 id AS operator_id,
8653 worker_id
8654 FROM
8655 mz_introspection.mz_dataflow_operators_per_worker
8656),
8657batches_cte AS (
8658 SELECT
8659 operator_id,
8660 worker_id,
8661 COUNT(*) AS batches
8662 FROM
8663 mz_introspection.mz_arrangement_batches_raw
8664 GROUP BY
8665 operator_id, worker_id
8666),
8667records_cte AS (
8668 SELECT
8669 operator_id,
8670 worker_id,
8671 COUNT(*) AS records
8672 FROM
8673 mz_introspection.mz_arrangement_records_raw
8674 GROUP BY
8675 operator_id, worker_id
8676),
8677heap_size_cte AS (
8678 SELECT
8679 operator_id,
8680 worker_id,
8681 COUNT(*) AS size
8682 FROM
8683 mz_introspection.mz_arrangement_heap_size_raw
8684 GROUP BY
8685 operator_id, worker_id
8686),
8687heap_capacity_cte AS (
8688 SELECT
8689 operator_id,
8690 worker_id,
8691 COUNT(*) AS capacity
8692 FROM
8693 mz_introspection.mz_arrangement_heap_capacity_raw
8694 GROUP BY
8695 operator_id, worker_id
8696),
8697heap_allocations_cte AS (
8698 SELECT
8699 operator_id,
8700 worker_id,
8701 COUNT(*) AS allocations
8702 FROM
8703 mz_introspection.mz_arrangement_heap_allocations_raw
8704 GROUP BY
8705 operator_id, worker_id
8706),
8707batcher_records_cte AS (
8708 SELECT
8709 operator_id,
8710 worker_id,
8711 COUNT(*) AS records
8712 FROM
8713 mz_introspection.mz_arrangement_batcher_records_raw
8714 GROUP BY
8715 operator_id, worker_id
8716),
8717batcher_size_cte AS (
8718 SELECT
8719 operator_id,
8720 worker_id,
8721 COUNT(*) AS size
8722 FROM
8723 mz_introspection.mz_arrangement_batcher_size_raw
8724 GROUP BY
8725 operator_id, worker_id
8726),
8727batcher_capacity_cte AS (
8728 SELECT
8729 operator_id,
8730 worker_id,
8731 COUNT(*) AS capacity
8732 FROM
8733 mz_introspection.mz_arrangement_batcher_capacity_raw
8734 GROUP BY
8735 operator_id, worker_id
8736),
8737batcher_allocations_cte AS (
8738 SELECT
8739 operator_id,
8740 worker_id,
8741 COUNT(*) AS allocations
8742 FROM
8743 mz_introspection.mz_arrangement_batcher_allocations_raw
8744 GROUP BY
8745 operator_id, worker_id
8746),
8747combined AS (
8748 SELECT
8749 opw.operator_id,
8750 opw.worker_id,
8751 CASE
8752 WHEN records_cte.records IS NULL AND batcher_records_cte.records IS NULL THEN NULL
8753 ELSE COALESCE(records_cte.records, 0) + COALESCE(batcher_records_cte.records, 0)
8754 END AS records,
8755 batches_cte.batches AS batches,
8756 CASE
8757 WHEN heap_size_cte.size IS NULL AND batcher_size_cte.size IS NULL THEN NULL
8758 ELSE COALESCE(heap_size_cte.size, 0) + COALESCE(batcher_size_cte.size, 0)
8759 END AS size,
8760 CASE
8761 WHEN heap_capacity_cte.capacity IS NULL AND batcher_capacity_cte.capacity IS NULL THEN NULL
8762 ELSE COALESCE(heap_capacity_cte.capacity, 0) + COALESCE(batcher_capacity_cte.capacity, 0)
8763 END AS capacity,
8764 CASE
8765 WHEN heap_allocations_cte.allocations IS NULL AND batcher_allocations_cte.allocations IS NULL THEN NULL
8766 ELSE COALESCE(heap_allocations_cte.allocations, 0) + COALESCE(batcher_allocations_cte.allocations, 0)
8767 END AS allocations
8768 FROM
8769 operators_per_worker_cte opw
8770 LEFT OUTER JOIN batches_cte USING (operator_id, worker_id)
8771 LEFT OUTER JOIN records_cte USING (operator_id, worker_id)
8772 LEFT OUTER JOIN heap_size_cte USING (operator_id, worker_id)
8773 LEFT OUTER JOIN heap_capacity_cte USING (operator_id, worker_id)
8774 LEFT OUTER JOIN heap_allocations_cte USING (operator_id, worker_id)
8775 LEFT OUTER JOIN batcher_records_cte USING (operator_id, worker_id)
8776 LEFT OUTER JOIN batcher_size_cte USING (operator_id, worker_id)
8777 LEFT OUTER JOIN batcher_capacity_cte USING (operator_id, worker_id)
8778 LEFT OUTER JOIN batcher_allocations_cte USING (operator_id, worker_id)
8779)
8780SELECT
8781 operator_id, worker_id, records, batches, size, capacity, allocations
8782FROM combined
8783WHERE
8784 records IS NOT NULL
8785 OR batches IS NOT NULL
8786 OR size IS NOT NULL
8787 OR capacity IS NOT NULL
8788 OR allocations IS NOT NULL
8789",
8790 access: vec![PUBLIC_SELECT],
8791 }
8792});
8793
8794pub static MZ_ARRANGEMENT_SIZES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8795 name: "mz_arrangement_sizes",
8796 schema: MZ_INTROSPECTION_SCHEMA,
8797 oid: oid::VIEW_MZ_ARRANGEMENT_SIZES_OID,
8798 desc: RelationDesc::builder()
8799 .with_column("operator_id", SqlScalarType::UInt64.nullable(false))
8800 .with_column("records", SqlScalarType::Int64.nullable(true))
8801 .with_column("batches", SqlScalarType::Int64.nullable(true))
8802 .with_column("size", SqlScalarType::Int64.nullable(true))
8803 .with_column("capacity", SqlScalarType::Int64.nullable(true))
8804 .with_column("allocations", SqlScalarType::Int64.nullable(true))
8805 .with_key(vec![0])
8806 .finish(),
8807 column_comments: BTreeMap::from_iter([
8808 (
8809 "operator_id",
8810 "The ID of the operator that created the arrangement. Corresponds to `mz_dataflow_operators.id`.",
8811 ),
8812 ("records", "The number of records in the arrangement."),
8813 ("batches", "The number of batches in the arrangement."),
8814 ("size", "The utilized size in bytes of the arrangement."),
8815 (
8816 "capacity",
8817 "The capacity in bytes of the arrangement. Can be larger than the size.",
8818 ),
8819 (
8820 "allocations",
8821 "The number of separate memory allocations backing the arrangement.",
8822 ),
8823 ]),
8824 sql: "
8825SELECT
8826 operator_id,
8827 SUM(records)::int8 AS records,
8828 SUM(batches)::int8 AS batches,
8829 SUM(size)::int8 AS size,
8830 SUM(capacity)::int8 AS capacity,
8831 SUM(allocations)::int8 AS allocations
8832FROM mz_introspection.mz_arrangement_sizes_per_worker
8833GROUP BY operator_id",
8834 access: vec![PUBLIC_SELECT],
8835});
8836
8837pub static MZ_ARRANGEMENT_SHARING_PER_WORKER: LazyLock<BuiltinView> =
8838 LazyLock::new(|| BuiltinView {
8839 name: "mz_arrangement_sharing_per_worker",
8840 schema: MZ_INTROSPECTION_SCHEMA,
8841 oid: oid::VIEW_MZ_ARRANGEMENT_SHARING_PER_WORKER_OID,
8842 desc: RelationDesc::builder()
8843 .with_column("operator_id", SqlScalarType::UInt64.nullable(false))
8844 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8845 .with_column("count", SqlScalarType::Int64.nullable(false))
8846 .with_key(vec![0, 1])
8847 .finish(),
8848 column_comments: BTreeMap::new(),
8849 sql: "
8850SELECT
8851 operator_id,
8852 worker_id,
8853 pg_catalog.count(*) AS count
8854FROM mz_introspection.mz_arrangement_sharing_raw
8855GROUP BY operator_id, worker_id",
8856 access: vec![PUBLIC_SELECT],
8857 });
8858
8859pub static MZ_ARRANGEMENT_SHARING: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8860 name: "mz_arrangement_sharing",
8861 schema: MZ_INTROSPECTION_SCHEMA,
8862 oid: oid::VIEW_MZ_ARRANGEMENT_SHARING_OID,
8863 desc: RelationDesc::builder()
8864 .with_column("operator_id", SqlScalarType::UInt64.nullable(false))
8865 .with_column("count", SqlScalarType::Int64.nullable(false))
8866 .finish(),
8867 column_comments: BTreeMap::from_iter([
8868 (
8869 "operator_id",
8870 "The ID of the operator that created the arrangement. Corresponds to `mz_dataflow_operators.id`.",
8871 ),
8872 (
8873 "count",
8874 "The number of operators that share the arrangement.",
8875 ),
8876 ]),
8877 sql: "
8878SELECT operator_id, count
8879FROM mz_introspection.mz_arrangement_sharing_per_worker
8880WHERE worker_id = 0",
8881 access: vec![PUBLIC_SELECT],
8882});
8883
8884pub static MZ_CLUSTER_REPLICA_UTILIZATION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
8885 name: "mz_cluster_replica_utilization",
8886 schema: MZ_INTERNAL_SCHEMA,
8887 oid: oid::VIEW_MZ_CLUSTER_REPLICA_UTILIZATION_OID,
8888 desc: RelationDesc::builder()
8889 .with_column("replica_id", SqlScalarType::String.nullable(false))
8890 .with_column("process_id", SqlScalarType::UInt64.nullable(false))
8891 .with_column("cpu_percent", SqlScalarType::Float64.nullable(true))
8892 .with_column("memory_percent", SqlScalarType::Float64.nullable(true))
8893 .with_column("disk_percent", SqlScalarType::Float64.nullable(true))
8894 .with_column("heap_percent", SqlScalarType::Float64.nullable(true))
8895 .finish(),
8896 column_comments: BTreeMap::from_iter([
8897 ("replica_id", "The ID of a cluster replica."),
8898 ("process_id", "The ID of a process within the replica."),
8899 (
8900 "cpu_percent",
8901 "Approximate CPU usage, in percent of the total allocation.",
8902 ),
8903 (
8904 "memory_percent",
8905 "Approximate RAM usage, in percent of the total allocation.",
8906 ),
8907 (
8908 "disk_percent",
8909 "Approximate disk usage, in percent of the total allocation.",
8910 ),
8911 (
8912 "heap_percent",
8913 "Approximate heap (RAM + swap) usage, in percent of the total allocation.",
8914 ),
8915 ]),
8916 sql: "
8917SELECT
8918 r.id AS replica_id,
8919 m.process_id,
8920 m.cpu_nano_cores::float8 / NULLIF(s.cpu_nano_cores, 0) * 100 AS cpu_percent,
8921 m.memory_bytes::float8 / NULLIF(s.memory_bytes, 0) * 100 AS memory_percent,
8922 m.disk_bytes::float8 / NULLIF(s.disk_bytes, 0) * 100 AS disk_percent,
8923 m.heap_bytes::float8 / NULLIF(m.heap_limit, 0) * 100 AS heap_percent
8924FROM
8925 mz_catalog.mz_cluster_replicas AS r
8926 JOIN mz_catalog.mz_cluster_replica_sizes AS s ON r.size = s.size
8927 JOIN mz_internal.mz_cluster_replica_metrics AS m ON m.replica_id = r.id",
8928 access: vec![PUBLIC_SELECT],
8929});
8930
8931pub static MZ_CLUSTER_REPLICA_UTILIZATION_HISTORY: LazyLock<BuiltinView> =
8932 LazyLock::new(|| BuiltinView {
8933 name: "mz_cluster_replica_utilization_history",
8934 schema: MZ_INTERNAL_SCHEMA,
8935 oid: oid::VIEW_MZ_CLUSTER_REPLICA_UTILIZATION_HISTORY_OID,
8936 desc: RelationDesc::builder()
8937 .with_column("replica_id", SqlScalarType::String.nullable(false))
8938 .with_column("process_id", SqlScalarType::UInt64.nullable(false))
8939 .with_column("cpu_percent", SqlScalarType::Float64.nullable(true))
8940 .with_column("memory_percent", SqlScalarType::Float64.nullable(true))
8941 .with_column("disk_percent", SqlScalarType::Float64.nullable(true))
8942 .with_column("heap_percent", SqlScalarType::Float64.nullable(true))
8943 .with_column(
8944 "occurred_at",
8945 SqlScalarType::TimestampTz { precision: None }.nullable(false),
8946 )
8947 .finish(),
8948 column_comments: BTreeMap::from_iter([
8949 ("replica_id", "The ID of a cluster replica."),
8950 ("process_id", "The ID of a process within the replica."),
8951 (
8952 "cpu_percent",
8953 "Approximate CPU usage, in percent of the total allocation.",
8954 ),
8955 (
8956 "memory_percent",
8957 "Approximate RAM usage, in percent of the total allocation.",
8958 ),
8959 (
8960 "disk_percent",
8961 "Approximate disk usage, in percent of the total allocation.",
8962 ),
8963 (
8964 "heap_percent",
8965 "Approximate heap (RAM + swap) usage, in percent of the total allocation.",
8966 ),
8967 (
8968 "occurred_at",
8969 "Wall-clock timestamp at which the event occurred.",
8970 ),
8971 ]),
8972 sql: "
8973SELECT
8974 r.id AS replica_id,
8975 m.process_id,
8976 m.cpu_nano_cores::float8 / NULLIF(s.cpu_nano_cores, 0) * 100 AS cpu_percent,
8977 m.memory_bytes::float8 / NULLIF(s.memory_bytes, 0) * 100 AS memory_percent,
8978 m.disk_bytes::float8 / NULLIF(s.disk_bytes, 0) * 100 AS disk_percent,
8979 m.heap_bytes::float8 / NULLIF(m.heap_limit, 0) * 100 AS heap_percent,
8980 m.occurred_at
8981FROM
8982 mz_catalog.mz_cluster_replicas AS r
8983 JOIN mz_catalog.mz_cluster_replica_sizes AS s ON r.size = s.size
8984 JOIN mz_internal.mz_cluster_replica_metrics_history AS m ON m.replica_id = r.id",
8985 access: vec![PUBLIC_SELECT],
8986 });
8987
8988pub static MZ_DATAFLOW_OPERATOR_PARENTS_PER_WORKER: LazyLock<BuiltinView> =
8989 LazyLock::new(|| BuiltinView {
8990 name: "mz_dataflow_operator_parents_per_worker",
8991 schema: MZ_INTROSPECTION_SCHEMA,
8992 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_PARENTS_PER_WORKER_OID,
8993 desc: RelationDesc::builder()
8994 .with_column("id", SqlScalarType::UInt64.nullable(false))
8995 .with_column("parent_id", SqlScalarType::UInt64.nullable(false))
8996 .with_column("worker_id", SqlScalarType::UInt64.nullable(false))
8997 .finish(),
8998 column_comments: BTreeMap::new(),
8999 sql: "
9000WITH operator_addrs AS(
9001 SELECT
9002 id, address, worker_id
9003 FROM mz_introspection.mz_dataflow_addresses_per_worker
9004 INNER JOIN mz_introspection.mz_dataflow_operators_per_worker
9005 USING (id, worker_id)
9006),
9007parent_addrs AS (
9008 SELECT
9009 id,
9010 address[1:list_length(address) - 1] AS parent_address,
9011 worker_id
9012 FROM operator_addrs
9013)
9014SELECT pa.id, oa.id AS parent_id, pa.worker_id
9015FROM parent_addrs AS pa
9016 INNER JOIN operator_addrs AS oa
9017 ON pa.parent_address = oa.address
9018 AND pa.worker_id = oa.worker_id",
9019 access: vec![PUBLIC_SELECT],
9020 });
9021
9022pub static MZ_DATAFLOW_OPERATOR_PARENTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9023 name: "mz_dataflow_operator_parents",
9024 schema: MZ_INTROSPECTION_SCHEMA,
9025 oid: oid::VIEW_MZ_DATAFLOW_OPERATOR_PARENTS_OID,
9026 desc: RelationDesc::builder()
9027 .with_column("id", SqlScalarType::UInt64.nullable(false))
9028 .with_column("parent_id", SqlScalarType::UInt64.nullable(false))
9029 .finish(),
9030 column_comments: BTreeMap::from_iter([
9031 (
9032 "id",
9033 "The ID of the operator. Corresponds to `mz_dataflow_operators.id`.",
9034 ),
9035 (
9036 "parent_id",
9037 "The ID of the operator's parent operator. Corresponds to `mz_dataflow_operators.id`.",
9038 ),
9039 ]),
9040 sql: "
9041SELECT id, parent_id
9042FROM mz_introspection.mz_dataflow_operator_parents_per_worker
9043WHERE worker_id = 0",
9044 access: vec![PUBLIC_SELECT],
9045});
9046
9047pub static MZ_DATAFLOW_ARRANGEMENT_SIZES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9048 name: "mz_dataflow_arrangement_sizes",
9049 schema: MZ_INTROSPECTION_SCHEMA,
9050 oid: oid::VIEW_MZ_DATAFLOW_ARRANGEMENT_SIZES_OID,
9051 desc: RelationDesc::builder()
9052 .with_column("id", SqlScalarType::UInt64.nullable(false))
9053 .with_column("name", SqlScalarType::String.nullable(false))
9054 .with_column("records", SqlScalarType::Int64.nullable(true))
9055 .with_column("batches", SqlScalarType::Int64.nullable(true))
9056 .with_column("size", SqlScalarType::Int64.nullable(true))
9057 .with_column("capacity", SqlScalarType::Int64.nullable(true))
9058 .with_column("allocations", SqlScalarType::Int64.nullable(true))
9059 .with_key(vec![0, 1])
9060 .finish(),
9061 column_comments: BTreeMap::from_iter([
9062 (
9063 "id",
9064 "The ID of the [dataflow]. Corresponds to `mz_dataflows.id`.",
9065 ),
9066 ("name", "The name of the [dataflow]."),
9067 (
9068 "records",
9069 "The number of records in all arrangements in the dataflow.",
9070 ),
9071 (
9072 "batches",
9073 "The number of batches in all arrangements in the dataflow.",
9074 ),
9075 ("size", "The utilized size in bytes of the arrangements."),
9076 (
9077 "capacity",
9078 "The capacity in bytes of the arrangements. Can be larger than the size.",
9079 ),
9080 (
9081 "allocations",
9082 "The number of separate memory allocations backing the arrangements.",
9083 ),
9084 ]),
9085 sql: "
9086SELECT
9087 mdod.dataflow_id AS id,
9088 mdod.dataflow_name AS name,
9089 SUM(mas.records)::int8 AS records,
9090 SUM(mas.batches)::int8 AS batches,
9091 SUM(mas.size)::int8 AS size,
9092 SUM(mas.capacity)::int8 AS capacity,
9093 SUM(mas.allocations)::int8 AS allocations
9094FROM mz_introspection.mz_dataflow_operator_dataflows AS mdod
9095LEFT JOIN mz_introspection.mz_arrangement_sizes AS mas
9096 ON mdod.id = mas.operator_id
9097GROUP BY mdod.dataflow_id, mdod.dataflow_name",
9098 access: vec![PUBLIC_SELECT],
9099});
9100
9101pub static MZ_EXPECTED_GROUP_SIZE_ADVICE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9102 name: "mz_expected_group_size_advice",
9103 schema: MZ_INTROSPECTION_SCHEMA,
9104 oid: oid::VIEW_MZ_EXPECTED_GROUP_SIZE_ADVICE_OID,
9105 desc: RelationDesc::builder()
9106 .with_column("dataflow_id", SqlScalarType::UInt64.nullable(false))
9107 .with_column("dataflow_name", SqlScalarType::String.nullable(false))
9108 .with_column("region_id", SqlScalarType::UInt64.nullable(false))
9109 .with_column("region_name", SqlScalarType::String.nullable(false))
9110 .with_column("levels", SqlScalarType::Int64.nullable(false))
9111 .with_column("to_cut", SqlScalarType::Int64.nullable(false))
9112 .with_column(
9113 "savings",
9114 SqlScalarType::Numeric {
9115 max_scale: Some(NumericMaxScale::ZERO),
9116 }
9117 .nullable(true),
9118 )
9119 .with_column("hint", SqlScalarType::Float64.nullable(false))
9120 .finish(),
9121 column_comments: BTreeMap::from_iter([
9122 (
9123 "dataflow_id",
9124 "The ID of the [dataflow]. Corresponds to `mz_dataflows.id`.",
9125 ),
9126 (
9127 "dataflow_name",
9128 "The internal name of the dataflow hosting the min/max aggregation or Top K.",
9129 ),
9130 (
9131 "region_id",
9132 "The ID of the root operator scope. Corresponds to `mz_dataflow_operators.id`.",
9133 ),
9134 (
9135 "region_name",
9136 "The internal name of the root operator scope for the min/max aggregation or Top K.",
9137 ),
9138 (
9139 "levels",
9140 "The number of levels in the hierarchical scheme implemented by the region.",
9141 ),
9142 (
9143 "to_cut",
9144 "The number of levels that can be eliminated (cut) from the region's hierarchy.",
9145 ),
9146 (
9147 "savings",
9148 "A conservative estimate of the amount of memory in bytes to be saved by applying the hint.",
9149 ),
9150 (
9151 "hint",
9152 "The hint value that will eliminate `to_cut` levels from the region's hierarchy.",
9153 ),
9154 ]),
9155 sql: "
9156 -- The mz_expected_group_size_advice view provides tuning suggestions for the GROUP SIZE
9157 -- query hints. This tuning hint is effective for min/max/top-k patterns, where a stack
9158 -- of arrangements must be built. For each dataflow and region corresponding to one
9159 -- such pattern, we look for how many levels can be eliminated without hitting a level
9160 -- that actually substantially filters the input. The advice is constructed so that
9161 -- setting the hint for the affected region will eliminate these redundant levels of
9162 -- the hierarchical rendering.
9163 --
9164 -- A number of helper CTEs are used for the view definition. The first one, operators,
9165 -- looks for operator names that comprise arrangements of inputs to each level of a
9166 -- min/max/top-k hierarchy.
9167 WITH operators AS (
9168 SELECT
9169 dod.dataflow_id,
9170 dor.id AS region_id,
9171 dod.id,
9172 ars.records,
9173 ars.size
9174 FROM
9175 mz_introspection.mz_dataflow_operator_dataflows dod
9176 JOIN mz_introspection.mz_dataflow_addresses doa
9177 ON dod.id = doa.id
9178 JOIN mz_introspection.mz_dataflow_addresses dra
9179 ON dra.address = doa.address[:list_length(doa.address) - 1]
9180 JOIN mz_introspection.mz_dataflow_operators dor
9181 ON dor.id = dra.id
9182 JOIN mz_introspection.mz_arrangement_sizes ars
9183 ON ars.operator_id = dod.id
9184 WHERE
9185 dod.name = 'Arranged TopK input'
9186 OR dod.name = 'Arranged MinsMaxesHierarchical input'
9187 OR dod.name = 'Arrange ReduceMinsMaxes'
9188 ),
9189 -- The second CTE, levels, simply computes the heights of the min/max/top-k hierarchies
9190 -- identified in operators above.
9191 levels AS (
9192 SELECT o.dataflow_id, o.region_id, COUNT(*) AS levels
9193 FROM operators o
9194 GROUP BY o.dataflow_id, o.region_id
9195 ),
9196 -- The third CTE, pivot, determines for each min/max/top-k hierarchy, the first input
9197 -- operator. This operator is crucially important, as it records the number of records
9198 -- that was given as input to the gadget as a whole.
9199 pivot AS (
9200 SELECT
9201 o1.dataflow_id,
9202 o1.region_id,
9203 o1.id,
9204 o1.records
9205 FROM operators o1
9206 WHERE
9207 o1.id = (
9208 SELECT MIN(o2.id)
9209 FROM operators o2
9210 WHERE
9211 o2.dataflow_id = o1.dataflow_id
9212 AND o2.region_id = o1.region_id
9213 OPTIONS (AGGREGATE INPUT GROUP SIZE = 8)
9214 )
9215 ),
9216 -- The fourth CTE, candidates, will look for operators where the number of records
9217 -- maintained is not significantly different from the number at the pivot (excluding
9218 -- the pivot itself). These are the candidates for being cut from the dataflow region
9219 -- by adjusting the hint. The query includes a constant, heuristically tuned on TPC-H
9220 -- load generator data, to give some room for small deviations in number of records.
9221 -- The intuition for allowing for this deviation is that we are looking for a strongly
9222 -- reducing point in the hierarchy. To see why one such operator ought to exist in an
9223 -- untuned hierarchy, consider that at each level, we use hashing to distribute rows
9224 -- among groups where the min/max/top-k computation is (partially) applied. If the
9225 -- hierarchy has too many levels, the first-level (pivot) groups will be such that many
9226 -- groups might be empty or contain only one row. Each subsequent level will have a number
9227 -- of groups that is reduced exponentially. So at some point, we will find the level where
9228 -- we actually start having a few rows per group. That's where we will see the row counts
9229 -- significantly drop off.
9230 candidates AS (
9231 SELECT
9232 o.dataflow_id,
9233 o.region_id,
9234 o.id,
9235 o.records,
9236 o.size
9237 FROM
9238 operators o
9239 JOIN pivot p
9240 ON o.dataflow_id = p.dataflow_id
9241 AND o.region_id = p.region_id
9242 AND o.id <> p.id
9243 WHERE o.records >= p.records * (1 - 0.15)
9244 ),
9245 -- The fifth CTE, cuts, computes for each relevant dataflow region, the number of
9246 -- candidate levels that should be cut. We only return here dataflow regions where at
9247 -- least one level must be cut. Note that once we hit a point where the hierarchy starts
9248 -- to have a filtering effect, i.e., after the last candidate, it is dangerous to suggest
9249 -- cutting the height of the hierarchy further. This is because we will have way less
9250 -- groups in the next level, so there should be even further reduction happening or there
9251 -- is some substantial skew in the data. But if the latter is the case, then we should not
9252 -- tune the GROUP SIZE hints down anyway to avoid hurting latency upon updates directed
9253 -- at these unusually large groups. In addition to selecting the levels to cut, we also
9254 -- compute a conservative estimate of the memory savings in bytes that will result from
9255 -- cutting these levels from the hierarchy. The estimate is based on the sizes of the
9256 -- input arrangements for each level to be cut. These arrangements should dominate the
9257 -- size of each level that can be cut, since the reduction gadget internal to the level
9258 -- does not remove much data at these levels.
9259 cuts AS (
9260 SELECT c.dataflow_id, c.region_id, COUNT(*) AS to_cut, SUM(c.size) AS savings
9261 FROM candidates c
9262 GROUP BY c.dataflow_id, c.region_id
9263 HAVING COUNT(*) > 0
9264 )
9265 -- Finally, we compute the hint suggestion for each dataflow region based on the number of
9266 -- levels and the number of candidates to be cut. The hint is computed taking into account
9267 -- the fan-in used in rendering for the hash partitioning and reduction of the groups,
9268 -- currently equal to 16.
9269 SELECT
9270 dod.dataflow_id,
9271 dod.dataflow_name,
9272 dod.id AS region_id,
9273 dod.name AS region_name,
9274 l.levels,
9275 c.to_cut,
9276 c.savings,
9277 pow(16, l.levels - c.to_cut) - 1 AS hint
9278 FROM cuts c
9279 JOIN levels l
9280 ON c.dataflow_id = l.dataflow_id AND c.region_id = l.region_id
9281 JOIN mz_introspection.mz_dataflow_operator_dataflows dod
9282 ON dod.dataflow_id = c.dataflow_id AND dod.id = c.region_id",
9283 access: vec![PUBLIC_SELECT],
9284});
9285
9286pub static MZ_INDEX_ADVICE: LazyLock<BuiltinView> = LazyLock::new(|| {
9287 BuiltinView {
9288 name: "mz_index_advice",
9289 schema: MZ_INTERNAL_SCHEMA,
9290 oid: oid::VIEW_MZ_INDEX_ADVICE_OID,
9291 desc: RelationDesc::builder()
9292 .with_column("object_id", SqlScalarType::String.nullable(true))
9293 .with_column("hint", SqlScalarType::String.nullable(false))
9294 .with_column("details", SqlScalarType::String.nullable(false))
9295 .with_column("referenced_object_ids", SqlScalarType::List { element_type: Box::new(SqlScalarType::String), custom_id: None }.nullable(true))
9296 .finish(),
9297 column_comments: BTreeMap::from_iter([
9298 ("object_id", "The ID of the object. Corresponds to mz_objects.id."),
9299 ("hint", "A suggestion to either change the object (e.g. create an index, turn a materialized view into an indexed view) or keep the object unchanged."),
9300 ("details", "Additional details on why the `hint` was proposed based on the dependencies of the object."),
9301 ("referenced_object_ids", "The IDs of objects referenced by `details`. Corresponds to mz_objects.id."),
9302 ]),
9303 sql: "
9304-- To avoid confusion with sources and sinks in the materialize sense,
9305-- the following uses the terms leafs (instead of sinks) and roots (instead of sources)
9306-- when referring to the object dependency graph.
9307--
9308-- The basic idea is to walk up the dependency graph to propagate the transitive dependencies
9309-- of maintained objected upwards. The leaves of the dependency graph are maintained objects
9310-- that are not depended on by other maintained objects and have a justification why they must
9311-- be maintained (e.g. a materialized view that is depended on by a sink).
9312-- Starting from these leaves, the dependencies are propagated upwards towards the roots according
9313-- to the object dependencies. Whenever there is a node that is being depended on by multiple
9314-- downstream objects, that node is marked to be converted into a maintained object and this
9315-- node is then propagated further up. Once completed, the list of objects that are marked as
9316-- maintained is checked against all objects to generate appropriate recommendations.
9317--
9318-- Note that the recommendations only incorporate dependencies between objects.
9319-- This can lead to bad recommendations, e.g. filters can no longer be pushed into (or close to)
9320-- a sink if an index is added in between the sink and the filter. For very selective filters,
9321-- this can lead to redundant work: the index is computing stuff only to discarded by the selective
9322-- filter later on. But these kind of aspects cannot be understood by merely looking at the
9323-- dependencies.
9324WITH MUTUALLY RECURSIVE
9325 -- for all objects, understand if they have an index on them and on which cluster they are running
9326 -- this avoids having different cases for views with an index and materialized views later on
9327 objects(id text, type text, cluster_id text, indexes text list) AS (
9328 -- views and materialized views without an index
9329 SELECT
9330 o.id,
9331 o.type,
9332 o.cluster_id,
9333 '{}'::text list AS indexes
9334 FROM mz_catalog.mz_objects o
9335 WHERE o.id LIKE 'u%' AND o.type IN ('materialized-view', 'view') AND NOT EXISTS (
9336 SELECT FROM mz_internal.mz_object_dependencies d
9337 JOIN mz_catalog.mz_objects AS i
9338 ON (i.id = d.object_id AND i.type = 'index')
9339 WHERE (o.id = d.referenced_object_id)
9340 )
9341
9342 UNION ALL
9343
9344 -- views and materialized views with an index
9345 SELECT
9346 o.id,
9347 o.type,
9348 -- o.cluster_id is always NULL for views, so use the cluster of the index instead
9349 COALESCE(o.cluster_id, i.cluster_id) AS cluster_id,
9350 list_agg(i.id) AS indexes
9351 FROM mz_catalog.mz_objects o
9352 JOIN mz_internal.mz_object_dependencies AS d
9353 ON (o.id = d.referenced_object_id)
9354 JOIN mz_catalog.mz_objects AS i
9355 ON (i.id = d.object_id AND i.type = 'index')
9356 WHERE o.id LIKE 'u%' AND o.type IN ('materialized-view', 'view', 'source')
9357 GROUP BY o.id, o.type, o.cluster_id, i.cluster_id
9358 ),
9359
9360 -- maintained objects that are at the leafs of the dependency graph with respect to a specific cluster
9361 maintained_leafs(id text, justification text) AS (
9362 -- materialized views that are connected to a sink
9363 SELECT
9364 m.id,
9365 s.id AS justification
9366 FROM objects AS m
9367 JOIN mz_internal.mz_object_dependencies AS d
9368 ON (m.id = d.referenced_object_id)
9369 JOIN mz_catalog.mz_objects AS s
9370 ON (s.id = d.object_id AND s.type = 'sink')
9371 WHERE m.type = 'materialized-view'
9372
9373 UNION ALL
9374
9375 -- (materialized) views with an index that are not transitively depend on by maintained objects on the same cluster
9376 SELECT
9377 v.id,
9378 unnest(v.indexes) AS justification
9379 FROM objects AS v
9380 WHERE v.type IN ('view', 'materialized-view', 'source') AND NOT EXISTS (
9381 SELECT FROM mz_internal.mz_object_transitive_dependencies AS d
9382 INNER JOIN mz_catalog.mz_objects AS child
9383 ON (d.object_id = child.id)
9384 WHERE d.referenced_object_id = v.id AND child.type IN ('materialized-view', 'index') AND v.cluster_id = child.cluster_id AND NOT v.indexes @> LIST[child.id]
9385 )
9386 ),
9387
9388 -- this is just a helper cte to union multiple lists as part of an aggregation, which is not directly possible in SQL
9389 agg_maintained_children(id text, maintained_children text list) AS (
9390 SELECT
9391 parent_id AS id,
9392 list_agg(maintained_child) AS maintained_leafs
9393 FROM (
9394 SELECT DISTINCT
9395 d.referenced_object_id AS parent_id,
9396 -- it's not possible to union lists in an aggregation, so we have to unnest the list first
9397 unnest(child.maintained_children) AS maintained_child
9398 FROM propagate_dependencies AS child
9399 INNER JOIN mz_internal.mz_object_dependencies AS d
9400 ON (child.id = d.object_id)
9401 )
9402 GROUP BY parent_id
9403 ),
9404
9405 -- propagate dependencies of maintained objects from the leafs to the roots of the dependency graph and
9406 -- record a justification when an object should be maintained, e.g. when it is depended on by more than one maintained object
9407 -- when an object should be maintained, maintained_children will just contain that object so that further upstream objects refer to it in their maintained_children
9408 propagate_dependencies(id text, maintained_children text list, justification text list) AS (
9409 -- base case: start with the leafs
9410 SELECT DISTINCT
9411 id,
9412 LIST[id] AS maintained_children,
9413 list_agg(justification) AS justification
9414 FROM maintained_leafs
9415 GROUP BY id
9416
9417 UNION
9418
9419 -- recursive case: if there is a child with the same dependencies as the parent,
9420 -- the parent is only reused by a single child
9421 SELECT
9422 parent.id,
9423 child.maintained_children,
9424 NULL::text list AS justification
9425 FROM agg_maintained_children AS parent
9426 INNER JOIN mz_internal.mz_object_dependencies AS d
9427 ON (parent.id = d.referenced_object_id)
9428 INNER JOIN propagate_dependencies AS child
9429 ON (d.object_id = child.id)
9430 WHERE parent.maintained_children = child.maintained_children
9431
9432 UNION
9433
9434 -- recursive case: if there is NO child with the same dependencies as the parent,
9435 -- different children are reusing the parent so maintaining the object is justified by itself
9436 SELECT DISTINCT
9437 parent.id,
9438 LIST[parent.id] AS maintained_children,
9439 parent.maintained_children AS justification
9440 FROM agg_maintained_children AS parent
9441 WHERE NOT EXISTS (
9442 SELECT FROM mz_internal.mz_object_dependencies AS d
9443 INNER JOIN propagate_dependencies AS child
9444 ON (d.object_id = child.id AND d.referenced_object_id = parent.id)
9445 WHERE parent.maintained_children = child.maintained_children
9446 )
9447 ),
9448
9449 objects_with_justification(id text, type text, cluster_id text, maintained_children text list, justification text list, indexes text list) AS (
9450 SELECT
9451 p.id,
9452 o.type,
9453 o.cluster_id,
9454 p.maintained_children,
9455 p.justification,
9456 o.indexes
9457 FROM propagate_dependencies p
9458 JOIN objects AS o
9459 ON (p.id = o.id)
9460 ),
9461
9462 hints(id text, hint text, details text, justification text list) AS (
9463 -- materialized views that are not required
9464 SELECT
9465 id,
9466 'convert to a view' AS hint,
9467 'no dependencies from sinks nor from objects on different clusters' AS details,
9468 justification
9469 FROM objects_with_justification
9470 WHERE type = 'materialized-view' AND justification IS NULL
9471
9472 UNION ALL
9473
9474 -- materialized views that are required because a sink or a maintained object from a different cluster depends on them
9475 SELECT
9476 id,
9477 'keep' AS hint,
9478 'dependencies from sinks or objects on different clusters: ' AS details,
9479 justification
9480 FROM objects_with_justification AS m
9481 WHERE type = 'materialized-view' AND justification IS NOT NULL AND EXISTS (
9482 SELECT FROM unnest(justification) AS dependency
9483 JOIN mz_catalog.mz_objects s ON (s.type = 'sink' AND s.id = dependency)
9484
9485 UNION ALL
9486
9487 SELECT FROM unnest(justification) AS dependency
9488 JOIN mz_catalog.mz_objects AS d ON (d.id = dependency)
9489 WHERE d.cluster_id != m.cluster_id
9490 )
9491
9492 UNION ALL
9493
9494 -- materialized views that can be converted to a view with or without an index because NO sink or a maintained object from a different cluster depends on them
9495 SELECT
9496 id,
9497 'convert to a view with an index' AS hint,
9498 'no dependencies from sinks nor from objects on different clusters, but maintained dependencies on the same cluster: ' AS details,
9499 justification
9500 FROM objects_with_justification AS m
9501 WHERE type = 'materialized-view' AND justification IS NOT NULL AND NOT EXISTS (
9502 SELECT FROM unnest(justification) AS dependency
9503 JOIN mz_catalog.mz_objects s ON (s.type = 'sink' AND s.id = dependency)
9504
9505 UNION ALL
9506
9507 SELECT FROM unnest(justification) AS dependency
9508 JOIN mz_catalog.mz_objects AS d ON (d.id = dependency)
9509 WHERE d.cluster_id != m.cluster_id
9510 )
9511
9512 UNION ALL
9513
9514 -- views that have indexes on different clusters should be a materialized view
9515 SELECT
9516 o.id,
9517 'convert to materialized view' AS hint,
9518 'dependencies on multiple clusters: ' AS details,
9519 o.justification
9520 FROM objects_with_justification o,
9521 LATERAL unnest(o.justification) j
9522 LEFT JOIN mz_catalog.mz_objects AS m
9523 ON (m.id = j AND m.type IN ('index', 'materialized-view'))
9524 WHERE o.type = 'view' AND o.justification IS NOT NULL
9525 GROUP BY o.id, o.justification
9526 HAVING count(DISTINCT m.cluster_id) >= 2
9527
9528 UNION ALL
9529
9530 -- views without an index that should be maintained
9531 SELECT
9532 id,
9533 'add index' AS hint,
9534 'multiple downstream dependencies: ' AS details,
9535 justification
9536 FROM objects_with_justification
9537 WHERE type = 'view' AND justification IS NOT NULL AND indexes = '{}'::text list
9538
9539 UNION ALL
9540
9541 -- index inside the dependency graph (not a leaf)
9542 SELECT
9543 unnest(indexes) AS id,
9544 'drop unless queried directly' AS hint,
9545 'fewer than two downstream dependencies: ' AS details,
9546 maintained_children AS justification
9547 FROM objects_with_justification
9548 WHERE type = 'view' AND NOT indexes = '{}'::text list AND justification IS NULL
9549
9550 UNION ALL
9551
9552 -- index on a leaf of the dependency graph
9553 SELECT
9554 unnest(indexes) AS id,
9555 'drop unless queried directly' AS hint,
9556 'associated object does not have any dependencies (maintained or not maintained)' AS details,
9557 NULL::text list AS justification
9558 FROM objects_with_justification
9559 -- indexes can only be part of justification for leaf nodes
9560 WHERE type IN ('view', 'materialized-view') AND NOT indexes = '{}'::text list AND justification @> indexes
9561
9562 UNION ALL
9563
9564 -- index on a source
9565 SELECT
9566 unnest(indexes) AS id,
9567 'drop unless queried directly' AS hint,
9568 'sources do not transform data and can expose data directly' AS details,
9569 NULL::text list AS justification
9570 FROM objects_with_justification
9571 -- indexes can only be part of justification for leaf nodes
9572 WHERE type = 'source' AND NOT indexes = '{}'::text list
9573
9574 UNION ALL
9575
9576 -- indexes on views inside the dependency graph
9577 SELECT
9578 unnest(indexes) AS id,
9579 'keep' AS hint,
9580 'multiple downstream dependencies: ' AS details,
9581 justification
9582 FROM objects_with_justification
9583 -- indexes can only be part of justification for leaf nodes
9584 WHERE type = 'view' AND justification IS NOT NULL AND NOT indexes = '{}'::text list AND NOT justification @> indexes
9585 ),
9586
9587 hints_resolved_ids(id text, hint text, details text, justification text list) AS (
9588 SELECT
9589 h.id,
9590 h.hint,
9591 h.details || list_agg(o.name)::text AS details,
9592 h.justification
9593 FROM hints AS h,
9594 LATERAL unnest(h.justification) j
9595 JOIN mz_catalog.mz_objects AS o
9596 ON (o.id = j)
9597 GROUP BY h.id, h.hint, h.details, h.justification
9598
9599 UNION ALL
9600
9601 SELECT
9602 id,
9603 hint,
9604 details,
9605 justification
9606 FROM hints
9607 WHERE justification IS NULL
9608 )
9609
9610SELECT
9611 h.id AS object_id,
9612 h.hint AS hint,
9613 h.details,
9614 h.justification AS referenced_object_ids
9615FROM hints_resolved_ids AS h",
9616 access: vec![PUBLIC_SELECT],
9617 }
9618});
9619
9620pub static PG_CONSTRAINT: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9623 name: "pg_constraint",
9624 schema: PG_CATALOG_SCHEMA,
9625 oid: oid::VIEW_PG_CONSTRAINT_OID,
9626 desc: RelationDesc::builder()
9627 .with_column("oid", SqlScalarType::Oid.nullable(false))
9628 .with_column("conname", SqlScalarType::String.nullable(false))
9629 .with_column("connamespace", SqlScalarType::Oid.nullable(false))
9630 .with_column("contype", SqlScalarType::PgLegacyChar.nullable(false))
9631 .with_column("condeferrable", SqlScalarType::Bool.nullable(false))
9632 .with_column("condeferred", SqlScalarType::Bool.nullable(false))
9633 .with_column("convalidated", SqlScalarType::Bool.nullable(false))
9634 .with_column("conrelid", SqlScalarType::Oid.nullable(false))
9635 .with_column("contypid", SqlScalarType::Oid.nullable(false))
9636 .with_column("conindid", SqlScalarType::Oid.nullable(false))
9637 .with_column("conparentid", SqlScalarType::Oid.nullable(false))
9638 .with_column("confrelid", SqlScalarType::Oid.nullable(false))
9639 .with_column("confupdtype", SqlScalarType::PgLegacyChar.nullable(false))
9640 .with_column("confdeltype", SqlScalarType::PgLegacyChar.nullable(false))
9641 .with_column("confmatchtype", SqlScalarType::PgLegacyChar.nullable(false))
9642 .with_column("conislocal", SqlScalarType::Bool.nullable(false))
9643 .with_column("coninhcount", SqlScalarType::Int32.nullable(false))
9644 .with_column("connoinherit", SqlScalarType::Bool.nullable(false))
9645 .with_column(
9646 "conkey",
9647 SqlScalarType::Array(Box::new(SqlScalarType::Int16)).nullable(false),
9648 )
9649 .with_column(
9650 "confkey",
9651 SqlScalarType::Array(Box::new(SqlScalarType::Int16)).nullable(false),
9652 )
9653 .with_column(
9654 "conpfeqop",
9655 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
9656 )
9657 .with_column(
9658 "conppeqop",
9659 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
9660 )
9661 .with_column(
9662 "conffeqop",
9663 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
9664 )
9665 .with_column(
9666 "conexclop",
9667 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
9668 )
9669 .with_column("conbin", SqlScalarType::String.nullable(false))
9670 .with_key(vec![])
9671 .finish(),
9672 column_comments: BTreeMap::new(),
9673 sql: "SELECT
9674 NULL::pg_catalog.oid as oid,
9675 NULL::pg_catalog.text as conname,
9676 NULL::pg_catalog.oid as connamespace,
9677 NULL::pg_catalog.\"char\" as contype,
9678 NULL::pg_catalog.bool as condeferrable,
9679 NULL::pg_catalog.bool as condeferred,
9680 NULL::pg_catalog.bool as convalidated,
9681 NULL::pg_catalog.oid as conrelid,
9682 NULL::pg_catalog.oid as contypid,
9683 NULL::pg_catalog.oid as conindid,
9684 NULL::pg_catalog.oid as conparentid,
9685 NULL::pg_catalog.oid as confrelid,
9686 NULL::pg_catalog.\"char\" as confupdtype,
9687 NULL::pg_catalog.\"char\" as confdeltype,
9688 NULL::pg_catalog.\"char\" as confmatchtype,
9689 NULL::pg_catalog.bool as conislocal,
9690 NULL::pg_catalog.int4 as coninhcount,
9691 NULL::pg_catalog.bool as connoinherit,
9692 NULL::pg_catalog.int2[] as conkey,
9693 NULL::pg_catalog.int2[] as confkey,
9694 NULL::pg_catalog.oid[] as conpfeqop,
9695 NULL::pg_catalog.oid[] as conppeqop,
9696 NULL::pg_catalog.oid[] as conffeqop,
9697 NULL::pg_catalog.oid[] as conexclop,
9698 NULL::pg_catalog.text as conbin
9699WHERE false",
9700 access: vec![PUBLIC_SELECT],
9701});
9702
9703pub static PG_TABLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9704 name: "pg_tables",
9705 schema: PG_CATALOG_SCHEMA,
9706 oid: oid::VIEW_PG_TABLES_OID,
9707 desc: RelationDesc::builder()
9708 .with_column("schemaname", SqlScalarType::String.nullable(true))
9709 .with_column("tablename", SqlScalarType::String.nullable(false))
9710 .with_column("tableowner", SqlScalarType::String.nullable(false))
9711 .finish(),
9712 column_comments: BTreeMap::new(),
9713 sql: "
9714SELECT n.nspname AS schemaname,
9715 c.relname AS tablename,
9716 pg_catalog.pg_get_userbyid(c.relowner) AS tableowner
9717FROM pg_catalog.pg_class c
9718LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
9719WHERE c.relkind IN ('r', 'p')",
9720 access: vec![PUBLIC_SELECT],
9721});
9722
9723pub static PG_TABLESPACE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9724 name: "pg_tablespace",
9725 schema: PG_CATALOG_SCHEMA,
9726 oid: oid::VIEW_PG_TABLESPACE_OID,
9727 desc: RelationDesc::builder()
9728 .with_column("oid", SqlScalarType::Oid.nullable(false))
9729 .with_column("spcname", SqlScalarType::String.nullable(false))
9730 .with_column("spcowner", SqlScalarType::Oid.nullable(true))
9731 .with_column(
9732 "spcacl",
9733 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
9734 )
9735 .with_column(
9736 "spcoptions",
9737 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
9738 )
9739 .with_key(vec![])
9740 .finish(),
9741 column_comments: BTreeMap::new(),
9742 sql: "
9743 SELECT oid, spcname, spcowner, spcacl, spcoptions
9744 FROM (
9745 VALUES (
9746 --These are the same defaults CockroachDB uses.
9747 0::pg_catalog.oid,
9748 'pg_default'::pg_catalog.text,
9749 NULL::pg_catalog.oid,
9750 NULL::pg_catalog.text[],
9751 NULL::pg_catalog.text[]
9752 )
9753 ) AS _ (oid, spcname, spcowner, spcacl, spcoptions)
9754",
9755 access: vec![PUBLIC_SELECT],
9756});
9757
9758pub static PG_ACCESS_METHODS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9759 name: "pg_am",
9760 schema: PG_CATALOG_SCHEMA,
9761 oid: oid::VIEW_PG_AM_OID,
9762 desc: RelationDesc::builder()
9763 .with_column("oid", SqlScalarType::Oid.nullable(false))
9764 .with_column("amname", SqlScalarType::String.nullable(false))
9765 .with_column("amhandler", SqlScalarType::RegProc.nullable(false))
9766 .with_column("amtype", SqlScalarType::PgLegacyChar.nullable(false))
9767 .with_key(vec![])
9768 .finish(),
9769 column_comments: BTreeMap::new(),
9770 sql: "
9771SELECT NULL::pg_catalog.oid AS oid,
9772 NULL::pg_catalog.text AS amname,
9773 NULL::pg_catalog.regproc AS amhandler,
9774 NULL::pg_catalog.\"char\" AS amtype
9775WHERE false",
9776 access: vec![PUBLIC_SELECT],
9777});
9778
9779pub static PG_ROLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9780 name: "pg_roles",
9781 schema: PG_CATALOG_SCHEMA,
9782 oid: oid::VIEW_PG_ROLES_OID,
9783 desc: RelationDesc::builder()
9784 .with_column("rolname", SqlScalarType::String.nullable(false))
9785 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
9786 .with_column("rolinherit", SqlScalarType::Bool.nullable(false))
9787 .with_column("rolcreaterole", SqlScalarType::Bool.nullable(true))
9788 .with_column("rolcreatedb", SqlScalarType::Bool.nullable(true))
9789 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(false))
9790 .with_column("rolreplication", SqlScalarType::Bool.nullable(false))
9791 .with_column("rolconnlimit", SqlScalarType::Int32.nullable(false))
9792 .with_column("rolpassword", SqlScalarType::String.nullable(false))
9793 .with_column(
9794 "rolvaliduntil",
9795 SqlScalarType::TimestampTz { precision: None }.nullable(true),
9796 )
9797 .with_column("rolbypassrls", SqlScalarType::Bool.nullable(false))
9798 .with_column(
9799 "rolconfig",
9800 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
9801 )
9802 .with_column("oid", SqlScalarType::Oid.nullable(false))
9803 .finish(),
9804 column_comments: BTreeMap::new(),
9805 sql: "SELECT
9806 rolname,
9807 rolsuper,
9808 rolinherit,
9809 rolcreaterole,
9810 rolcreatedb,
9811 COALESCE(rolcanlogin, false) AS rolcanlogin,
9812 rolreplication,
9813 rolconnlimit,
9814 '********' as rolpassword,
9815 rolvaliduntil,
9816 rolbypassrls,
9817 (
9818 SELECT array_agg(parameter_name || '=' || parameter_value)
9819 FROM mz_catalog.mz_role_parameters rp
9820 JOIN mz_catalog.mz_roles r ON r.id = rp.role_id
9821 WHERE ai.oid = r.oid
9822 ) AS rolconfig,
9823 oid
9824FROM pg_catalog.pg_authid ai",
9825 access: vec![PUBLIC_SELECT],
9826});
9827
9828pub static PG_USER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9829 name: "pg_user",
9830 schema: PG_CATALOG_SCHEMA,
9831 oid: oid::VIEW_PG_USER_OID,
9832 desc: RelationDesc::builder()
9833 .with_column("usename", SqlScalarType::String.nullable(false))
9834 .with_column("usesysid", SqlScalarType::Oid.nullable(false))
9835 .with_column("usecreatedb", SqlScalarType::Bool.nullable(true))
9836 .with_column("usesuper", SqlScalarType::Bool.nullable(true))
9837 .with_column("userepl", SqlScalarType::Bool.nullable(false))
9838 .with_column("usebypassrls", SqlScalarType::Bool.nullable(false))
9839 .with_column("passwd", SqlScalarType::String.nullable(true))
9840 .with_column(
9841 "valuntil",
9842 SqlScalarType::TimestampTz { precision: None }.nullable(true),
9843 )
9844 .with_column(
9845 "useconfig",
9846 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(true),
9847 )
9848 .finish(),
9849 column_comments: BTreeMap::new(),
9850 sql: "
9851SELECT
9852 rolname as usename,
9853 ai.oid as usesysid,
9854 rolcreatedb AS usecreatedb,
9855 rolsuper AS usesuper,
9856 rolreplication AS userepl,
9857 rolbypassrls AS usebypassrls,
9858 rolpassword as passwd,
9859 rolvaliduntil as valuntil,
9860 (
9861 SELECT array_agg(parameter_name || '=' || parameter_value)
9862 FROM mz_catalog.mz_role_parameters rp
9863 JOIN mz_catalog.mz_roles r ON r.id = rp.role_id
9864 WHERE ai.oid = r.oid
9865 ) AS useconfig
9866FROM pg_catalog.pg_authid ai
9867WHERE rolcanlogin",
9868 access: vec![PUBLIC_SELECT],
9869});
9870
9871pub static PG_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9872 name: "pg_views",
9873 schema: PG_CATALOG_SCHEMA,
9874 oid: oid::VIEW_PG_VIEWS_OID,
9875 desc: RelationDesc::builder()
9876 .with_column("schemaname", SqlScalarType::String.nullable(true))
9877 .with_column("viewname", SqlScalarType::String.nullable(false))
9878 .with_column("viewowner", SqlScalarType::Oid.nullable(false))
9879 .with_column("definition", SqlScalarType::String.nullable(false))
9880 .finish(),
9881 column_comments: BTreeMap::new(),
9882 sql: "SELECT
9883 s.name AS schemaname,
9884 v.name AS viewname,
9885 role_owner.oid AS viewowner,
9886 v.definition AS definition
9887FROM mz_catalog.mz_views v
9888LEFT JOIN mz_catalog.mz_schemas s ON s.id = v.schema_id
9889LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
9890JOIN mz_catalog.mz_roles role_owner ON role_owner.id = v.owner_id
9891WHERE s.database_id IS NULL OR d.name = current_database()",
9892 access: vec![PUBLIC_SELECT],
9893});
9894
9895pub static PG_MATVIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9896 name: "pg_matviews",
9897 schema: PG_CATALOG_SCHEMA,
9898 oid: oid::VIEW_PG_MATVIEWS_OID,
9899 desc: RelationDesc::builder()
9900 .with_column("schemaname", SqlScalarType::String.nullable(true))
9901 .with_column("matviewname", SqlScalarType::String.nullable(false))
9902 .with_column("matviewowner", SqlScalarType::Oid.nullable(false))
9903 .with_column("definition", SqlScalarType::String.nullable(false))
9904 .finish(),
9905 column_comments: BTreeMap::new(),
9906 sql: "SELECT
9907 s.name AS schemaname,
9908 m.name AS matviewname,
9909 role_owner.oid AS matviewowner,
9910 m.definition AS definition
9911FROM mz_catalog.mz_materialized_views m
9912LEFT JOIN mz_catalog.mz_schemas s ON s.id = m.schema_id
9913LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
9914JOIN mz_catalog.mz_roles role_owner ON role_owner.id = m.owner_id
9915WHERE s.database_id IS NULL OR d.name = current_database()",
9916 access: vec![PUBLIC_SELECT],
9917});
9918
9919pub static INFORMATION_SCHEMA_APPLICABLE_ROLES: LazyLock<BuiltinView> =
9920 LazyLock::new(|| BuiltinView {
9921 name: "applicable_roles",
9922 schema: INFORMATION_SCHEMA,
9923 oid: oid::VIEW_APPLICABLE_ROLES_OID,
9924 desc: RelationDesc::builder()
9925 .with_column("grantee", SqlScalarType::String.nullable(false))
9926 .with_column("role_name", SqlScalarType::String.nullable(false))
9927 .with_column("is_grantable", SqlScalarType::String.nullable(false))
9928 .finish(),
9929 column_comments: BTreeMap::new(),
9930 sql: "
9931SELECT
9932 member.name AS grantee,
9933 role.name AS role_name,
9934 -- ADMIN OPTION isn't implemented.
9935 'NO' AS is_grantable
9936FROM mz_catalog.mz_role_members membership
9937JOIN mz_catalog.mz_roles role ON membership.role_id = role.id
9938JOIN mz_catalog.mz_roles member ON membership.member = member.id
9939WHERE mz_catalog.mz_is_superuser() OR pg_has_role(current_role, member.oid, 'USAGE')",
9940 access: vec![PUBLIC_SELECT],
9941 });
9942
9943pub static INFORMATION_SCHEMA_COLUMNS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
9944 name: "columns",
9945 schema: INFORMATION_SCHEMA,
9946 oid: oid::VIEW_COLUMNS_OID,
9947 desc: RelationDesc::builder()
9948 .with_column("table_catalog", SqlScalarType::String.nullable(false))
9949 .with_column("table_schema", SqlScalarType::String.nullable(false))
9950 .with_column("table_name", SqlScalarType::String.nullable(false))
9951 .with_column("column_name", SqlScalarType::String.nullable(false))
9952 .with_column("ordinal_position", SqlScalarType::Int64.nullable(false))
9953 .with_column("column_default", SqlScalarType::String.nullable(true))
9954 .with_column("is_nullable", SqlScalarType::String.nullable(false))
9955 .with_column("data_type", SqlScalarType::String.nullable(false))
9956 .with_column(
9957 "character_maximum_length",
9958 SqlScalarType::Int32.nullable(true),
9959 )
9960 .with_column("numeric_precision", SqlScalarType::Int32.nullable(true))
9961 .with_column("numeric_scale", SqlScalarType::Int32.nullable(true))
9962 .finish(),
9963 column_comments: BTreeMap::new(),
9964 sql: "
9965SELECT
9966 current_database() as table_catalog,
9967 s.name AS table_schema,
9968 o.name AS table_name,
9969 c.name AS column_name,
9970 c.position::int8 AS ordinal_position,
9971 c.default AS column_default,
9972 CASE WHEN c.nullable THEN 'YES' ELSE 'NO' END AS is_nullable,
9973 c.type AS data_type,
9974 NULL::pg_catalog.int4 AS character_maximum_length,
9975 NULL::pg_catalog.int4 AS numeric_precision,
9976 NULL::pg_catalog.int4 AS numeric_scale
9977FROM mz_catalog.mz_columns c
9978JOIN mz_catalog.mz_objects o ON o.id = c.id
9979JOIN mz_catalog.mz_schemas s ON s.id = o.schema_id
9980LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
9981WHERE s.database_id IS NULL OR d.name = current_database()",
9982 access: vec![PUBLIC_SELECT],
9983});
9984
9985pub static INFORMATION_SCHEMA_ENABLED_ROLES: LazyLock<BuiltinView> =
9986 LazyLock::new(|| BuiltinView {
9987 name: "enabled_roles",
9988 schema: INFORMATION_SCHEMA,
9989 oid: oid::VIEW_ENABLED_ROLES_OID,
9990 desc: RelationDesc::builder()
9991 .with_column("role_name", SqlScalarType::String.nullable(false))
9992 .finish(),
9993 column_comments: BTreeMap::new(),
9994 sql: "
9995SELECT name AS role_name
9996FROM mz_catalog.mz_roles
9997WHERE mz_catalog.mz_is_superuser() OR pg_has_role(current_role, oid, 'USAGE')",
9998 access: vec![PUBLIC_SELECT],
9999 });
10000
10001pub static INFORMATION_SCHEMA_ROLE_TABLE_GRANTS: LazyLock<BuiltinView> = LazyLock::new(|| {
10002 BuiltinView {
10003 name: "role_table_grants",
10004 schema: INFORMATION_SCHEMA,
10005 oid: oid::VIEW_ROLE_TABLE_GRANTS_OID,
10006 desc: RelationDesc::builder()
10007 .with_column("grantor", SqlScalarType::String.nullable(false))
10008 .with_column("grantee", SqlScalarType::String.nullable(true))
10009 .with_column("table_catalog", SqlScalarType::String.nullable(true))
10010 .with_column("table_schema", SqlScalarType::String.nullable(false))
10011 .with_column("table_name", SqlScalarType::String.nullable(false))
10012 .with_column("privilege_type", SqlScalarType::String.nullable(true))
10013 .with_column("is_grantable", SqlScalarType::String.nullable(false))
10014 .with_column("with_hierarchy", SqlScalarType::String.nullable(false))
10015 .finish(),
10016 column_comments: BTreeMap::new(),
10017 sql: "
10018SELECT grantor, grantee, table_catalog, table_schema, table_name, privilege_type, is_grantable, with_hierarchy
10019FROM information_schema.table_privileges
10020WHERE
10021 grantor IN (SELECT role_name FROM information_schema.enabled_roles)
10022 OR grantee IN (SELECT role_name FROM information_schema.enabled_roles)",
10023 access: vec![PUBLIC_SELECT],
10024 }
10025});
10026
10027pub static INFORMATION_SCHEMA_KEY_COLUMN_USAGE: LazyLock<BuiltinView> =
10028 LazyLock::new(|| BuiltinView {
10029 name: "key_column_usage",
10030 schema: INFORMATION_SCHEMA,
10031 oid: oid::VIEW_KEY_COLUMN_USAGE_OID,
10032 desc: RelationDesc::builder()
10033 .with_column("constraint_catalog", SqlScalarType::String.nullable(false))
10034 .with_column("constraint_schema", SqlScalarType::String.nullable(false))
10035 .with_column("constraint_name", SqlScalarType::String.nullable(false))
10036 .with_column("table_catalog", SqlScalarType::String.nullable(false))
10037 .with_column("table_schema", SqlScalarType::String.nullable(false))
10038 .with_column("table_name", SqlScalarType::String.nullable(false))
10039 .with_column("column_name", SqlScalarType::String.nullable(false))
10040 .with_column("ordinal_position", SqlScalarType::Int32.nullable(false))
10041 .with_column(
10042 "position_in_unique_constraint",
10043 SqlScalarType::Int32.nullable(false),
10044 )
10045 .with_key(vec![])
10046 .finish(),
10047 column_comments: BTreeMap::new(),
10048 sql: "SELECT
10049 NULL::text AS constraint_catalog,
10050 NULL::text AS constraint_schema,
10051 NULL::text AS constraint_name,
10052 NULL::text AS table_catalog,
10053 NULL::text AS table_schema,
10054 NULL::text AS table_name,
10055 NULL::text AS column_name,
10056 NULL::integer AS ordinal_position,
10057 NULL::integer AS position_in_unique_constraint
10058WHERE false",
10059 access: vec![PUBLIC_SELECT],
10060 });
10061
10062pub static INFORMATION_SCHEMA_REFERENTIAL_CONSTRAINTS: LazyLock<BuiltinView> =
10063 LazyLock::new(|| BuiltinView {
10064 name: "referential_constraints",
10065 schema: INFORMATION_SCHEMA,
10066 oid: oid::VIEW_REFERENTIAL_CONSTRAINTS_OID,
10067 desc: RelationDesc::builder()
10068 .with_column("constraint_catalog", SqlScalarType::String.nullable(false))
10069 .with_column("constraint_schema", SqlScalarType::String.nullable(false))
10070 .with_column("constraint_name", SqlScalarType::String.nullable(false))
10071 .with_column(
10072 "unique_constraint_catalog",
10073 SqlScalarType::String.nullable(false),
10074 )
10075 .with_column(
10076 "unique_constraint_schema",
10077 SqlScalarType::String.nullable(false),
10078 )
10079 .with_column(
10080 "unique_constraint_name",
10081 SqlScalarType::String.nullable(false),
10082 )
10083 .with_column("match_option", SqlScalarType::String.nullable(false))
10084 .with_column("update_rule", SqlScalarType::String.nullable(false))
10085 .with_column("delete_rule", SqlScalarType::String.nullable(false))
10086 .with_key(vec![])
10087 .finish(),
10088 column_comments: BTreeMap::new(),
10089 sql: "SELECT
10090 NULL::text AS constraint_catalog,
10091 NULL::text AS constraint_schema,
10092 NULL::text AS constraint_name,
10093 NULL::text AS unique_constraint_catalog,
10094 NULL::text AS unique_constraint_schema,
10095 NULL::text AS unique_constraint_name,
10096 NULL::text AS match_option,
10097 NULL::text AS update_rule,
10098 NULL::text AS delete_rule
10099WHERE false",
10100 access: vec![PUBLIC_SELECT],
10101 });
10102
10103pub static INFORMATION_SCHEMA_ROUTINES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10104 name: "routines",
10105 schema: INFORMATION_SCHEMA,
10106 oid: oid::VIEW_ROUTINES_OID,
10107 desc: RelationDesc::builder()
10108 .with_column("routine_catalog", SqlScalarType::String.nullable(false))
10109 .with_column("routine_schema", SqlScalarType::String.nullable(false))
10110 .with_column("routine_name", SqlScalarType::String.nullable(false))
10111 .with_column("routine_type", SqlScalarType::String.nullable(false))
10112 .with_column("routine_definition", SqlScalarType::String.nullable(true))
10113 .finish(),
10114 column_comments: BTreeMap::new(),
10115 sql: "SELECT
10116 current_database() as routine_catalog,
10117 s.name AS routine_schema,
10118 f.name AS routine_name,
10119 'FUNCTION' AS routine_type,
10120 NULL::text AS routine_definition
10121FROM mz_catalog.mz_functions f
10122JOIN mz_catalog.mz_schemas s ON s.id = f.schema_id
10123LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
10124WHERE s.database_id IS NULL OR d.name = current_database()",
10125 access: vec![PUBLIC_SELECT],
10126});
10127
10128pub static INFORMATION_SCHEMA_SCHEMATA: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10129 name: "schemata",
10130 schema: INFORMATION_SCHEMA,
10131 oid: oid::VIEW_SCHEMATA_OID,
10132 desc: RelationDesc::builder()
10133 .with_column("catalog_name", SqlScalarType::String.nullable(false))
10134 .with_column("schema_name", SqlScalarType::String.nullable(false))
10135 .finish(),
10136 column_comments: BTreeMap::new(),
10137 sql: "
10138SELECT
10139 current_database() as catalog_name,
10140 s.name AS schema_name
10141FROM mz_catalog.mz_schemas s
10142LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
10143WHERE s.database_id IS NULL OR d.name = current_database()",
10144 access: vec![PUBLIC_SELECT],
10145});
10146
10147pub static INFORMATION_SCHEMA_TABLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10148 name: "tables",
10149 schema: INFORMATION_SCHEMA,
10150 oid: oid::VIEW_TABLES_OID,
10151 desc: RelationDesc::builder()
10152 .with_column("table_catalog", SqlScalarType::String.nullable(false))
10153 .with_column("table_schema", SqlScalarType::String.nullable(false))
10154 .with_column("table_name", SqlScalarType::String.nullable(false))
10155 .with_column("table_type", SqlScalarType::String.nullable(false))
10156 .finish(),
10157 column_comments: BTreeMap::new(),
10158 sql: "SELECT
10159 current_database() as table_catalog,
10160 s.name AS table_schema,
10161 r.name AS table_name,
10162 CASE r.type
10163 WHEN 'materialized-view' THEN 'MATERIALIZED VIEW'
10164 WHEN 'table' THEN 'BASE TABLE'
10165 ELSE pg_catalog.upper(r.type)
10166 END AS table_type
10167FROM mz_catalog.mz_relations r
10168JOIN mz_catalog.mz_schemas s ON s.id = r.schema_id
10169LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
10170WHERE s.database_id IS NULL OR d.name = current_database()",
10171 access: vec![PUBLIC_SELECT],
10172});
10173
10174pub static INFORMATION_SCHEMA_TABLE_CONSTRAINTS: LazyLock<BuiltinView> =
10175 LazyLock::new(|| BuiltinView {
10176 name: "table_constraints",
10177 schema: INFORMATION_SCHEMA,
10178 oid: oid::VIEW_TABLE_CONSTRAINTS_OID,
10179 desc: RelationDesc::builder()
10180 .with_column("constraint_catalog", SqlScalarType::String.nullable(false))
10181 .with_column("constraint_schema", SqlScalarType::String.nullable(false))
10182 .with_column("constraint_name", SqlScalarType::String.nullable(false))
10183 .with_column("table_catalog", SqlScalarType::String.nullable(false))
10184 .with_column("table_schema", SqlScalarType::String.nullable(false))
10185 .with_column("table_name", SqlScalarType::String.nullable(false))
10186 .with_column("constraint_type", SqlScalarType::String.nullable(false))
10187 .with_column("is_deferrable", SqlScalarType::String.nullable(false))
10188 .with_column("initially_deferred", SqlScalarType::String.nullable(false))
10189 .with_column("enforced", SqlScalarType::String.nullable(false))
10190 .with_column("nulls_distinct", SqlScalarType::String.nullable(false))
10191 .with_key(vec![])
10192 .finish(),
10193 column_comments: BTreeMap::new(),
10194 sql: "SELECT
10195 NULL::text AS constraint_catalog,
10196 NULL::text AS constraint_schema,
10197 NULL::text AS constraint_name,
10198 NULL::text AS table_catalog,
10199 NULL::text AS table_schema,
10200 NULL::text AS table_name,
10201 NULL::text AS constraint_type,
10202 NULL::text AS is_deferrable,
10203 NULL::text AS initially_deferred,
10204 NULL::text AS enforced,
10205 NULL::text AS nulls_distinct
10206WHERE false",
10207 access: vec![PUBLIC_SELECT],
10208 });
10209
10210pub static INFORMATION_SCHEMA_TABLE_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| {
10211 BuiltinView {
10212 name: "table_privileges",
10213 schema: INFORMATION_SCHEMA,
10214 oid: oid::VIEW_TABLE_PRIVILEGES_OID,
10215 desc: RelationDesc::builder()
10216 .with_column("grantor", SqlScalarType::String.nullable(false))
10217 .with_column("grantee", SqlScalarType::String.nullable(true))
10218 .with_column("table_catalog", SqlScalarType::String.nullable(true))
10219 .with_column("table_schema", SqlScalarType::String.nullable(false))
10220 .with_column("table_name", SqlScalarType::String.nullable(false))
10221 .with_column("privilege_type", SqlScalarType::String.nullable(true))
10222 .with_column("is_grantable", SqlScalarType::String.nullable(false))
10223 .with_column("with_hierarchy", SqlScalarType::String.nullable(false))
10224 .finish(),
10225 column_comments: BTreeMap::new(),
10226 sql: "
10227SELECT
10228 grantor,
10229 grantee,
10230 table_catalog,
10231 table_schema,
10232 table_name,
10233 privilege_type,
10234 is_grantable,
10235 CASE privilege_type
10236 WHEN 'SELECT' THEN 'YES'
10237 ELSE 'NO'
10238 END AS with_hierarchy
10239FROM
10240 (SELECT
10241 grantor.name AS grantor,
10242 CASE mz_internal.mz_aclitem_grantee(privileges)
10243 WHEN 'p' THEN 'PUBLIC'
10244 ELSE grantee.name
10245 END AS grantee,
10246 table_catalog,
10247 table_schema,
10248 table_name,
10249 unnest(mz_internal.mz_format_privileges(mz_internal.mz_aclitem_privileges(privileges))) AS privilege_type,
10250 -- ADMIN OPTION isn't implemented.
10251 'NO' AS is_grantable
10252 FROM
10253 (SELECT
10254 unnest(relations.privileges) AS privileges,
10255 CASE
10256 WHEN schemas.database_id IS NULL THEN current_database()
10257 ELSE databases.name
10258 END AS table_catalog,
10259 schemas.name AS table_schema,
10260 relations.name AS table_name
10261 FROM mz_catalog.mz_relations AS relations
10262 JOIN mz_catalog.mz_schemas AS schemas ON relations.schema_id = schemas.id
10263 LEFT JOIN mz_catalog.mz_databases AS databases ON schemas.database_id = databases.id
10264 WHERE schemas.database_id IS NULL OR databases.name = current_database())
10265 JOIN mz_catalog.mz_roles AS grantor ON mz_internal.mz_aclitem_grantor(privileges) = grantor.id
10266 LEFT JOIN mz_catalog.mz_roles AS grantee ON mz_internal.mz_aclitem_grantee(privileges) = grantee.id)
10267WHERE
10268 -- WHERE clause is not guaranteed to short-circuit and 'PUBLIC' will cause an error when passed
10269 -- to pg_has_role. Therefore we need to use a CASE statement.
10270 CASE
10271 WHEN grantee = 'PUBLIC' THEN true
10272 ELSE mz_catalog.mz_is_superuser()
10273 OR pg_has_role(current_role, grantee, 'USAGE')
10274 OR pg_has_role(current_role, grantor, 'USAGE')
10275 END",
10276 access: vec![PUBLIC_SELECT],
10277 }
10278});
10279
10280pub static INFORMATION_SCHEMA_TRIGGERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10281 name: "triggers",
10282 schema: INFORMATION_SCHEMA,
10283 oid: oid::VIEW_TRIGGERS_OID,
10284 desc: RelationDesc::builder()
10285 .with_column("trigger_catalog", SqlScalarType::String.nullable(false))
10286 .with_column("trigger_schema", SqlScalarType::String.nullable(false))
10287 .with_column("trigger_name", SqlScalarType::String.nullable(false))
10288 .with_column("event_manipulation", SqlScalarType::String.nullable(false))
10289 .with_column(
10290 "event_object_catalog",
10291 SqlScalarType::String.nullable(false),
10292 )
10293 .with_column("event_object_schema", SqlScalarType::String.nullable(false))
10294 .with_column("event_object_table", SqlScalarType::String.nullable(false))
10295 .with_column("action_order", SqlScalarType::Int32.nullable(false))
10296 .with_column("action_condition", SqlScalarType::String.nullable(false))
10297 .with_column("action_statement", SqlScalarType::String.nullable(false))
10298 .with_column("action_orientation", SqlScalarType::String.nullable(false))
10299 .with_column("action_timing", SqlScalarType::String.nullable(false))
10300 .with_column(
10301 "action_reference_old_table",
10302 SqlScalarType::String.nullable(false),
10303 )
10304 .with_column(
10305 "action_reference_new_table",
10306 SqlScalarType::String.nullable(false),
10307 )
10308 .with_key(vec![])
10309 .finish(),
10310 column_comments: BTreeMap::new(),
10311 sql: "SELECT
10312 NULL::text as trigger_catalog,
10313 NULL::text AS trigger_schema,
10314 NULL::text AS trigger_name,
10315 NULL::text AS event_manipulation,
10316 NULL::text AS event_object_catalog,
10317 NULL::text AS event_object_schema,
10318 NULL::text AS event_object_table,
10319 NULL::integer AS action_order,
10320 NULL::text AS action_condition,
10321 NULL::text AS action_statement,
10322 NULL::text AS action_orientation,
10323 NULL::text AS action_timing,
10324 NULL::text AS action_reference_old_table,
10325 NULL::text AS action_reference_new_table
10326WHERE FALSE",
10327 access: vec![PUBLIC_SELECT],
10328});
10329
10330pub static INFORMATION_SCHEMA_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10331 name: "views",
10332 schema: INFORMATION_SCHEMA,
10333 oid: oid::VIEW_VIEWS_OID,
10334 desc: RelationDesc::builder()
10335 .with_column("table_catalog", SqlScalarType::String.nullable(false))
10336 .with_column("table_schema", SqlScalarType::String.nullable(false))
10337 .with_column("table_name", SqlScalarType::String.nullable(false))
10338 .with_column("view_definition", SqlScalarType::String.nullable(false))
10339 .finish(),
10340 column_comments: BTreeMap::new(),
10341 sql: "SELECT
10342 current_database() as table_catalog,
10343 s.name AS table_schema,
10344 v.name AS table_name,
10345 v.definition AS view_definition
10346FROM mz_catalog.mz_views v
10347JOIN mz_catalog.mz_schemas s ON s.id = v.schema_id
10348LEFT JOIN mz_catalog.mz_databases d ON d.id = s.database_id
10349WHERE s.database_id IS NULL OR d.name = current_database()",
10350 access: vec![PUBLIC_SELECT],
10351});
10352
10353pub static INFORMATION_SCHEMA_CHARACTER_SETS: LazyLock<BuiltinView> =
10354 LazyLock::new(|| BuiltinView {
10355 name: "character_sets",
10356 schema: INFORMATION_SCHEMA,
10357 oid: oid::VIEW_CHARACTER_SETS_OID,
10358 desc: RelationDesc::builder()
10359 .with_column(
10360 "character_set_catalog",
10361 SqlScalarType::String.nullable(true),
10362 )
10363 .with_column("character_set_schema", SqlScalarType::String.nullable(true))
10364 .with_column("character_set_name", SqlScalarType::String.nullable(false))
10365 .with_column(
10366 "character_repertoire",
10367 SqlScalarType::String.nullable(false),
10368 )
10369 .with_column("form_of_use", SqlScalarType::String.nullable(false))
10370 .with_column(
10371 "default_collate_catalog",
10372 SqlScalarType::String.nullable(false),
10373 )
10374 .with_column(
10375 "default_collate_schema",
10376 SqlScalarType::String.nullable(false),
10377 )
10378 .with_column(
10379 "default_collate_name",
10380 SqlScalarType::String.nullable(false),
10381 )
10382 .with_key(vec![])
10383 .finish(),
10384 column_comments: BTreeMap::new(),
10385 sql: "SELECT
10386 NULL as character_set_catalog,
10387 NULL as character_set_schema,
10388 'UTF8' as character_set_name,
10389 'UCS' as character_repertoire,
10390 'UTF8' as form_of_use,
10391 current_database() as default_collate_catalog,
10392 'pg_catalog' as default_collate_schema,
10393 'en_US.utf8' as default_collate_name",
10394 access: vec![PUBLIC_SELECT],
10395 });
10396
10397pub static PG_COLLATION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10400 name: "pg_collation",
10401 schema: PG_CATALOG_SCHEMA,
10402 oid: oid::VIEW_PG_COLLATION_OID,
10403 desc: RelationDesc::builder()
10404 .with_column("oid", SqlScalarType::Oid.nullable(false))
10405 .with_column("collname", SqlScalarType::String.nullable(false))
10406 .with_column("collnamespace", SqlScalarType::Oid.nullable(false))
10407 .with_column("collowner", SqlScalarType::Oid.nullable(false))
10408 .with_column("collprovider", SqlScalarType::PgLegacyChar.nullable(false))
10409 .with_column("collisdeterministic", SqlScalarType::Bool.nullable(false))
10410 .with_column("collencoding", SqlScalarType::Int32.nullable(false))
10411 .with_column("collcollate", SqlScalarType::String.nullable(false))
10412 .with_column("collctype", SqlScalarType::String.nullable(false))
10413 .with_column("collversion", SqlScalarType::String.nullable(false))
10414 .with_key(vec![])
10415 .finish(),
10416 column_comments: BTreeMap::new(),
10417 sql: "
10418SELECT
10419 NULL::pg_catalog.oid AS oid,
10420 NULL::pg_catalog.text AS collname,
10421 NULL::pg_catalog.oid AS collnamespace,
10422 NULL::pg_catalog.oid AS collowner,
10423 NULL::pg_catalog.\"char\" AS collprovider,
10424 NULL::pg_catalog.bool AS collisdeterministic,
10425 NULL::pg_catalog.int4 AS collencoding,
10426 NULL::pg_catalog.text AS collcollate,
10427 NULL::pg_catalog.text AS collctype,
10428 NULL::pg_catalog.text AS collversion
10429WHERE false",
10430 access: vec![PUBLIC_SELECT],
10431});
10432
10433pub static PG_POLICY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10435 name: "pg_policy",
10436 schema: PG_CATALOG_SCHEMA,
10437 oid: oid::VIEW_PG_POLICY_OID,
10438 desc: RelationDesc::builder()
10439 .with_column("oid", SqlScalarType::Oid.nullable(false))
10440 .with_column("polname", SqlScalarType::String.nullable(false))
10441 .with_column("polrelid", SqlScalarType::Oid.nullable(false))
10442 .with_column("polcmd", SqlScalarType::PgLegacyChar.nullable(false))
10443 .with_column("polpermissive", SqlScalarType::Bool.nullable(false))
10444 .with_column(
10445 "polroles",
10446 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
10447 )
10448 .with_column("polqual", SqlScalarType::String.nullable(false))
10449 .with_column("polwithcheck", SqlScalarType::String.nullable(false))
10450 .with_key(vec![])
10451 .finish(),
10452 column_comments: BTreeMap::new(),
10453 sql: "
10454SELECT
10455 NULL::pg_catalog.oid AS oid,
10456 NULL::pg_catalog.text AS polname,
10457 NULL::pg_catalog.oid AS polrelid,
10458 NULL::pg_catalog.\"char\" AS polcmd,
10459 NULL::pg_catalog.bool AS polpermissive,
10460 NULL::pg_catalog.oid[] AS polroles,
10461 NULL::pg_catalog.text AS polqual,
10462 NULL::pg_catalog.text AS polwithcheck
10463WHERE false",
10464 access: vec![PUBLIC_SELECT],
10465});
10466
10467pub static PG_INHERITS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10469 name: "pg_inherits",
10470 schema: PG_CATALOG_SCHEMA,
10471 oid: oid::VIEW_PG_INHERITS_OID,
10472 desc: RelationDesc::builder()
10473 .with_column("inhrelid", SqlScalarType::Oid.nullable(false))
10474 .with_column("inhparent", SqlScalarType::Oid.nullable(false))
10475 .with_column("inhseqno", SqlScalarType::Int32.nullable(false))
10476 .with_column("inhdetachpending", SqlScalarType::Bool.nullable(false))
10477 .with_key(vec![])
10478 .finish(),
10479 column_comments: BTreeMap::new(),
10480 sql: "
10481SELECT
10482 NULL::pg_catalog.oid AS inhrelid,
10483 NULL::pg_catalog.oid AS inhparent,
10484 NULL::pg_catalog.int4 AS inhseqno,
10485 NULL::pg_catalog.bool AS inhdetachpending
10486WHERE false",
10487 access: vec![PUBLIC_SELECT],
10488});
10489
10490pub static PG_LOCKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10491 name: "pg_locks",
10492 schema: PG_CATALOG_SCHEMA,
10493 oid: oid::VIEW_PG_LOCKS_OID,
10494 desc: RelationDesc::builder()
10495 .with_column("locktype", SqlScalarType::String.nullable(false))
10496 .with_column("database", SqlScalarType::Oid.nullable(false))
10497 .with_column("relation", SqlScalarType::Oid.nullable(false))
10498 .with_column("page", SqlScalarType::Int32.nullable(false))
10499 .with_column("tuple", SqlScalarType::Int16.nullable(false))
10500 .with_column("virtualxid", SqlScalarType::String.nullable(false))
10501 .with_column("transactionid", SqlScalarType::String.nullable(false))
10502 .with_column("classid", SqlScalarType::Oid.nullable(false))
10503 .with_column("objid", SqlScalarType::Oid.nullable(false))
10504 .with_column("objsubid", SqlScalarType::Int16.nullable(false))
10505 .with_column("virtualtransaction", SqlScalarType::String.nullable(false))
10506 .with_column("pid", SqlScalarType::Int32.nullable(false))
10507 .with_column("mode", SqlScalarType::String.nullable(false))
10508 .with_column("granted", SqlScalarType::Bool.nullable(false))
10509 .with_column("fastpath", SqlScalarType::Bool.nullable(false))
10510 .with_column(
10511 "waitstart",
10512 SqlScalarType::TimestampTz { precision: None }.nullable(false),
10513 )
10514 .with_key(vec![])
10515 .finish(),
10516 column_comments: BTreeMap::new(),
10517 sql: "
10518SELECT
10519-- While there exist locks in Materialize, we don't expose them, so all of these fields are NULL.
10520 NULL::pg_catalog.text AS locktype,
10521 NULL::pg_catalog.oid AS database,
10522 NULL::pg_catalog.oid AS relation,
10523 NULL::pg_catalog.int4 AS page,
10524 NULL::pg_catalog.int2 AS tuple,
10525 NULL::pg_catalog.text AS virtualxid,
10526 NULL::pg_catalog.text AS transactionid,
10527 NULL::pg_catalog.oid AS classid,
10528 NULL::pg_catalog.oid AS objid,
10529 NULL::pg_catalog.int2 AS objsubid,
10530 NULL::pg_catalog.text AS virtualtransaction,
10531 NULL::pg_catalog.int4 AS pid,
10532 NULL::pg_catalog.text AS mode,
10533 NULL::pg_catalog.bool AS granted,
10534 NULL::pg_catalog.bool AS fastpath,
10535 NULL::pg_catalog.timestamptz AS waitstart
10536WHERE false",
10537 access: vec![PUBLIC_SELECT],
10538});
10539
10540pub static PG_AUTHID_CORE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10543 name: "pg_authid_core",
10544 schema: MZ_INTERNAL_SCHEMA,
10545 oid: oid::VIEW_PG_AUTHID_CORE_OID,
10546 desc: RelationDesc::builder()
10547 .with_column("oid", SqlScalarType::Oid.nullable(false))
10548 .with_column("rolname", SqlScalarType::String.nullable(false))
10549 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
10550 .with_column("rolinherit", SqlScalarType::Bool.nullable(false))
10551 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(false))
10552 .with_column("rolreplication", SqlScalarType::Bool.nullable(false))
10553 .with_column("rolbypassrls", SqlScalarType::Bool.nullable(false))
10554 .with_column("rolconnlimit", SqlScalarType::Int32.nullable(false))
10555 .with_column("rolpassword", SqlScalarType::String.nullable(true))
10556 .with_column(
10557 "rolvaliduntil",
10558 SqlScalarType::TimestampTz { precision: None }.nullable(true),
10559 )
10560 .finish(),
10561 column_comments: BTreeMap::new(),
10562 sql: r#"
10563SELECT
10564 r.oid AS oid,
10565 r.name AS rolname,
10566 rolsuper,
10567 inherit AS rolinherit,
10568 COALESCE(r.rolcanlogin, false) AS rolcanlogin,
10569 -- MZ doesn't support replication in the same way Postgres does
10570 false AS rolreplication,
10571 -- MZ doesn't how row level security
10572 false AS rolbypassrls,
10573 -- MZ doesn't have a connection limit
10574 -1 AS rolconnlimit,
10575 a.password_hash AS rolpassword,
10576 NULL::pg_catalog.timestamptz AS rolvaliduntil
10577FROM mz_catalog.mz_roles r
10578LEFT JOIN mz_catalog.mz_role_auth a ON r.oid = a.role_oid"#,
10579 access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
10580});
10581
10582pub const PG_AUTHID_CORE_IND: BuiltinIndex = BuiltinIndex {
10583 name: "pg_authid_core_ind",
10584 schema: MZ_INTERNAL_SCHEMA,
10585 oid: oid::INDEX_PG_AUTHID_CORE_IND_OID,
10586 sql: "IN CLUSTER mz_catalog_server
10587ON mz_internal.pg_authid_core (rolname)",
10588 is_retained_metrics_object: false,
10589};
10590
10591pub static PG_AUTHID: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10592 name: "pg_authid",
10593 schema: PG_CATALOG_SCHEMA,
10594 oid: oid::VIEW_PG_AUTHID_OID,
10595 desc: RelationDesc::builder()
10596 .with_column("oid", SqlScalarType::Oid.nullable(false))
10597 .with_column("rolname", SqlScalarType::String.nullable(false))
10598 .with_column("rolsuper", SqlScalarType::Bool.nullable(true))
10599 .with_column("rolinherit", SqlScalarType::Bool.nullable(false))
10600 .with_column("rolcreaterole", SqlScalarType::Bool.nullable(true))
10601 .with_column("rolcreatedb", SqlScalarType::Bool.nullable(true))
10602 .with_column("rolcanlogin", SqlScalarType::Bool.nullable(false))
10603 .with_column("rolreplication", SqlScalarType::Bool.nullable(false))
10604 .with_column("rolbypassrls", SqlScalarType::Bool.nullable(false))
10605 .with_column("rolconnlimit", SqlScalarType::Int32.nullable(false))
10606 .with_column("rolpassword", SqlScalarType::String.nullable(true))
10607 .with_column(
10608 "rolvaliduntil",
10609 SqlScalarType::TimestampTz { precision: None }.nullable(true),
10610 )
10611 .finish(),
10612 column_comments: BTreeMap::new(),
10613 sql: r#"
10629WITH extra AS (
10630 SELECT
10631 DISTINCT ON (oid)
10632 oid,
10633 mz_catalog.has_system_privilege(oid, 'CREATEROLE') AS rolcreaterole,
10634 mz_catalog.has_system_privilege(oid, 'CREATEDB') AS rolcreatedb
10635 FROM mz_internal.pg_authid_core
10636)
10637SELECT
10638 oid,
10639 rolname,
10640 rolsuper,
10641 rolinherit,
10642 extra.rolcreaterole,
10643 extra.rolcreatedb,
10644 rolcanlogin,
10645 rolreplication,
10646 rolbypassrls,
10647 rolconnlimit,
10648 rolpassword,
10649 rolvaliduntil
10650FROM mz_internal.pg_authid_core
10651LEFT JOIN extra USING (oid)"#,
10652 access: vec![rbac::owner_privilege(ObjectType::Table, MZ_SYSTEM_ROLE_ID)],
10653});
10654
10655pub static PG_AGGREGATE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10656 name: "pg_aggregate",
10657 schema: PG_CATALOG_SCHEMA,
10658 oid: oid::VIEW_PG_AGGREGATE_OID,
10659 desc: RelationDesc::builder()
10660 .with_column("aggfnoid", SqlScalarType::Oid.nullable(false))
10661 .with_column("aggkind", SqlScalarType::String.nullable(false))
10662 .with_column("aggnumdirectargs", SqlScalarType::Int16.nullable(false))
10663 .with_column("aggtransfn", SqlScalarType::RegProc.nullable(true))
10664 .with_column("aggfinalfn", SqlScalarType::RegProc.nullable(false))
10665 .with_column("aggcombinefn", SqlScalarType::RegProc.nullable(false))
10666 .with_column("aggserialfn", SqlScalarType::RegProc.nullable(false))
10667 .with_column("aggdeserialfn", SqlScalarType::RegProc.nullable(false))
10668 .with_column("aggmtransfn", SqlScalarType::RegProc.nullable(false))
10669 .with_column("aggminvtransfn", SqlScalarType::RegProc.nullable(false))
10670 .with_column("aggmfinalfn", SqlScalarType::RegProc.nullable(false))
10671 .with_column("aggfinalextra", SqlScalarType::Bool.nullable(false))
10672 .with_column("aggmfinalextra", SqlScalarType::Bool.nullable(false))
10673 .with_column("aggfinalmodify", SqlScalarType::PgLegacyChar.nullable(true))
10674 .with_column(
10675 "aggmfinalmodify",
10676 SqlScalarType::PgLegacyChar.nullable(true),
10677 )
10678 .with_column("aggsortop", SqlScalarType::Oid.nullable(false))
10679 .with_column("aggtranstype", SqlScalarType::Oid.nullable(true))
10680 .with_column("aggtransspace", SqlScalarType::Int32.nullable(true))
10681 .with_column("aggmtranstype", SqlScalarType::Oid.nullable(false))
10682 .with_column("aggmtransspace", SqlScalarType::Int32.nullable(true))
10683 .with_column("agginitval", SqlScalarType::String.nullable(true))
10684 .with_column("aggminitval", SqlScalarType::String.nullable(true))
10685 .finish(),
10686 column_comments: BTreeMap::new(),
10687 sql: "SELECT
10688 a.oid as aggfnoid,
10689 -- Currently Materialize only support 'normal' aggregate functions.
10690 a.agg_kind as aggkind,
10691 a.agg_num_direct_args as aggnumdirectargs,
10692 -- Materialize doesn't support these fields.
10693 NULL::pg_catalog.regproc as aggtransfn,
10694 '0'::pg_catalog.regproc as aggfinalfn,
10695 '0'::pg_catalog.regproc as aggcombinefn,
10696 '0'::pg_catalog.regproc as aggserialfn,
10697 '0'::pg_catalog.regproc as aggdeserialfn,
10698 '0'::pg_catalog.regproc as aggmtransfn,
10699 '0'::pg_catalog.regproc as aggminvtransfn,
10700 '0'::pg_catalog.regproc as aggmfinalfn,
10701 false as aggfinalextra,
10702 false as aggmfinalextra,
10703 NULL::pg_catalog.\"char\" AS aggfinalmodify,
10704 NULL::pg_catalog.\"char\" AS aggmfinalmodify,
10705 '0'::pg_catalog.oid as aggsortop,
10706 NULL::pg_catalog.oid as aggtranstype,
10707 NULL::pg_catalog.int4 as aggtransspace,
10708 '0'::pg_catalog.oid as aggmtranstype,
10709 NULL::pg_catalog.int4 as aggmtransspace,
10710 NULL::pg_catalog.text as agginitval,
10711 NULL::pg_catalog.text as aggminitval
10712FROM mz_internal.mz_aggregates a",
10713 access: vec![PUBLIC_SELECT],
10714});
10715
10716pub static PG_TRIGGER: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10717 name: "pg_trigger",
10718 schema: PG_CATALOG_SCHEMA,
10719 oid: oid::VIEW_PG_TRIGGER_OID,
10720 desc: RelationDesc::builder()
10721 .with_column("oid", SqlScalarType::Oid.nullable(false))
10722 .with_column("tgrelid", SqlScalarType::Oid.nullable(false))
10723 .with_column("tgparentid", SqlScalarType::Oid.nullable(false))
10724 .with_column("tgname", SqlScalarType::String.nullable(false))
10725 .with_column("tgfoid", SqlScalarType::Oid.nullable(false))
10726 .with_column("tgtype", SqlScalarType::Int16.nullable(false))
10727 .with_column("tgenabled", SqlScalarType::PgLegacyChar.nullable(false))
10728 .with_column("tgisinternal", SqlScalarType::Bool.nullable(false))
10729 .with_column("tgconstrrelid", SqlScalarType::Oid.nullable(false))
10730 .with_column("tgconstrindid", SqlScalarType::Oid.nullable(false))
10731 .with_column("tgconstraint", SqlScalarType::Oid.nullable(false))
10732 .with_column("tgdeferrable", SqlScalarType::Bool.nullable(false))
10733 .with_column("tginitdeferred", SqlScalarType::Bool.nullable(false))
10734 .with_column("tgnargs", SqlScalarType::Int16.nullable(false))
10735 .with_column("tgattr", SqlScalarType::Int2Vector.nullable(false))
10736 .with_column("tgargs", SqlScalarType::Bytes.nullable(false))
10737 .with_column("tgqual", SqlScalarType::String.nullable(false))
10738 .with_column("tgoldtable", SqlScalarType::String.nullable(false))
10739 .with_column("tgnewtable", SqlScalarType::String.nullable(false))
10740 .with_key(vec![])
10741 .finish(),
10742 column_comments: BTreeMap::new(),
10743 sql: "SELECT
10744 -- MZ doesn't support triggers so all of these fields are NULL.
10745 NULL::pg_catalog.oid AS oid,
10746 NULL::pg_catalog.oid AS tgrelid,
10747 NULL::pg_catalog.oid AS tgparentid,
10748 NULL::pg_catalog.text AS tgname,
10749 NULL::pg_catalog.oid AS tgfoid,
10750 NULL::pg_catalog.int2 AS tgtype,
10751 NULL::pg_catalog.\"char\" AS tgenabled,
10752 NULL::pg_catalog.bool AS tgisinternal,
10753 NULL::pg_catalog.oid AS tgconstrrelid,
10754 NULL::pg_catalog.oid AS tgconstrindid,
10755 NULL::pg_catalog.oid AS tgconstraint,
10756 NULL::pg_catalog.bool AS tgdeferrable,
10757 NULL::pg_catalog.bool AS tginitdeferred,
10758 NULL::pg_catalog.int2 AS tgnargs,
10759 NULL::pg_catalog.int2vector AS tgattr,
10760 NULL::pg_catalog.bytea AS tgargs,
10761 -- NOTE: The tgqual column is actually type `pg_node_tree` which we don't support. CockroachDB
10762 -- uses text as a placeholder, so we'll follow their lead here.
10763 NULL::pg_catalog.text AS tgqual,
10764 NULL::pg_catalog.text AS tgoldtable,
10765 NULL::pg_catalog.text AS tgnewtable
10766WHERE false
10767 ",
10768 access: vec![PUBLIC_SELECT],
10769});
10770
10771pub static PG_REWRITE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10772 name: "pg_rewrite",
10773 schema: PG_CATALOG_SCHEMA,
10774 oid: oid::VIEW_PG_REWRITE_OID,
10775 desc: RelationDesc::builder()
10776 .with_column("oid", SqlScalarType::Oid.nullable(false))
10777 .with_column("rulename", SqlScalarType::String.nullable(false))
10778 .with_column("ev_class", SqlScalarType::Oid.nullable(false))
10779 .with_column("ev_type", SqlScalarType::PgLegacyChar.nullable(false))
10780 .with_column("ev_enabled", SqlScalarType::PgLegacyChar.nullable(false))
10781 .with_column("is_instead", SqlScalarType::Bool.nullable(false))
10782 .with_column("ev_qual", SqlScalarType::String.nullable(false))
10783 .with_column("ev_action", SqlScalarType::String.nullable(false))
10784 .with_key(vec![])
10785 .finish(),
10786 column_comments: BTreeMap::new(),
10787 sql: "SELECT
10788 -- MZ doesn't support rewrite rules so all of these fields are NULL.
10789 NULL::pg_catalog.oid AS oid,
10790 NULL::pg_catalog.text AS rulename,
10791 NULL::pg_catalog.oid AS ev_class,
10792 NULL::pg_catalog.\"char\" AS ev_type,
10793 NULL::pg_catalog.\"char\" AS ev_enabled,
10794 NULL::pg_catalog.bool AS is_instead,
10795 -- NOTE: The ev_qual and ev_action columns are actually type `pg_node_tree` which we don't
10796 -- support. CockroachDB uses text as a placeholder, so we'll follow their lead here.
10797 NULL::pg_catalog.text AS ev_qual,
10798 NULL::pg_catalog.text AS ev_action
10799WHERE false
10800 ",
10801 access: vec![PUBLIC_SELECT],
10802});
10803
10804pub static PG_EXTENSION: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10805 name: "pg_extension",
10806 schema: PG_CATALOG_SCHEMA,
10807 oid: oid::VIEW_PG_EXTENSION_OID,
10808 desc: RelationDesc::builder()
10809 .with_column("oid", SqlScalarType::Oid.nullable(false))
10810 .with_column("extname", SqlScalarType::String.nullable(false))
10811 .with_column("extowner", SqlScalarType::Oid.nullable(false))
10812 .with_column("extnamespace", SqlScalarType::Oid.nullable(false))
10813 .with_column("extrelocatable", SqlScalarType::Bool.nullable(false))
10814 .with_column("extversion", SqlScalarType::String.nullable(false))
10815 .with_column(
10816 "extconfig",
10817 SqlScalarType::Array(Box::new(SqlScalarType::Oid)).nullable(false),
10818 )
10819 .with_column(
10820 "extcondition",
10821 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
10822 )
10823 .with_key(vec![])
10824 .finish(),
10825 column_comments: BTreeMap::new(),
10826 sql: "SELECT
10827 -- MZ doesn't support extensions so all of these fields are NULL.
10828 NULL::pg_catalog.oid AS oid,
10829 NULL::pg_catalog.text AS extname,
10830 NULL::pg_catalog.oid AS extowner,
10831 NULL::pg_catalog.oid AS extnamespace,
10832 NULL::pg_catalog.bool AS extrelocatable,
10833 NULL::pg_catalog.text AS extversion,
10834 NULL::pg_catalog.oid[] AS extconfig,
10835 NULL::pg_catalog.text[] AS extcondition
10836WHERE false
10837 ",
10838 access: vec![PUBLIC_SELECT],
10839});
10840
10841pub static MZ_SHOW_ALL_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10842 name: "mz_show_all_objects",
10843 schema: MZ_INTERNAL_SCHEMA,
10844 oid: oid::VIEW_MZ_SHOW_ALL_OBJECTS_OID,
10845 desc: RelationDesc::builder()
10846 .with_column("schema_id", SqlScalarType::String.nullable(false))
10847 .with_column("name", SqlScalarType::String.nullable(false))
10848 .with_column("type", SqlScalarType::String.nullable(false))
10849 .with_column("comment", SqlScalarType::String.nullable(false))
10850 .finish(),
10851 column_comments: BTreeMap::new(),
10852 sql: "WITH comments AS (
10853 SELECT id, object_type, comment
10854 FROM mz_internal.mz_comments
10855 WHERE object_sub_id IS NULL
10856 )
10857 SELECT schema_id, name, type, COALESCE(comment, '') AS comment
10858 FROM mz_catalog.mz_objects AS objs
10859 LEFT JOIN comments ON objs.id = comments.id
10860 WHERE (comments.object_type = objs.type OR comments.object_type IS NULL)",
10861 access: vec![PUBLIC_SELECT],
10862});
10863
10864pub static MZ_SHOW_CLUSTERS: LazyLock<BuiltinView> = LazyLock::new(|| {
10865 BuiltinView {
10866 name: "mz_show_clusters",
10867 schema: MZ_INTERNAL_SCHEMA,
10868 oid: oid::VIEW_MZ_SHOW_CLUSTERS_OID,
10869 desc: RelationDesc::builder()
10870 .with_column("name", SqlScalarType::String.nullable(false))
10871 .with_column("replicas", SqlScalarType::String.nullable(true))
10872 .with_column("comment", SqlScalarType::String.nullable(false))
10873 .finish(),
10874 column_comments: BTreeMap::new(),
10875 sql: "
10876 WITH clusters AS (
10877 SELECT
10878 mc.id,
10879 mc.name,
10880 pg_catalog.string_agg(mcr.name || ' (' || mcr.size || ')', ', ' ORDER BY mcr.name) AS replicas
10881 FROM mz_catalog.mz_clusters mc
10882 LEFT JOIN mz_catalog.mz_cluster_replicas mcr
10883 ON mc.id = mcr.cluster_id
10884 GROUP BY mc.id, mc.name
10885 ),
10886 comments AS (
10887 SELECT id, comment
10888 FROM mz_internal.mz_comments
10889 WHERE object_type = 'cluster' AND object_sub_id IS NULL
10890 )
10891 SELECT name, replicas, COALESCE(comment, '') as comment
10892 FROM clusters
10893 LEFT JOIN comments ON clusters.id = comments.id",
10894 access: vec![PUBLIC_SELECT],
10895}
10896});
10897
10898pub static MZ_SHOW_SECRETS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10899 name: "mz_show_secrets",
10900 schema: MZ_INTERNAL_SCHEMA,
10901 oid: oid::VIEW_MZ_SHOW_SECRETS_OID,
10902 desc: RelationDesc::builder()
10903 .with_column("schema_id", SqlScalarType::String.nullable(false))
10904 .with_column("name", SqlScalarType::String.nullable(false))
10905 .with_column("comment", SqlScalarType::String.nullable(false))
10906 .finish(),
10907 column_comments: BTreeMap::new(),
10908 sql: "WITH comments AS (
10909 SELECT id, comment
10910 FROM mz_internal.mz_comments
10911 WHERE object_type = 'secret' AND object_sub_id IS NULL
10912 )
10913 SELECT schema_id, name, COALESCE(comment, '') as comment
10914 FROM mz_catalog.mz_secrets secrets
10915 LEFT JOIN comments ON secrets.id = comments.id",
10916 access: vec![PUBLIC_SELECT],
10917});
10918
10919pub static MZ_SHOW_COLUMNS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10920 name: "mz_show_columns",
10921 schema: MZ_INTERNAL_SCHEMA,
10922 oid: oid::VIEW_MZ_SHOW_COLUMNS_OID,
10923 desc: RelationDesc::builder()
10924 .with_column("id", SqlScalarType::String.nullable(false))
10925 .with_column("name", SqlScalarType::String.nullable(false))
10926 .with_column("nullable", SqlScalarType::Bool.nullable(false))
10927 .with_column("type", SqlScalarType::String.nullable(false))
10928 .with_column("position", SqlScalarType::UInt64.nullable(false))
10929 .with_column("comment", SqlScalarType::String.nullable(false))
10930 .finish(),
10931 column_comments: BTreeMap::new(),
10932 sql: "
10933 SELECT columns.id, name, nullable, type, position, COALESCE(comment, '') as comment
10934 FROM mz_catalog.mz_columns columns
10935 LEFT JOIN mz_internal.mz_comments comments
10936 ON columns.id = comments.id AND columns.position = comments.object_sub_id",
10937 access: vec![PUBLIC_SELECT],
10938});
10939
10940pub static MZ_SHOW_DATABASES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10941 name: "mz_show_databases",
10942 schema: MZ_INTERNAL_SCHEMA,
10943 oid: oid::VIEW_MZ_SHOW_DATABASES_OID,
10944 desc: RelationDesc::builder()
10945 .with_column("name", SqlScalarType::String.nullable(false))
10946 .with_column("comment", SqlScalarType::String.nullable(false))
10947 .finish(),
10948 column_comments: BTreeMap::new(),
10949 sql: "WITH comments AS (
10950 SELECT id, comment
10951 FROM mz_internal.mz_comments
10952 WHERE object_type = 'database' AND object_sub_id IS NULL
10953 )
10954 SELECT name, COALESCE(comment, '') as comment
10955 FROM mz_catalog.mz_databases databases
10956 LEFT JOIN comments ON databases.id = comments.id",
10957 access: vec![PUBLIC_SELECT],
10958});
10959
10960pub static MZ_SHOW_SCHEMAS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10961 name: "mz_show_schemas",
10962 schema: MZ_INTERNAL_SCHEMA,
10963 oid: oid::VIEW_MZ_SHOW_SCHEMAS_OID,
10964 desc: RelationDesc::builder()
10965 .with_column("database_id", SqlScalarType::String.nullable(true))
10966 .with_column("name", SqlScalarType::String.nullable(false))
10967 .with_column("comment", SqlScalarType::String.nullable(false))
10968 .finish(),
10969 column_comments: BTreeMap::new(),
10970 sql: "WITH comments AS (
10971 SELECT id, comment
10972 FROM mz_internal.mz_comments
10973 WHERE object_type = 'schema' AND object_sub_id IS NULL
10974 )
10975 SELECT database_id, name, COALESCE(comment, '') as comment
10976 FROM mz_catalog.mz_schemas schemas
10977 LEFT JOIN comments ON schemas.id = comments.id",
10978 access: vec![PUBLIC_SELECT],
10979});
10980
10981pub static MZ_SHOW_ROLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
10982 name: "mz_show_roles",
10983 schema: MZ_INTERNAL_SCHEMA,
10984 oid: oid::VIEW_MZ_SHOW_ROLES_OID,
10985 desc: RelationDesc::builder()
10986 .with_column("name", SqlScalarType::String.nullable(false))
10987 .with_column("comment", SqlScalarType::String.nullable(false))
10988 .finish(),
10989 column_comments: BTreeMap::new(),
10990 sql: "WITH comments AS (
10991 SELECT id, comment
10992 FROM mz_internal.mz_comments
10993 WHERE object_type = 'role' AND object_sub_id IS NULL
10994 )
10995 SELECT name, COALESCE(comment, '') as comment
10996 FROM mz_catalog.mz_roles roles
10997 LEFT JOIN comments ON roles.id = comments.id
10998 WHERE roles.id NOT LIKE 's%'
10999 AND roles.id NOT LIKE 'g%'",
11000 access: vec![PUBLIC_SELECT],
11001});
11002
11003pub static MZ_SHOW_TABLES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11004 name: "mz_show_tables",
11005 schema: MZ_INTERNAL_SCHEMA,
11006 oid: oid::VIEW_MZ_SHOW_TABLES_OID,
11007 desc: RelationDesc::builder()
11008 .with_column("schema_id", SqlScalarType::String.nullable(false))
11009 .with_column("name", SqlScalarType::String.nullable(false))
11010 .with_column("comment", SqlScalarType::String.nullable(false))
11011 .with_column("source_id", SqlScalarType::String.nullable(true))
11012 .finish(),
11013 column_comments: BTreeMap::new(),
11014 sql: "WITH comments AS (
11015 SELECT id, comment
11016 FROM mz_internal.mz_comments
11017 WHERE object_type = 'table' AND object_sub_id IS NULL
11018 )
11019 SELECT schema_id, name, COALESCE(comment, '') as comment, source_id
11020 FROM mz_catalog.mz_tables tables
11021 LEFT JOIN comments ON tables.id = comments.id",
11022 access: vec![PUBLIC_SELECT],
11023});
11024
11025pub static MZ_SHOW_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11026 name: "mz_show_views",
11027 schema: MZ_INTERNAL_SCHEMA,
11028 oid: oid::VIEW_MZ_SHOW_VIEWS_OID,
11029 desc: RelationDesc::builder()
11030 .with_column("schema_id", SqlScalarType::String.nullable(false))
11031 .with_column("name", SqlScalarType::String.nullable(false))
11032 .with_column("comment", SqlScalarType::String.nullable(false))
11033 .finish(),
11034 column_comments: BTreeMap::new(),
11035 sql: "WITH comments AS (
11036 SELECT id, comment
11037 FROM mz_internal.mz_comments
11038 WHERE object_type = 'view' AND object_sub_id IS NULL
11039 )
11040 SELECT schema_id, name, COALESCE(comment, '') as comment
11041 FROM mz_catalog.mz_views views
11042 LEFT JOIN comments ON views.id = comments.id",
11043 access: vec![PUBLIC_SELECT],
11044});
11045
11046pub static MZ_SHOW_TYPES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11047 name: "mz_show_types",
11048 schema: MZ_INTERNAL_SCHEMA,
11049 oid: oid::VIEW_MZ_SHOW_TYPES_OID,
11050 desc: RelationDesc::builder()
11051 .with_column("schema_id", SqlScalarType::String.nullable(false))
11052 .with_column("name", SqlScalarType::String.nullable(false))
11053 .with_column("comment", SqlScalarType::String.nullable(false))
11054 .finish(),
11055 column_comments: BTreeMap::new(),
11056 sql: "WITH comments AS (
11057 SELECT id, comment
11058 FROM mz_internal.mz_comments
11059 WHERE object_type = 'type' AND object_sub_id IS NULL
11060 )
11061 SELECT schema_id, name, COALESCE(comment, '') as comment
11062 FROM mz_catalog.mz_types types
11063 LEFT JOIN comments ON types.id = comments.id",
11064 access: vec![PUBLIC_SELECT],
11065});
11066
11067pub static MZ_SHOW_CONNECTIONS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11068 name: "mz_show_connections",
11069 schema: MZ_INTERNAL_SCHEMA,
11070 oid: oid::VIEW_MZ_SHOW_CONNECTIONS_OID,
11071 desc: RelationDesc::builder()
11072 .with_column("schema_id", SqlScalarType::String.nullable(false))
11073 .with_column("name", SqlScalarType::String.nullable(false))
11074 .with_column("type", SqlScalarType::String.nullable(false))
11075 .with_column("comment", SqlScalarType::String.nullable(false))
11076 .finish(),
11077 column_comments: BTreeMap::new(),
11078 sql: "WITH comments AS (
11079 SELECT id, comment
11080 FROM mz_internal.mz_comments
11081 WHERE object_type = 'connection' AND object_sub_id IS NULL
11082 )
11083 SELECT schema_id, name, type, COALESCE(comment, '') as comment
11084 FROM mz_catalog.mz_connections connections
11085 LEFT JOIN comments ON connections.id = comments.id",
11086 access: vec![PUBLIC_SELECT],
11087});
11088
11089pub static MZ_SHOW_SOURCES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11090 name: "mz_show_sources",
11091 schema: MZ_INTERNAL_SCHEMA,
11092 oid: oid::VIEW_MZ_SHOW_SOURCES_OID,
11093 desc: RelationDesc::builder()
11094 .with_column("id", SqlScalarType::String.nullable(false))
11095 .with_column("name", SqlScalarType::String.nullable(false))
11096 .with_column("type", SqlScalarType::String.nullable(false))
11097 .with_column("cluster", SqlScalarType::String.nullable(true))
11098 .with_column("schema_id", SqlScalarType::String.nullable(false))
11099 .with_column("cluster_id", SqlScalarType::String.nullable(true))
11100 .with_column("comment", SqlScalarType::String.nullable(false))
11101 .finish(),
11102 column_comments: BTreeMap::new(),
11103 sql: "
11104WITH comments AS (
11105 SELECT id, comment
11106 FROM mz_internal.mz_comments
11107 WHERE object_type = 'source' AND object_sub_id IS NULL
11108)
11109SELECT
11110 sources.id,
11111 sources.name,
11112 sources.type,
11113 clusters.name AS cluster,
11114 schema_id,
11115 cluster_id,
11116 COALESCE(comments.comment, '') as comment
11117FROM
11118 mz_catalog.mz_sources AS sources
11119 LEFT JOIN
11120 mz_catalog.mz_clusters AS clusters
11121 ON clusters.id = sources.cluster_id
11122 LEFT JOIN comments ON sources.id = comments.id",
11123 access: vec![PUBLIC_SELECT],
11124});
11125
11126pub static MZ_SHOW_SINKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11127 name: "mz_show_sinks",
11128 schema: MZ_INTERNAL_SCHEMA,
11129 oid: oid::VIEW_MZ_SHOW_SINKS_OID,
11130 desc: RelationDesc::builder()
11131 .with_column("id", SqlScalarType::String.nullable(false))
11132 .with_column("name", SqlScalarType::String.nullable(false))
11133 .with_column("type", SqlScalarType::String.nullable(false))
11134 .with_column("cluster", SqlScalarType::String.nullable(false))
11135 .with_column("schema_id", SqlScalarType::String.nullable(false))
11136 .with_column("cluster_id", SqlScalarType::String.nullable(false))
11137 .with_column("comment", SqlScalarType::String.nullable(false))
11138 .finish(),
11139 column_comments: BTreeMap::new(),
11140 sql: "
11141WITH comments AS (
11142 SELECT id, comment
11143 FROM mz_internal.mz_comments
11144 WHERE object_type = 'sink' AND object_sub_id IS NULL
11145)
11146SELECT
11147 sinks.id,
11148 sinks.name,
11149 sinks.type,
11150 clusters.name AS cluster,
11151 schema_id,
11152 cluster_id,
11153 COALESCE(comments.comment, '') as comment
11154FROM
11155 mz_catalog.mz_sinks AS sinks
11156 JOIN
11157 mz_catalog.mz_clusters AS clusters
11158 ON clusters.id = sinks.cluster_id
11159 LEFT JOIN comments ON sinks.id = comments.id",
11160 access: vec![PUBLIC_SELECT],
11161});
11162
11163pub static MZ_SHOW_MATERIALIZED_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11164 name: "mz_show_materialized_views",
11165 schema: MZ_INTERNAL_SCHEMA,
11166 oid: oid::VIEW_MZ_SHOW_MATERIALIZED_VIEWS_OID,
11167 desc: RelationDesc::builder()
11168 .with_column("id", SqlScalarType::String.nullable(false))
11169 .with_column("name", SqlScalarType::String.nullable(false))
11170 .with_column("cluster", SqlScalarType::String.nullable(false))
11171 .with_column("schema_id", SqlScalarType::String.nullable(false))
11172 .with_column("cluster_id", SqlScalarType::String.nullable(false))
11173 .with_column("comment", SqlScalarType::String.nullable(false))
11174 .finish(),
11175 column_comments: BTreeMap::new(),
11176 sql: "
11177WITH
11178 comments AS (
11179 SELECT id, comment
11180 FROM mz_internal.mz_comments
11181 WHERE object_type = 'materialized-view' AND object_sub_id IS NULL
11182 )
11183SELECT
11184 mviews.id as id,
11185 mviews.name,
11186 clusters.name AS cluster,
11187 schema_id,
11188 cluster_id,
11189 COALESCE(comments.comment, '') as comment
11190FROM
11191 mz_catalog.mz_materialized_views AS mviews
11192 JOIN mz_catalog.mz_clusters AS clusters ON clusters.id = mviews.cluster_id
11193 LEFT JOIN comments ON mviews.id = comments.id",
11194 access: vec![PUBLIC_SELECT],
11195});
11196
11197pub static MZ_SHOW_INDEXES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11198 name: "mz_show_indexes",
11199 schema: MZ_INTERNAL_SCHEMA,
11200 oid: oid::VIEW_MZ_SHOW_INDEXES_OID,
11201 desc: RelationDesc::builder()
11202 .with_column("id", SqlScalarType::String.nullable(false))
11203 .with_column("name", SqlScalarType::String.nullable(false))
11204 .with_column("on", SqlScalarType::String.nullable(false))
11205 .with_column("cluster", SqlScalarType::String.nullable(false))
11206 .with_column(
11207 "key",
11208 SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
11209 )
11210 .with_column("on_id", SqlScalarType::String.nullable(false))
11211 .with_column("schema_id", SqlScalarType::String.nullable(false))
11212 .with_column("cluster_id", SqlScalarType::String.nullable(false))
11213 .with_column("comment", SqlScalarType::String.nullable(false))
11214 .finish(),
11215 column_comments: BTreeMap::new(),
11216 sql: "
11217WITH comments AS (
11218 SELECT id, comment
11219 FROM mz_internal.mz_comments
11220 WHERE object_type = 'index' AND object_sub_id IS NULL
11221)
11222SELECT
11223 idxs.id AS id,
11224 idxs.name AS name,
11225 objs.name AS on,
11226 clusters.name AS cluster,
11227 COALESCE(keys.key, '{}'::_text) AS key,
11228 idxs.on_id AS on_id,
11229 objs.schema_id AS schema_id,
11230 clusters.id AS cluster_id,
11231 COALESCE(comments.comment, '') as comment
11232FROM
11233 mz_catalog.mz_indexes AS idxs
11234 JOIN mz_catalog.mz_objects AS objs ON idxs.on_id = objs.id
11235 JOIN mz_catalog.mz_clusters AS clusters ON clusters.id = idxs.cluster_id
11236 LEFT JOIN
11237 (SELECT
11238 idxs.id,
11239 ARRAY_AGG(
11240 CASE
11241 WHEN idx_cols.on_expression IS NULL THEN obj_cols.name
11242 ELSE idx_cols.on_expression
11243 END
11244 ORDER BY idx_cols.index_position ASC
11245 ) AS key
11246 FROM
11247 mz_catalog.mz_indexes AS idxs
11248 JOIN mz_catalog.mz_index_columns idx_cols ON idxs.id = idx_cols.index_id
11249 LEFT JOIN mz_catalog.mz_columns obj_cols ON
11250 idxs.on_id = obj_cols.id AND idx_cols.on_position = obj_cols.position
11251 GROUP BY idxs.id) AS keys
11252 ON idxs.id = keys.id
11253 LEFT JOIN comments ON idxs.id = comments.id",
11254 access: vec![PUBLIC_SELECT],
11255});
11256
11257pub static MZ_SHOW_CLUSTER_REPLICAS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11258 name: "mz_show_cluster_replicas",
11259 schema: MZ_INTERNAL_SCHEMA,
11260 oid: oid::VIEW_MZ_SHOW_CLUSTER_REPLICAS_OID,
11261 desc: RelationDesc::builder()
11262 .with_column("cluster", SqlScalarType::String.nullable(false))
11263 .with_column("replica", SqlScalarType::String.nullable(false))
11264 .with_column("replica_id", SqlScalarType::String.nullable(false))
11265 .with_column("size", SqlScalarType::String.nullable(true))
11266 .with_column("ready", SqlScalarType::Bool.nullable(false))
11267 .with_column("comment", SqlScalarType::String.nullable(false))
11268 .finish(),
11269 column_comments: BTreeMap::new(),
11270 sql: r#"SELECT
11271 mz_catalog.mz_clusters.name AS cluster,
11272 mz_catalog.mz_cluster_replicas.name AS replica,
11273 mz_catalog.mz_cluster_replicas.id as replica_id,
11274 mz_catalog.mz_cluster_replicas.size AS size,
11275 coalesce(statuses.ready, FALSE) AS ready,
11276 coalesce(comments.comment, '') as comment
11277FROM
11278 mz_catalog.mz_cluster_replicas
11279 JOIN mz_catalog.mz_clusters
11280 ON mz_catalog.mz_cluster_replicas.cluster_id = mz_catalog.mz_clusters.id
11281 LEFT JOIN
11282 (
11283 SELECT
11284 replica_id,
11285 bool_and(hydrated) AS ready
11286 FROM mz_internal.mz_hydration_statuses
11287 WHERE replica_id is not null
11288 GROUP BY replica_id
11289 ) AS statuses
11290 ON mz_catalog.mz_cluster_replicas.id = statuses.replica_id
11291 LEFT JOIN mz_internal.mz_comments comments
11292 ON mz_catalog.mz_cluster_replicas.id = comments.id
11293WHERE (comments.object_type = 'cluster-replica' OR comments.object_type IS NULL)
11294ORDER BY 1, 2"#,
11295 access: vec![PUBLIC_SELECT],
11296});
11297
11298pub static MZ_SHOW_CONTINUAL_TASKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11299 name: "mz_show_continual_tasks",
11300 schema: MZ_INTERNAL_SCHEMA,
11301 oid: oid::VIEW_MZ_SHOW_CONTINUAL_TASKS_OID,
11302 desc: RelationDesc::builder()
11303 .with_column("id", SqlScalarType::String.nullable(false))
11304 .with_column("name", SqlScalarType::String.nullable(false))
11305 .with_column("cluster", SqlScalarType::String.nullable(false))
11306 .with_column("schema_id", SqlScalarType::String.nullable(false))
11307 .with_column("cluster_id", SqlScalarType::String.nullable(false))
11308 .with_column("comment", SqlScalarType::String.nullable(false))
11309 .finish(),
11310 column_comments: BTreeMap::new(),
11311 sql: "
11312WITH comments AS (
11313 SELECT id, comment
11314 FROM mz_internal.mz_comments
11315 WHERE object_type = 'continual-task' AND object_sub_id IS NULL
11316)
11317SELECT
11318 cts.id as id,
11319 cts.name,
11320 clusters.name AS cluster,
11321 schema_id,
11322 cluster_id,
11323 COALESCE(comments.comment, '') as comment
11324FROM
11325 mz_internal.mz_continual_tasks AS cts
11326 JOIN mz_catalog.mz_clusters AS clusters ON clusters.id = cts.cluster_id
11327 LEFT JOIN comments ON cts.id = comments.id",
11328 access: vec![PUBLIC_SELECT],
11329});
11330
11331pub static MZ_MCP_DATA_PRODUCTS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11337 name: "mz_mcp_data_products",
11338 schema: MZ_INTERNAL_SCHEMA,
11339 oid: oid::VIEW_MZ_MCP_DATA_PRODUCTS_OID,
11340 desc: RelationDesc::builder()
11341 .with_column("object_name", SqlScalarType::String.nullable(false))
11342 .with_column("cluster", SqlScalarType::String.nullable(false))
11343 .with_column("description", SqlScalarType::String.nullable(true))
11344 .with_column("schema", SqlScalarType::Jsonb.nullable(false))
11345 .with_key(vec![0, 1, 2])
11346 .finish(),
11347 column_comments: BTreeMap::from_iter([
11348 (
11349 "object_name",
11350 "Fully qualified object name (database.schema.name).",
11351 ),
11352 ("cluster", "Cluster where the index is hosted."),
11353 (
11354 "description",
11355 "Index comment (used as data product description).",
11356 ),
11357 (
11358 "schema",
11359 "JSON Schema describing the object's columns and types.",
11360 ),
11361 ]),
11362 sql: r#"
11363SELECT * FROM (
11364 SELECT
11365 '"' || op.database || '"."' || op.schema || '"."' || op.name || '"' AS object_name,
11366 c.name AS cluster,
11367 cts.comment AS description,
11368 COALESCE(jsonb_build_object(
11369 'type', 'object',
11370 'required', jsonb_agg(distinct ccol.name) FILTER (WHERE ccol.position = ic.on_position),
11371 'properties', jsonb_strip_nulls(jsonb_object_agg(
11372 ccol.name,
11373 CASE
11374 WHEN ccol.type IN (
11375 'uint2', 'uint4','uint8', 'int', 'integer', 'smallint',
11376 'double', 'double precision', 'bigint', 'float',
11377 'numeric', 'real'
11378 ) THEN jsonb_build_object(
11379 'type', 'number',
11380 'description', cts_col.comment
11381 )
11382 WHEN ccol.type = 'boolean' THEN jsonb_build_object(
11383 'type', 'boolean',
11384 'description', cts_col.comment
11385 )
11386 WHEN ccol.type = 'bytea' THEN jsonb_build_object(
11387 'type', 'string',
11388 'description', cts_col.comment,
11389 'contentEncoding', 'base64',
11390 'contentMediaType', 'application/octet-stream'
11391 )
11392 WHEN ccol.type = 'date' THEN jsonb_build_object(
11393 'type', 'string',
11394 'format', 'date',
11395 'description', cts_col.comment
11396 )
11397 WHEN ccol.type = 'time' THEN jsonb_build_object(
11398 'type', 'string',
11399 'format', 'time',
11400 'description', cts_col.comment
11401 )
11402 WHEN ccol.type ilike 'timestamp%%' THEN jsonb_build_object(
11403 'type', 'string',
11404 'format', 'date-time',
11405 'description', cts_col.comment
11406 )
11407 WHEN ccol.type = 'jsonb' THEN jsonb_build_object(
11408 'type', 'object',
11409 'description', cts_col.comment
11410 )
11411 WHEN ccol.type = 'uuid' THEN jsonb_build_object(
11412 'type', 'string',
11413 'format', 'uuid',
11414 'description', cts_col.comment
11415 )
11416 ELSE jsonb_build_object(
11417 'type', 'string',
11418 'description', cts_col.comment
11419 )
11420 END
11421 ))
11422 ), '{"type": "object", "properties": {}}'::jsonb) AS schema
11423FROM mz_internal.mz_show_my_object_privileges op
11424JOIN mz_objects o ON op.name = o.name AND op.object_type = o.type
11425JOIN mz_schemas s ON s.name = op.schema AND s.id = o.schema_id
11426JOIN mz_databases d ON d.name = op.database AND d.id = s.database_id
11427JOIN mz_indexes i ON i.on_id = o.id
11428JOIN mz_index_columns ic ON i.id = ic.index_id
11429JOIN mz_columns ccol ON ccol.id = o.id
11430JOIN mz_clusters c ON c.id = i.cluster_id
11431JOIN mz_internal.mz_show_my_cluster_privileges cp ON cp.name = c.name
11432LEFT JOIN mz_internal.mz_comments cts ON cts.id = i.id AND cts.object_sub_id IS NULL
11433LEFT JOIN mz_internal.mz_comments cts_col ON cts_col.id = o.id AND cts_col.object_sub_id = ccol.position
11434WHERE op.privilege_type = 'SELECT'
11435 AND cp.privilege_type = 'USAGE'
11436GROUP BY 1, 2, 3
11437)
11438"#,
11439 access: vec![PUBLIC_SELECT],
11440});
11441
11442pub static MZ_SHOW_ROLE_MEMBERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11443 name: "mz_show_role_members",
11444 schema: MZ_INTERNAL_SCHEMA,
11445 oid: oid::VIEW_MZ_SHOW_ROLE_MEMBERS_OID,
11446 desc: RelationDesc::builder()
11447 .with_column("role", SqlScalarType::String.nullable(false))
11448 .with_column("member", SqlScalarType::String.nullable(false))
11449 .with_column("grantor", SqlScalarType::String.nullable(false))
11450 .finish(),
11451 column_comments: BTreeMap::from_iter([
11452 ("role", "The role that `member` is a member of."),
11453 ("member", "The role that is a member of `role`."),
11454 (
11455 "grantor",
11456 "The role that granted membership of `member` to `role`.",
11457 ),
11458 ]),
11459 sql: r#"SELECT
11460 r1.name AS role,
11461 r2.name AS member,
11462 r3.name AS grantor
11463FROM mz_catalog.mz_role_members rm
11464JOIN mz_catalog.mz_roles r1 ON r1.id = rm.role_id
11465JOIN mz_catalog.mz_roles r2 ON r2.id = rm.member
11466JOIN mz_catalog.mz_roles r3 ON r3.id = rm.grantor
11467ORDER BY role"#,
11468 access: vec![PUBLIC_SELECT],
11469});
11470
11471pub static MZ_SHOW_MY_ROLE_MEMBERS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11472 name: "mz_show_my_role_members",
11473 schema: MZ_INTERNAL_SCHEMA,
11474 oid: oid::VIEW_MZ_SHOW_MY_ROLE_MEMBERS_OID,
11475 desc: RelationDesc::builder()
11476 .with_column("role", SqlScalarType::String.nullable(false))
11477 .with_column("member", SqlScalarType::String.nullable(false))
11478 .with_column("grantor", SqlScalarType::String.nullable(false))
11479 .finish(),
11480 column_comments: BTreeMap::from_iter([
11481 ("role", "The role that `member` is a member of."),
11482 ("member", "The role that is a member of `role`."),
11483 (
11484 "grantor",
11485 "The role that granted membership of `member` to `role`.",
11486 ),
11487 ]),
11488 sql: r#"SELECT role, member, grantor
11489FROM mz_internal.mz_show_role_members
11490WHERE pg_has_role(member, 'USAGE')"#,
11491 access: vec![PUBLIC_SELECT],
11492});
11493
11494pub static MZ_SHOW_SYSTEM_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11495 name: "mz_show_system_privileges",
11496 schema: MZ_INTERNAL_SCHEMA,
11497 oid: oid::VIEW_MZ_SHOW_SYSTEM_PRIVILEGES_OID,
11498 desc: RelationDesc::builder()
11499 .with_column("grantor", SqlScalarType::String.nullable(true))
11500 .with_column("grantee", SqlScalarType::String.nullable(true))
11501 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11502 .finish(),
11503 column_comments: BTreeMap::from_iter([
11504 ("grantor", "The role that granted the privilege."),
11505 ("grantee", "The role that the privilege was granted to."),
11506 ("privilege_type", "They type of privilege granted."),
11507 ]),
11508 sql: r#"SELECT
11509 grantor.name AS grantor,
11510 CASE privileges.grantee
11511 WHEN 'p' THEN 'PUBLIC'
11512 ELSE grantee.name
11513 END AS grantee,
11514 privileges.privilege_type AS privilege_type
11515FROM
11516 (SELECT mz_internal.mz_aclexplode(ARRAY[privileges]).*
11517 FROM mz_catalog.mz_system_privileges) AS privileges
11518LEFT JOIN mz_catalog.mz_roles grantor ON privileges.grantor = grantor.id
11519LEFT JOIN mz_catalog.mz_roles grantee ON privileges.grantee = grantee.id
11520WHERE privileges.grantee NOT LIKE 's%'"#,
11521 access: vec![PUBLIC_SELECT],
11522});
11523
11524pub static MZ_SHOW_MY_SYSTEM_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11525 name: "mz_show_my_system_privileges",
11526 schema: MZ_INTERNAL_SCHEMA,
11527 oid: oid::VIEW_MZ_SHOW_MY_SYSTEM_PRIVILEGES_OID,
11528 desc: RelationDesc::builder()
11529 .with_column("grantor", SqlScalarType::String.nullable(true))
11530 .with_column("grantee", SqlScalarType::String.nullable(true))
11531 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11532 .finish(),
11533 column_comments: BTreeMap::from_iter([
11534 ("grantor", "The role that granted the privilege."),
11535 ("grantee", "The role that the privilege was granted to."),
11536 ("privilege_type", "They type of privilege granted."),
11537 ]),
11538 sql: r#"SELECT grantor, grantee, privilege_type
11539FROM mz_internal.mz_show_system_privileges
11540WHERE
11541 CASE
11542 WHEN grantee = 'PUBLIC' THEN true
11543 ELSE pg_has_role(grantee, 'USAGE')
11544 END"#,
11545 access: vec![PUBLIC_SELECT],
11546});
11547
11548pub static MZ_SHOW_CLUSTER_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11549 name: "mz_show_cluster_privileges",
11550 schema: MZ_INTERNAL_SCHEMA,
11551 oid: oid::VIEW_MZ_SHOW_CLUSTER_PRIVILEGES_OID,
11552 desc: RelationDesc::builder()
11553 .with_column("grantor", SqlScalarType::String.nullable(true))
11554 .with_column("grantee", SqlScalarType::String.nullable(true))
11555 .with_column("name", SqlScalarType::String.nullable(false))
11556 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11557 .finish(),
11558 column_comments: BTreeMap::from_iter([
11559 ("grantor", "The role that granted the privilege."),
11560 ("grantee", "The role that the privilege was granted to."),
11561 ("name", "The name of the cluster."),
11562 ("privilege_type", "They type of privilege granted."),
11563 ]),
11564 sql: r#"SELECT
11565 grantor.name AS grantor,
11566 CASE privileges.grantee
11567 WHEN 'p' THEN 'PUBLIC'
11568 ELSE grantee.name
11569 END AS grantee,
11570 privileges.name AS name,
11571 privileges.privilege_type AS privilege_type
11572FROM
11573 (SELECT mz_internal.mz_aclexplode(privileges).*, name
11574 FROM mz_catalog.mz_clusters
11575 WHERE id NOT LIKE 's%') AS privileges
11576LEFT JOIN mz_catalog.mz_roles grantor ON privileges.grantor = grantor.id
11577LEFT JOIN mz_catalog.mz_roles grantee ON privileges.grantee = grantee.id
11578WHERE privileges.grantee NOT LIKE 's%'"#,
11579 access: vec![PUBLIC_SELECT],
11580});
11581
11582pub static MZ_SHOW_MY_CLUSTER_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11583 name: "mz_show_my_cluster_privileges",
11584 schema: MZ_INTERNAL_SCHEMA,
11585 oid: oid::VIEW_MZ_SHOW_MY_CLUSTER_PRIVILEGES_OID,
11586 desc: RelationDesc::builder()
11587 .with_column("grantor", SqlScalarType::String.nullable(true))
11588 .with_column("grantee", SqlScalarType::String.nullable(true))
11589 .with_column("name", SqlScalarType::String.nullable(false))
11590 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11591 .finish(),
11592 column_comments: BTreeMap::from_iter([
11593 ("grantor", "The role that granted the privilege."),
11594 ("grantee", "The role that the privilege was granted to."),
11595 ("name", "The name of the cluster."),
11596 ("privilege_type", "They type of privilege granted."),
11597 ]),
11598 sql: r#"SELECT grantor, grantee, name, privilege_type
11599FROM mz_internal.mz_show_cluster_privileges
11600WHERE
11601 CASE
11602 WHEN grantee = 'PUBLIC' THEN true
11603 ELSE pg_has_role(grantee, 'USAGE')
11604 END"#,
11605 access: vec![PUBLIC_SELECT],
11606});
11607
11608pub static MZ_SHOW_DATABASE_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11609 name: "mz_show_database_privileges",
11610 schema: MZ_INTERNAL_SCHEMA,
11611 oid: oid::VIEW_MZ_SHOW_DATABASE_PRIVILEGES_OID,
11612 desc: RelationDesc::builder()
11613 .with_column("grantor", SqlScalarType::String.nullable(true))
11614 .with_column("grantee", SqlScalarType::String.nullable(true))
11615 .with_column("name", SqlScalarType::String.nullable(false))
11616 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11617 .finish(),
11618 column_comments: BTreeMap::from_iter([
11619 ("grantor", "The role that granted the privilege."),
11620 ("grantee", "The role that the privilege was granted to."),
11621 ("name", "The name of the database."),
11622 ("privilege_type", "They type of privilege granted."),
11623 ]),
11624 sql: r#"SELECT
11625 grantor.name AS grantor,
11626 CASE privileges.grantee
11627 WHEN 'p' THEN 'PUBLIC'
11628 ELSE grantee.name
11629 END AS grantee,
11630 privileges.name AS name,
11631 privileges.privilege_type AS privilege_type
11632FROM
11633 (SELECT mz_internal.mz_aclexplode(privileges).*, name
11634 FROM mz_catalog.mz_databases
11635 WHERE id NOT LIKE 's%') AS privileges
11636LEFT JOIN mz_catalog.mz_roles grantor ON privileges.grantor = grantor.id
11637LEFT JOIN mz_catalog.mz_roles grantee ON privileges.grantee = grantee.id
11638WHERE privileges.grantee NOT LIKE 's%'"#,
11639 access: vec![PUBLIC_SELECT],
11640});
11641
11642pub static MZ_SHOW_MY_DATABASE_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11643 name: "mz_show_my_database_privileges",
11644 schema: MZ_INTERNAL_SCHEMA,
11645 oid: oid::VIEW_MZ_SHOW_MY_DATABASE_PRIVILEGES_OID,
11646 desc: RelationDesc::builder()
11647 .with_column("grantor", SqlScalarType::String.nullable(true))
11648 .with_column("grantee", SqlScalarType::String.nullable(true))
11649 .with_column("name", SqlScalarType::String.nullable(false))
11650 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11651 .finish(),
11652 column_comments: BTreeMap::from_iter([
11653 ("grantor", "The role that granted the privilege."),
11654 ("grantee", "The role that the privilege was granted to."),
11655 ("name", "The name of the cluster."),
11656 ("privilege_type", "They type of privilege granted."),
11657 ]),
11658 sql: r#"SELECT grantor, grantee, name, privilege_type
11659FROM mz_internal.mz_show_database_privileges
11660WHERE
11661 CASE
11662 WHEN grantee = 'PUBLIC' THEN true
11663 ELSE pg_has_role(grantee, 'USAGE')
11664 END"#,
11665 access: vec![PUBLIC_SELECT],
11666});
11667
11668pub static MZ_SHOW_SCHEMA_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11669 name: "mz_show_schema_privileges",
11670 schema: MZ_INTERNAL_SCHEMA,
11671 oid: oid::VIEW_MZ_SHOW_SCHEMA_PRIVILEGES_OID,
11672 desc: RelationDesc::builder()
11673 .with_column("grantor", SqlScalarType::String.nullable(true))
11674 .with_column("grantee", SqlScalarType::String.nullable(true))
11675 .with_column("database", SqlScalarType::String.nullable(true))
11676 .with_column("name", SqlScalarType::String.nullable(false))
11677 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11678 .finish(),
11679 column_comments: BTreeMap::from_iter([
11680 ("grantor", "The role that granted the privilege."),
11681 ("grantee", "The role that the privilege was granted to."),
11682 (
11683 "database",
11684 "The name of the database containing the schema.",
11685 ),
11686 ("name", "The name of the schema."),
11687 ("privilege_type", "They type of privilege granted."),
11688 ]),
11689 sql: r#"SELECT
11690 grantor.name AS grantor,
11691 CASE privileges.grantee
11692 WHEN 'p' THEN 'PUBLIC'
11693 ELSE grantee.name
11694 END AS grantee,
11695 databases.name AS database,
11696 privileges.name AS name,
11697 privileges.privilege_type AS privilege_type
11698FROM
11699 (SELECT mz_internal.mz_aclexplode(privileges).*, database_id, name
11700 FROM mz_catalog.mz_schemas
11701 WHERE id NOT LIKE 's%') AS privileges
11702LEFT JOIN mz_catalog.mz_roles grantor ON privileges.grantor = grantor.id
11703LEFT JOIN mz_catalog.mz_roles grantee ON privileges.grantee = grantee.id
11704LEFT JOIN mz_catalog.mz_databases databases ON privileges.database_id = databases.id
11705WHERE privileges.grantee NOT LIKE 's%'"#,
11706 access: vec![PUBLIC_SELECT],
11707});
11708
11709pub static MZ_SHOW_MY_SCHEMA_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11710 name: "mz_show_my_schema_privileges",
11711 schema: MZ_INTERNAL_SCHEMA,
11712 oid: oid::VIEW_MZ_SHOW_MY_SCHEMA_PRIVILEGES_OID,
11713 desc: RelationDesc::builder()
11714 .with_column("grantor", SqlScalarType::String.nullable(true))
11715 .with_column("grantee", SqlScalarType::String.nullable(true))
11716 .with_column("database", SqlScalarType::String.nullable(true))
11717 .with_column("name", SqlScalarType::String.nullable(false))
11718 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11719 .finish(),
11720 column_comments: BTreeMap::from_iter([
11721 ("grantor", "The role that granted the privilege."),
11722 ("grantee", "The role that the privilege was granted to."),
11723 (
11724 "database",
11725 "The name of the database containing the schema.",
11726 ),
11727 ("name", "The name of the schema."),
11728 ("privilege_type", "They type of privilege granted."),
11729 ]),
11730 sql: r#"SELECT grantor, grantee, database, name, privilege_type
11731FROM mz_internal.mz_show_schema_privileges
11732WHERE
11733 CASE
11734 WHEN grantee = 'PUBLIC' THEN true
11735 ELSE pg_has_role(grantee, 'USAGE')
11736 END"#,
11737 access: vec![PUBLIC_SELECT],
11738});
11739
11740pub static MZ_SHOW_OBJECT_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11741 name: "mz_show_object_privileges",
11742 schema: MZ_INTERNAL_SCHEMA,
11743 oid: oid::VIEW_MZ_SHOW_OBJECT_PRIVILEGES_OID,
11744 desc: RelationDesc::builder()
11745 .with_column("grantor", SqlScalarType::String.nullable(true))
11746 .with_column("grantee", SqlScalarType::String.nullable(true))
11747 .with_column("database", SqlScalarType::String.nullable(true))
11748 .with_column("schema", SqlScalarType::String.nullable(true))
11749 .with_column("name", SqlScalarType::String.nullable(false))
11750 .with_column("object_type", SqlScalarType::String.nullable(false))
11751 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11752 .finish(),
11753 column_comments: BTreeMap::from_iter([
11754 ("grantor", "The role that granted the privilege."),
11755 ("grantee", "The role that the privilege was granted to."),
11756 (
11757 "database",
11758 "The name of the database containing the object.",
11759 ),
11760 ("schema", "The name of the schema containing the object."),
11761 ("name", "The name of the object."),
11762 (
11763 "object_type",
11764 "The type of object the privilege is granted on.",
11765 ),
11766 ("privilege_type", "They type of privilege granted."),
11767 ]),
11768 sql: r#"SELECT
11769 grantor.name AS grantor,
11770 CASE privileges.grantee
11771 WHEN 'p' THEN 'PUBLIC'
11772 ELSE grantee.name
11773 END AS grantee,
11774 databases.name AS database,
11775 schemas.name AS schema,
11776 privileges.name AS name,
11777 privileges.type AS object_type,
11778 privileges.privilege_type AS privilege_type
11779FROM
11780 (SELECT mz_internal.mz_aclexplode(privileges).*, schema_id, name, type
11781 FROM mz_catalog.mz_objects
11782 WHERE id NOT LIKE 's%') AS privileges
11783LEFT JOIN mz_catalog.mz_roles grantor ON privileges.grantor = grantor.id
11784LEFT JOIN mz_catalog.mz_roles grantee ON privileges.grantee = grantee.id
11785LEFT JOIN mz_catalog.mz_schemas schemas ON privileges.schema_id = schemas.id
11786LEFT JOIN mz_catalog.mz_databases databases ON schemas.database_id = databases.id
11787WHERE privileges.grantee NOT LIKE 's%'"#,
11788 access: vec![PUBLIC_SELECT],
11789});
11790
11791pub static MZ_SHOW_MY_OBJECT_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11792 name: "mz_show_my_object_privileges",
11793 schema: MZ_INTERNAL_SCHEMA,
11794 oid: oid::VIEW_MZ_SHOW_MY_OBJECT_PRIVILEGES_OID,
11795 desc: RelationDesc::builder()
11796 .with_column("grantor", SqlScalarType::String.nullable(true))
11797 .with_column("grantee", SqlScalarType::String.nullable(true))
11798 .with_column("database", SqlScalarType::String.nullable(true))
11799 .with_column("schema", SqlScalarType::String.nullable(true))
11800 .with_column("name", SqlScalarType::String.nullable(false))
11801 .with_column("object_type", SqlScalarType::String.nullable(false))
11802 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11803 .finish(),
11804 column_comments: BTreeMap::from_iter([
11805 ("grantor", "The role that granted the privilege."),
11806 ("grantee", "The role that the privilege was granted to."),
11807 (
11808 "database",
11809 "The name of the database containing the object.",
11810 ),
11811 ("schema", "The name of the schema containing the object."),
11812 ("name", "The name of the object."),
11813 (
11814 "object_type",
11815 "The type of object the privilege is granted on.",
11816 ),
11817 ("privilege_type", "They type of privilege granted."),
11818 ]),
11819 sql: r#"SELECT grantor, grantee, database, schema, name, object_type, privilege_type
11820FROM mz_internal.mz_show_object_privileges
11821WHERE
11822 CASE
11823 WHEN grantee = 'PUBLIC' THEN true
11824 ELSE pg_has_role(grantee, 'USAGE')
11825 END"#,
11826 access: vec![PUBLIC_SELECT],
11827});
11828
11829pub static MZ_SHOW_ALL_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11830 name: "mz_show_all_privileges",
11831 schema: MZ_INTERNAL_SCHEMA,
11832 oid: oid::VIEW_MZ_SHOW_ALL_PRIVILEGES_OID,
11833 desc: RelationDesc::builder()
11834 .with_column("grantor", SqlScalarType::String.nullable(true))
11835 .with_column("grantee", SqlScalarType::String.nullable(true))
11836 .with_column("database", SqlScalarType::String.nullable(true))
11837 .with_column("schema", SqlScalarType::String.nullable(true))
11838 .with_column("name", SqlScalarType::String.nullable(true))
11839 .with_column("object_type", SqlScalarType::String.nullable(false))
11840 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11841 .finish(),
11842 column_comments: BTreeMap::from_iter([
11843 ("grantor", "The role that granted the privilege."),
11844 ("grantee", "The role that the privilege was granted to."),
11845 (
11846 "database",
11847 "The name of the database containing the object.",
11848 ),
11849 ("schema", "The name of the schema containing the object."),
11850 ("name", "The name of the privilege target."),
11851 (
11852 "object_type",
11853 "The type of object the privilege is granted on.",
11854 ),
11855 ("privilege_type", "They type of privilege granted."),
11856 ]),
11857 sql: r#"SELECT grantor, grantee, NULL AS database, NULL AS schema, NULL AS name, 'system' AS object_type, privilege_type
11858FROM mz_internal.mz_show_system_privileges
11859UNION ALL
11860SELECT grantor, grantee, NULL AS database, NULL AS schema, name, 'cluster' AS object_type, privilege_type
11861FROM mz_internal.mz_show_cluster_privileges
11862UNION ALL
11863SELECT grantor, grantee, NULL AS database, NULL AS schema, name, 'database' AS object_type, privilege_type
11864FROM mz_internal.mz_show_database_privileges
11865UNION ALL
11866SELECT grantor, grantee, database, NULL AS schema, name, 'schema' AS object_type, privilege_type
11867FROM mz_internal.mz_show_schema_privileges
11868UNION ALL
11869SELECT grantor, grantee, database, schema, name, object_type, privilege_type
11870FROM mz_internal.mz_show_object_privileges"#,
11871 access: vec![PUBLIC_SELECT],
11872});
11873
11874pub static MZ_SHOW_ALL_MY_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11875 name: "mz_show_all_my_privileges",
11876 schema: MZ_INTERNAL_SCHEMA,
11877 oid: oid::VIEW_MZ_SHOW_ALL_MY_PRIVILEGES_OID,
11878 desc: RelationDesc::builder()
11879 .with_column("grantor", SqlScalarType::String.nullable(true))
11880 .with_column("grantee", SqlScalarType::String.nullable(true))
11881 .with_column("database", SqlScalarType::String.nullable(true))
11882 .with_column("schema", SqlScalarType::String.nullable(true))
11883 .with_column("name", SqlScalarType::String.nullable(true))
11884 .with_column("object_type", SqlScalarType::String.nullable(false))
11885 .with_column("privilege_type", SqlScalarType::String.nullable(false))
11886 .finish(),
11887 column_comments: BTreeMap::from_iter([
11888 ("grantor", "The role that granted the privilege."),
11889 ("grantee", "The role that the privilege was granted to."),
11890 (
11891 "database",
11892 "The name of the database containing the object.",
11893 ),
11894 ("schema", "The name of the schema containing the object."),
11895 ("name", "The name of the privilege target."),
11896 (
11897 "object_type",
11898 "The type of object the privilege is granted on.",
11899 ),
11900 ("privilege_type", "They type of privilege granted."),
11901 ]),
11902 sql: r#"SELECT grantor, grantee, database, schema, name, object_type, privilege_type
11903FROM mz_internal.mz_show_all_privileges
11904WHERE
11905 CASE
11906 WHEN grantee = 'PUBLIC' THEN true
11907 ELSE pg_has_role(grantee, 'USAGE')
11908 END"#,
11909 access: vec![PUBLIC_SELECT],
11910});
11911
11912pub static MZ_SHOW_DEFAULT_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11913 name: "mz_show_default_privileges",
11914 schema: MZ_INTERNAL_SCHEMA,
11915 oid: oid::VIEW_MZ_SHOW_DEFAULT_PRIVILEGES_OID,
11916 desc: RelationDesc::builder()
11917 .with_column("object_owner", SqlScalarType::String.nullable(true))
11918 .with_column("database", SqlScalarType::String.nullable(true))
11919 .with_column("schema", SqlScalarType::String.nullable(true))
11920 .with_column("object_type", SqlScalarType::String.nullable(false))
11921 .with_column("grantee", SqlScalarType::String.nullable(true))
11922 .with_column("privilege_type", SqlScalarType::String.nullable(true))
11923 .finish(),
11924 column_comments: BTreeMap::from_iter([
11925 (
11926 "object_owner",
11927 "Privileges described in this row will be granted on objects created by `object_owner`.",
11928 ),
11929 (
11930 "database",
11931 "Privileges described in this row will be granted only on objects created in `database` if non-null.",
11932 ),
11933 (
11934 "schema",
11935 "Privileges described in this row will be granted only on objects created in `schema` if non-null.",
11936 ),
11937 (
11938 "object_type",
11939 "Privileges described in this row will be granted only on objects of type `object_type`.",
11940 ),
11941 (
11942 "grantee",
11943 "Privileges described in this row will be granted to `grantee`.",
11944 ),
11945 ("privilege_type", "They type of privilege to be granted."),
11946 ]),
11947 sql: r#"SELECT
11948 CASE defaults.role_id
11949 WHEN 'p' THEN 'PUBLIC'
11950 ELSE object_owner.name
11951 END AS object_owner,
11952 databases.name AS database,
11953 schemas.name AS schema,
11954 object_type,
11955 CASE defaults.grantee
11956 WHEN 'p' THEN 'PUBLIC'
11957 ELSE grantee.name
11958 END AS grantee,
11959 unnest(mz_internal.mz_format_privileges(defaults.privileges)) AS privilege_type
11960FROM mz_catalog.mz_default_privileges defaults
11961LEFT JOIN mz_catalog.mz_roles AS object_owner ON defaults.role_id = object_owner.id
11962LEFT JOIN mz_catalog.mz_roles AS grantee ON defaults.grantee = grantee.id
11963LEFT JOIN mz_catalog.mz_databases AS databases ON defaults.database_id = databases.id
11964LEFT JOIN mz_catalog.mz_schemas AS schemas ON defaults.schema_id = schemas.id
11965WHERE defaults.grantee NOT LIKE 's%'
11966 AND defaults.database_id IS NULL OR defaults.database_id NOT LIKE 's%'
11967 AND defaults.schema_id IS NULL OR defaults.schema_id NOT LIKE 's%'"#,
11968 access: vec![PUBLIC_SELECT],
11969});
11970
11971pub static MZ_SHOW_MY_DEFAULT_PRIVILEGES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
11972 name: "mz_show_my_default_privileges",
11973 schema: MZ_INTERNAL_SCHEMA,
11974 oid: oid::VIEW_MZ_SHOW_MY_DEFAULT_PRIVILEGES_OID,
11975 desc: RelationDesc::builder()
11976 .with_column("object_owner", SqlScalarType::String.nullable(true))
11977 .with_column("database", SqlScalarType::String.nullable(true))
11978 .with_column("schema", SqlScalarType::String.nullable(true))
11979 .with_column("object_type", SqlScalarType::String.nullable(false))
11980 .with_column("grantee", SqlScalarType::String.nullable(true))
11981 .with_column("privilege_type", SqlScalarType::String.nullable(true))
11982 .finish(),
11983 column_comments: BTreeMap::from_iter([
11984 (
11985 "object_owner",
11986 "Privileges described in this row will be granted on objects created by `object_owner`.",
11987 ),
11988 (
11989 "database",
11990 "Privileges described in this row will be granted only on objects created in `database` if non-null.",
11991 ),
11992 (
11993 "schema",
11994 "Privileges described in this row will be granted only on objects created in `schema` if non-null.",
11995 ),
11996 (
11997 "object_type",
11998 "Privileges described in this row will be granted only on objects of type `object_type`.",
11999 ),
12000 (
12001 "grantee",
12002 "Privileges described in this row will be granted to `grantee`.",
12003 ),
12004 ("privilege_type", "They type of privilege to be granted."),
12005 ]),
12006 sql: r#"SELECT object_owner, database, schema, object_type, grantee, privilege_type
12007FROM mz_internal.mz_show_default_privileges
12008WHERE
12009 CASE
12010 WHEN grantee = 'PUBLIC' THEN true
12011 ELSE pg_has_role(grantee, 'USAGE')
12012 END"#,
12013 access: vec![PUBLIC_SELECT],
12014});
12015
12016pub static MZ_SHOW_NETWORK_POLICIES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12017 name: "mz_show_network_policies",
12018 schema: MZ_INTERNAL_SCHEMA,
12019 oid: oid::VIEW_MZ_SHOW_NETWORK_POLICIES_OID,
12020 desc: RelationDesc::builder()
12021 .with_column("name", SqlScalarType::String.nullable(false))
12022 .with_column("rules", SqlScalarType::String.nullable(true))
12023 .with_column("comment", SqlScalarType::String.nullable(false))
12024 .finish(),
12025 column_comments: BTreeMap::new(),
12026 sql: "
12027WITH comments AS (
12028 SELECT id, comment
12029 FROM mz_internal.mz_comments
12030 WHERE object_type = 'network-policy' AND object_sub_id IS NULL
12031)
12032SELECT
12033 policy.name,
12034 pg_catalog.string_agg(rule.name,',' ORDER BY rule.name) as rules,
12035 COALESCE(comment, '') as comment
12036FROM
12037 mz_internal.mz_network_policies as policy
12038LEFT JOIN
12039 mz_internal.mz_network_policy_rules as rule ON policy.id = rule.policy_id
12040LEFT JOIN
12041 comments ON policy.id = comments.id
12042WHERE
12043 policy.id NOT LIKE 's%'
12044AND
12045 policy.id NOT LIKE 'g%'
12046GROUP BY policy.name, comments.comment;",
12047 access: vec![PUBLIC_SELECT],
12048});
12049
12050pub static MZ_CLUSTER_REPLICA_HISTORY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12051 name: "mz_cluster_replica_history",
12052 schema: MZ_INTERNAL_SCHEMA,
12053 oid: oid::VIEW_MZ_CLUSTER_REPLICA_HISTORY_OID,
12054 desc: RelationDesc::builder()
12055 .with_column("replica_id", SqlScalarType::String.nullable(true))
12056 .with_column("size", SqlScalarType::String.nullable(true))
12057 .with_column("cluster_id", SqlScalarType::String.nullable(true))
12058 .with_column("cluster_name", SqlScalarType::String.nullable(true))
12059 .with_column("replica_name", SqlScalarType::String.nullable(true))
12060 .with_column(
12061 "created_at",
12062 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12063 )
12064 .with_column(
12065 "dropped_at",
12066 SqlScalarType::TimestampTz { precision: None }.nullable(true),
12067 )
12068 .with_column(
12069 "credits_per_hour",
12070 SqlScalarType::Numeric { max_scale: None }.nullable(true),
12071 )
12072 .finish(),
12073 column_comments: BTreeMap::from_iter([
12074 ("replica_id", "The ID of a cluster replica."),
12075 (
12076 "size",
12077 "The size of the cluster replica. Corresponds to `mz_cluster_replica_sizes.size`.",
12078 ),
12079 (
12080 "cluster_id",
12081 "The ID of the cluster associated with the replica.",
12082 ),
12083 (
12084 "cluster_name",
12085 "The name of the cluster associated with the replica.",
12086 ),
12087 ("replica_name", "The name of the replica."),
12088 ("created_at", "The time at which the replica was created."),
12089 (
12090 "dropped_at",
12091 "The time at which the replica was dropped, or `NULL` if it still exists.",
12092 ),
12093 (
12094 "credits_per_hour",
12095 "The number of compute credits consumed per hour. Corresponds to `mz_cluster_replica_sizes.credits_per_hour`.",
12096 ),
12097 ]),
12098 sql: r#"
12099 WITH
12100 creates AS
12101 (
12102 SELECT
12103 details ->> 'logical_size' AS size,
12104 details ->> 'replica_id' AS replica_id,
12105 details ->> 'replica_name' AS replica_name,
12106 details ->> 'cluster_name' AS cluster_name,
12107 details ->> 'cluster_id' AS cluster_id,
12108 occurred_at
12109 FROM mz_catalog.mz_audit_events
12110 WHERE
12111 object_type = 'cluster-replica' AND event_type = 'create'
12112 AND
12113 details ->> 'replica_id' IS NOT NULL
12114 AND
12115 details ->> 'cluster_id' !~~ 's%'
12116 ),
12117 drops AS
12118 (
12119 SELECT details ->> 'replica_id' AS replica_id, occurred_at
12120 FROM mz_catalog.mz_audit_events
12121 WHERE object_type = 'cluster-replica' AND event_type = 'drop'
12122 )
12123 SELECT
12124 creates.replica_id,
12125 creates.size,
12126 creates.cluster_id,
12127 creates.cluster_name,
12128 creates.replica_name,
12129 creates.occurred_at AS created_at,
12130 drops.occurred_at AS dropped_at,
12131 mz_cluster_replica_sizes.credits_per_hour as credits_per_hour
12132 FROM
12133 creates
12134 LEFT JOIN drops ON creates.replica_id = drops.replica_id
12135 LEFT JOIN
12136 mz_catalog.mz_cluster_replica_sizes
12137 ON mz_cluster_replica_sizes.size = creates.size"#,
12138 access: vec![PUBLIC_SELECT],
12139});
12140
12141pub static MZ_CLUSTER_REPLICA_NAME_HISTORY: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12142 name: "mz_cluster_replica_name_history",
12143 schema: MZ_INTERNAL_SCHEMA,
12144 oid: oid::VIEW_MZ_CLUSTER_REPLICA_NAME_HISTORY_OID,
12145 desc: RelationDesc::builder()
12146 .with_column(
12147 "occurred_at",
12148 SqlScalarType::TimestampTz { precision: None }.nullable(true),
12149 )
12150 .with_column("id", SqlScalarType::String.nullable(true))
12151 .with_column("previous_name", SqlScalarType::String.nullable(true))
12152 .with_column("new_name", SqlScalarType::String.nullable(true))
12153 .finish(),
12154 column_comments: BTreeMap::from_iter([
12155 (
12156 "occurred_at",
12157 "The time at which the cluster replica was created or renamed. `NULL` if it's a built in system cluster replica.",
12158 ),
12159 ("id", "The ID of the cluster replica."),
12160 (
12161 "previous_name",
12162 "The previous name of the cluster replica. `NULL` if there was no previous name.",
12163 ),
12164 ("new_name", "The new name of the cluster replica."),
12165 ]),
12166 sql: r#"WITH user_replica_alter_history AS (
12167 SELECT occurred_at,
12168 audit_events.details->>'replica_id' AS id,
12169 audit_events.details->>'old_name' AS previous_name,
12170 audit_events.details->>'new_name' AS new_name
12171 FROM mz_catalog.mz_audit_events AS audit_events
12172 WHERE object_type = 'cluster-replica'
12173 AND audit_events.event_type = 'alter'
12174 AND audit_events.details->>'replica_id' like 'u%'
12175),
12176user_replica_create_history AS (
12177 SELECT occurred_at,
12178 audit_events.details->>'replica_id' AS id,
12179 NULL AS previous_name,
12180 audit_events.details->>'replica_name' AS new_name
12181 FROM mz_catalog.mz_audit_events AS audit_events
12182 WHERE object_type = 'cluster-replica'
12183 AND audit_events.event_type = 'create'
12184 AND audit_events.details->>'replica_id' like 'u%'
12185),
12186-- Because built in system cluster replicas don't have audit events, we need to manually add them
12187system_replicas AS (
12188 -- We assume that the system cluster replicas were created at the beginning of time
12189 SELECT NULL::timestamptz AS occurred_at,
12190 id,
12191 NULL AS previous_name,
12192 name AS new_name
12193 FROM mz_catalog.mz_cluster_replicas
12194 WHERE id LIKE 's%'
12195)
12196SELECT *
12197FROM user_replica_alter_history
12198UNION ALL
12199SELECT *
12200FROM user_replica_create_history
12201UNION ALL
12202SELECT *
12203FROM system_replicas"#,
12204 access: vec![PUBLIC_SELECT],
12205});
12206
12207pub static MZ_HYDRATION_STATUSES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12208 name: "mz_hydration_statuses",
12209 schema: MZ_INTERNAL_SCHEMA,
12210 oid: oid::VIEW_MZ_HYDRATION_STATUSES_OID,
12211 desc: RelationDesc::builder()
12212 .with_column("object_id", SqlScalarType::String.nullable(false))
12213 .with_column("replica_id", SqlScalarType::String.nullable(true))
12214 .with_column("hydrated", SqlScalarType::Bool.nullable(true))
12215 .finish(),
12216 column_comments: BTreeMap::from_iter([
12217 (
12218 "object_id",
12219 "The ID of a dataflow-powered object. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, `mz_internal.mz_subscriptions`, `mz_catalog.mz_sources.id`, or `mz_catalog.mz_sinks.id`.",
12220 ),
12221 ("replica_id", "The ID of a cluster replica."),
12222 ("hydrated", "Whether the object is hydrated on the replica."),
12223 ]),
12224 sql: r#"WITH
12225-- Joining against the linearizable catalog tables ensures that this view
12226-- always contains the set of installed objects, even when it depends
12227-- on introspection relations that may received delayed updates.
12228--
12229-- Note that this view only includes objects that are maintained by dataflows.
12230-- In particular, some source types (webhook, introspection, ...) are not and
12231-- are therefore omitted.
12232indexes AS (
12233 SELECT
12234 i.id AS object_id,
12235 h.replica_id,
12236 COALESCE(h.hydrated, false) AS hydrated
12237 FROM mz_catalog.mz_indexes i
12238 LEFT JOIN mz_internal.mz_compute_hydration_statuses h
12239 ON (h.object_id = i.id)
12240),
12241materialized_views AS (
12242 SELECT
12243 i.id AS object_id,
12244 h.replica_id,
12245 COALESCE(h.hydrated, false) AS hydrated
12246 FROM mz_catalog.mz_materialized_views i
12247 LEFT JOIN mz_internal.mz_compute_hydration_statuses h
12248 ON (h.object_id = i.id)
12249),
12250continual_tasks AS (
12251 SELECT
12252 i.id AS object_id,
12253 h.replica_id,
12254 COALESCE(h.hydrated, false) AS hydrated
12255 FROM mz_internal.mz_continual_tasks i
12256 LEFT JOIN mz_internal.mz_compute_hydration_statuses h
12257 ON (h.object_id = i.id)
12258),
12259-- Hydration is a dataflow concept and not all sources are maintained by
12260-- dataflows, so we need to find the ones that are. Generally, sources that
12261-- have a cluster ID are maintained by a dataflow running on that cluster.
12262-- Webhook sources are an exception to this rule.
12263sources_with_clusters AS (
12264 SELECT id, cluster_id
12265 FROM mz_catalog.mz_sources
12266 WHERE cluster_id IS NOT NULL AND type != 'webhook'
12267),
12268sources AS (
12269 SELECT
12270 s.id AS object_id,
12271 ss.replica_id AS replica_id,
12272 ss.rehydration_latency IS NOT NULL AS hydrated
12273 FROM sources_with_clusters s
12274 LEFT JOIN mz_internal.mz_source_statistics ss USING (id)
12275),
12276-- We don't yet report sink hydration status (database-issues#8331), so we do a best effort attempt here and
12277-- define a sink as hydrated when it's both "running" and has a frontier greater than the minimum.
12278-- There is likely still a possibility of FPs.
12279sinks AS (
12280 SELECT
12281 s.id AS object_id,
12282 r.id AS replica_id,
12283 ss.status = 'running' AND COALESCE(f.write_frontier, 0) > 0 AS hydrated
12284 FROM mz_catalog.mz_sinks s
12285 LEFT JOIN mz_internal.mz_sink_statuses ss USING (id)
12286 JOIN mz_catalog.mz_cluster_replicas r
12287 ON (r.cluster_id = s.cluster_id)
12288 LEFT JOIN mz_catalog.mz_cluster_replica_frontiers f
12289 ON (f.object_id = s.id AND f.replica_id = r.id)
12290)
12291SELECT * FROM indexes
12292UNION ALL
12293SELECT * FROM materialized_views
12294UNION ALL
12295SELECT * FROM continual_tasks
12296UNION ALL
12297SELECT * FROM sources
12298UNION ALL
12299SELECT * FROM sinks"#,
12300 access: vec![PUBLIC_SELECT],
12301});
12302
12303pub const MZ_HYDRATION_STATUSES_IND: BuiltinIndex = BuiltinIndex {
12304 name: "mz_hydration_statuses_ind",
12305 schema: MZ_INTERNAL_SCHEMA,
12306 oid: oid::INDEX_MZ_HYDRATION_STATUSES_IND_OID,
12307 sql: "IN CLUSTER mz_catalog_server
12308ON mz_internal.mz_hydration_statuses (object_id, replica_id)",
12309 is_retained_metrics_object: false,
12310};
12311
12312pub static MZ_MATERIALIZATION_DEPENDENCIES: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12313 name: "mz_materialization_dependencies",
12314 schema: MZ_INTERNAL_SCHEMA,
12315 oid: oid::VIEW_MZ_MATERIALIZATION_DEPENDENCIES_OID,
12316 desc: RelationDesc::builder()
12317 .with_column("object_id", SqlScalarType::String.nullable(false))
12318 .with_column("dependency_id", SqlScalarType::String.nullable(false))
12319 .finish(),
12320 column_comments: BTreeMap::from_iter([
12321 (
12322 "object_id",
12323 "The ID of a materialization. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, or `mz_catalog.mz_sinks.id`.",
12324 ),
12325 (
12326 "dependency_id",
12327 "The ID of a dataflow dependency. Corresponds to `mz_catalog.mz_indexes.id`, `mz_catalog.mz_materialized_views.id`, `mz_catalog.mz_sources.id`, or `mz_catalog.mz_tables.id`.",
12328 ),
12329 ]),
12330 sql: "
12331SELECT object_id, dependency_id
12332FROM mz_internal.mz_compute_dependencies
12333UNION ALL
12334SELECT s.id, d.referenced_object_id AS dependency_id
12335FROM mz_internal.mz_object_dependencies d
12336JOIN mz_catalog.mz_sinks s ON (s.id = d.object_id)
12337JOIN mz_catalog.mz_relations r ON (r.id = d.referenced_object_id)",
12338 access: vec![PUBLIC_SELECT],
12339});
12340
12341pub static MZ_MATERIALIZATION_LAG: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12342 name: "mz_materialization_lag",
12343 schema: MZ_INTERNAL_SCHEMA,
12344 oid: oid::VIEW_MZ_MATERIALIZATION_LAG_OID,
12345 desc: RelationDesc::builder()
12346 .with_column("object_id", SqlScalarType::String.nullable(false))
12347 .with_column("local_lag", SqlScalarType::Interval.nullable(true))
12348 .with_column("global_lag", SqlScalarType::Interval.nullable(true))
12349 .with_column(
12350 "slowest_local_input_id",
12351 SqlScalarType::String.nullable(false),
12352 )
12353 .with_column(
12354 "slowest_global_input_id",
12355 SqlScalarType::String.nullable(false),
12356 )
12357 .finish(),
12358 column_comments: BTreeMap::from_iter([
12359 (
12360 "object_id",
12361 "The ID of the materialized view, index, or sink.",
12362 ),
12363 (
12364 "local_lag",
12365 "The amount of time the materialization lags behind its direct inputs.",
12366 ),
12367 (
12368 "global_lag",
12369 "The amount of time the materialization lags behind its root inputs (sources and tables).",
12370 ),
12371 (
12372 "slowest_local_input_id",
12373 "The ID of the slowest direct input.",
12374 ),
12375 (
12376 "slowest_global_input_id",
12377 "The ID of the slowest root input.",
12378 ),
12379 ]),
12380 sql: "
12381WITH MUTUALLY RECURSIVE
12382 -- IDs of objects for which we want to know the lag.
12383 materializations (id text) AS (
12384 SELECT id FROM mz_catalog.mz_indexes
12385 UNION ALL
12386 SELECT id FROM mz_catalog.mz_materialized_views
12387 UNION ALL
12388 SELECT id FROM mz_internal.mz_continual_tasks
12389 UNION ALL
12390 SELECT id FROM mz_catalog.mz_sinks
12391 ),
12392 -- Direct dependencies of materializations.
12393 direct_dependencies (id text, dep_id text) AS (
12394 SELECT m.id, d.dependency_id
12395 FROM materializations m
12396 JOIN mz_internal.mz_materialization_dependencies d ON (m.id = d.object_id)
12397 ),
12398 -- All transitive dependencies of materializations.
12399 transitive_dependencies (id text, dep_id text) AS (
12400 SELECT id, dep_id FROM direct_dependencies
12401 UNION
12402 SELECT td.id, dd.dep_id
12403 FROM transitive_dependencies td
12404 JOIN direct_dependencies dd ON (dd.id = td.dep_id)
12405 ),
12406 -- Root dependencies of materializations (sources and tables).
12407 root_dependencies (id text, dep_id text) AS (
12408 SELECT *
12409 FROM transitive_dependencies td
12410 WHERE NOT EXISTS (
12411 SELECT 1
12412 FROM direct_dependencies dd
12413 WHERE dd.id = td.dep_id
12414 )
12415 ),
12416 -- Write progress times of materializations.
12417 materialization_times (id text, time timestamptz) AS (
12418 SELECT m.id, to_timestamp(f.write_frontier::text::double / 1000)
12419 FROM materializations m
12420 JOIN mz_internal.mz_frontiers f ON (m.id = f.object_id)
12421 ),
12422 -- Write progress times of direct dependencies of materializations.
12423 input_times (id text, slowest_dep text, time timestamptz) AS (
12424 SELECT DISTINCT ON (d.id)
12425 d.id,
12426 d.dep_id,
12427 to_timestamp(f.write_frontier::text::double / 1000)
12428 FROM direct_dependencies d
12429 JOIN mz_internal.mz_frontiers f ON (d.dep_id = f.object_id)
12430 ORDER BY d.id, f.write_frontier ASC
12431 ),
12432 -- Write progress times of root dependencies of materializations.
12433 root_times (id text, slowest_dep text, time timestamptz) AS (
12434 SELECT DISTINCT ON (d.id)
12435 d.id,
12436 d.dep_id,
12437 to_timestamp(f.write_frontier::text::double / 1000)
12438 FROM root_dependencies d
12439 JOIN mz_internal.mz_frontiers f ON (d.dep_id = f.object_id)
12440 ORDER BY d.id, f.write_frontier ASC
12441 )
12442SELECT
12443 id AS object_id,
12444 -- Ensure that lag values are always NULL for materializations that have reached the empty
12445 -- frontier, as those have processed all their input data.
12446 -- Also make sure that lag values are never negative, even when input frontiers are before
12447 -- output frontiers (as can happen during hydration).
12448 CASE
12449 WHEN m.time IS NULL THEN INTERVAL '0'
12450 WHEN i.time IS NULL THEN NULL
12451 ELSE greatest(i.time - m.time, INTERVAL '0')
12452 END AS local_lag,
12453 CASE
12454 WHEN m.time IS NULL THEN INTERVAL '0'
12455 WHEN r.time IS NULL THEN NULL
12456 ELSE greatest(r.time - m.time, INTERVAL '0')
12457 END AS global_lag,
12458 i.slowest_dep AS slowest_local_input_id,
12459 r.slowest_dep AS slowest_global_input_id
12460FROM materialization_times m
12461JOIN input_times i USING (id)
12462JOIN root_times r USING (id)",
12463 access: vec![PUBLIC_SELECT],
12464});
12465
12466pub static MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW: LazyLock<BuiltinView> = LazyLock::new(|| {
12472 BuiltinView {
12473 name: "mz_console_cluster_utilization_overview",
12474 schema: MZ_INTERNAL_SCHEMA,
12475 oid: oid::VIEW_MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW_OID,
12476 desc: RelationDesc::builder()
12477 .with_column(
12478 "bucket_start",
12479 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12480 )
12481 .with_column("replica_id", SqlScalarType::String.nullable(false))
12482 .with_column("memory_percent", SqlScalarType::Float64.nullable(true))
12483 .with_column(
12484 "max_memory_at",
12485 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12486 )
12487 .with_column("disk_percent", SqlScalarType::Float64.nullable(true))
12488 .with_column(
12489 "max_disk_at",
12490 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12491 )
12492 .with_column(
12493 "memory_and_disk_percent",
12494 SqlScalarType::Float64.nullable(true),
12495 )
12496 .with_column(
12497 "max_memory_and_disk_memory_percent",
12498 SqlScalarType::Float64.nullable(true),
12499 )
12500 .with_column(
12501 "max_memory_and_disk_disk_percent",
12502 SqlScalarType::Float64.nullable(true),
12503 )
12504 .with_column(
12505 "max_memory_and_disk_at",
12506 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12507 )
12508 .with_column("heap_percent", SqlScalarType::Float64.nullable(true))
12509 .with_column(
12510 "max_heap_at",
12511 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12512 )
12513 .with_column("max_cpu_percent", SqlScalarType::Float64.nullable(true))
12514 .with_column(
12515 "max_cpu_at",
12516 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12517 )
12518 .with_column("offline_events", SqlScalarType::Jsonb.nullable(true))
12519 .with_column(
12520 "bucket_end",
12521 SqlScalarType::TimestampTz { precision: None }.nullable(false),
12522 )
12523 .with_column("name", SqlScalarType::String.nullable(true))
12524 .with_column("cluster_id", SqlScalarType::String.nullable(true))
12525 .with_column("size", SqlScalarType::String.nullable(true))
12526 .finish(),
12527 column_comments: BTreeMap::new(),
12528 sql: r#"WITH replica_history AS (
12529 SELECT replica_id,
12530 size,
12531 cluster_id
12532 FROM mz_internal.mz_cluster_replica_history
12533 UNION
12534 -- We need to union the current set of cluster replicas since mz_cluster_replica_history doesn't include system clusters
12535 SELECT id AS replica_id,
12536 size,
12537 cluster_id
12538 FROM mz_catalog.mz_cluster_replicas
12539),
12540replica_metrics_history AS (
12541 SELECT
12542 m.occurred_at,
12543 m.replica_id,
12544 r.size,
12545 (SUM(m.cpu_nano_cores::float8) / NULLIF(s.cpu_nano_cores, 0)) / NULLIF(s.processes, 0) AS cpu_percent,
12546 (SUM(m.memory_bytes::float8) / NULLIF(s.memory_bytes, 0)) / NULLIF(s.processes, 0) AS memory_percent,
12547 (SUM(m.disk_bytes::float8) / NULLIF(s.disk_bytes, 0)) / NULLIF(s.processes, 0) AS disk_percent,
12548 (SUM(m.heap_bytes::float8) / NULLIF(m.heap_limit, 0)) / NULLIF(s.processes, 0) AS heap_percent,
12549 SUM(m.disk_bytes::float8) AS disk_bytes,
12550 SUM(m.memory_bytes::float8) AS memory_bytes,
12551 s.disk_bytes::numeric * s.processes AS total_disk_bytes,
12552 s.memory_bytes::numeric * s.processes AS total_memory_bytes
12553 FROM
12554 replica_history AS r
12555 INNER JOIN mz_catalog.mz_cluster_replica_sizes AS s ON r.size = s.size
12556 INNER JOIN mz_internal.mz_cluster_replica_metrics_history AS m ON m.replica_id = r.replica_id
12557 GROUP BY
12558 m.occurred_at,
12559 m.replica_id,
12560 r.size,
12561 s.cpu_nano_cores,
12562 s.memory_bytes,
12563 s.disk_bytes,
12564 m.heap_limit,
12565 s.processes
12566),
12567replica_utilization_history_binned AS (
12568 SELECT m.occurred_at,
12569 m.replica_id,
12570 m.cpu_percent,
12571 m.memory_percent,
12572 m.memory_bytes,
12573 m.disk_percent,
12574 m.disk_bytes,
12575 m.heap_percent,
12576 m.total_disk_bytes,
12577 m.total_memory_bytes,
12578 m.size,
12579 date_bin(
12580 '8 HOURS',
12581 occurred_at,
12582 '1970-01-01'::timestamp
12583 ) AS bucket_start
12584 FROM replica_history AS r
12585 JOIN replica_metrics_history AS m ON m.replica_id = r.replica_id
12586 WHERE mz_now() <= date_bin(
12587 '8 HOURS',
12588 occurred_at,
12589 '1970-01-01'::timestamp
12590 ) + INTERVAL '14 DAYS'
12591),
12592-- For each (replica, bucket), take the (replica, bucket) with the highest memory
12593max_memory AS (
12594 SELECT DISTINCT ON (bucket_start, replica_id) bucket_start,
12595 replica_id,
12596 memory_percent,
12597 occurred_at
12598 FROM replica_utilization_history_binned
12599 OPTIONS (DISTINCT ON INPUT GROUP SIZE = 480)
12600 ORDER BY bucket_start,
12601 replica_id,
12602 COALESCE(memory_bytes, 0) DESC
12603),
12604max_disk AS (
12605 SELECT DISTINCT ON (bucket_start, replica_id) bucket_start,
12606 replica_id,
12607 disk_percent,
12608 occurred_at
12609 FROM replica_utilization_history_binned
12610 OPTIONS (DISTINCT ON INPUT GROUP SIZE = 480)
12611 ORDER BY bucket_start,
12612 replica_id,
12613 COALESCE(disk_bytes, 0) DESC
12614),
12615max_cpu AS (
12616 SELECT DISTINCT ON (bucket_start, replica_id) bucket_start,
12617 replica_id,
12618 cpu_percent,
12619 occurred_at
12620 FROM replica_utilization_history_binned
12621 OPTIONS (DISTINCT ON INPUT GROUP SIZE = 480)
12622 ORDER BY bucket_start,
12623 replica_id,
12624 COALESCE(cpu_percent, 0) DESC
12625),
12626/*
12627 This is different
12628 from adding max_memory
12629 and max_disk per bucket because both
12630 values may not occur at the same time if the bucket interval is large.
12631 */
12632max_memory_and_disk AS (
12633 SELECT DISTINCT ON (bucket_start, replica_id) bucket_start,
12634 replica_id,
12635 memory_percent,
12636 disk_percent,
12637 memory_and_disk_percent,
12638 occurred_at
12639 FROM (
12640 SELECT *,
12641 CASE
12642 WHEN disk_bytes IS NULL
12643 AND memory_bytes IS NULL THEN NULL
12644 ELSE (COALESCE(disk_bytes, 0) + COALESCE(memory_bytes, 0))
12645 / (total_disk_bytes::numeric + total_memory_bytes::numeric)
12646 END AS memory_and_disk_percent
12647 FROM replica_utilization_history_binned
12648 ) AS max_memory_and_disk_inner
12649 OPTIONS (DISTINCT ON INPUT GROUP SIZE = 480)
12650 ORDER BY bucket_start,
12651 replica_id,
12652 COALESCE(memory_and_disk_percent, 0) DESC
12653),
12654max_heap AS (
12655 SELECT DISTINCT ON (bucket_start, replica_id)
12656 bucket_start,
12657 replica_id,
12658 heap_percent,
12659 occurred_at
12660 FROM replica_utilization_history_binned
12661 OPTIONS (DISTINCT ON INPUT GROUP SIZE = 480)
12662 ORDER BY bucket_start, replica_id, COALESCE(heap_percent, 0) DESC
12663),
12664-- For each (replica, bucket), get its offline events at that time
12665replica_offline_event_history AS (
12666 SELECT date_bin(
12667 '8 HOURS',
12668 occurred_at,
12669 '1970-01-01'::timestamp
12670 ) AS bucket_start,
12671 replica_id,
12672 jsonb_agg(
12673 jsonb_build_object(
12674 'replicaId',
12675 rsh.replica_id,
12676 'occurredAt',
12677 rsh.occurred_at,
12678 'status',
12679 rsh.status,
12680 'reason',
12681 rsh.reason
12682 )
12683 ) AS offline_events
12684 FROM mz_internal.mz_cluster_replica_status_history AS rsh -- We assume the statuses for process 0 are the same as all processes
12685 WHERE process_id = '0'
12686 AND status = 'offline'
12687 AND mz_now() <= date_bin(
12688 '8 HOURS',
12689 occurred_at,
12690 '1970-01-01'::timestamp
12691 ) + INTERVAL '14 DAYS'
12692 GROUP BY bucket_start,
12693 replica_id
12694)
12695SELECT
12696 bucket_start,
12697 replica_id,
12698 max_memory.memory_percent,
12699 max_memory.occurred_at as max_memory_at,
12700 max_disk.disk_percent,
12701 max_disk.occurred_at as max_disk_at,
12702 max_memory_and_disk.memory_and_disk_percent as memory_and_disk_percent,
12703 max_memory_and_disk.memory_percent as max_memory_and_disk_memory_percent,
12704 max_memory_and_disk.disk_percent as max_memory_and_disk_disk_percent,
12705 max_memory_and_disk.occurred_at as max_memory_and_disk_at,
12706 max_heap.heap_percent,
12707 max_heap.occurred_at as max_heap_at,
12708 max_cpu.cpu_percent as max_cpu_percent,
12709 max_cpu.occurred_at as max_cpu_at,
12710 replica_offline_event_history.offline_events,
12711 bucket_start + INTERVAL '8 HOURS' as bucket_end,
12712 replica_name_history.new_name AS name,
12713 replica_history.cluster_id,
12714 replica_history.size
12715FROM max_memory
12716JOIN max_disk USING (bucket_start, replica_id)
12717JOIN max_cpu USING (bucket_start, replica_id)
12718JOIN max_memory_and_disk USING (bucket_start, replica_id)
12719JOIN max_heap USING (bucket_start, replica_id)
12720JOIN replica_history USING (replica_id)
12721CROSS JOIN LATERAL (
12722 SELECT new_name
12723 FROM mz_internal.mz_cluster_replica_name_history as replica_name_history
12724 WHERE replica_id = replica_name_history.id -- We treat NULLs as the beginning of time
12725 AND bucket_start + INTERVAL '8 HOURS' >= COALESCE(
12726 replica_name_history.occurred_at,
12727 '1970-01-01'::timestamp
12728 )
12729 ORDER BY replica_name_history.occurred_at DESC
12730 LIMIT '1'
12731) AS replica_name_history
12732LEFT JOIN replica_offline_event_history USING (bucket_start, replica_id)"#,
12733 access: vec![PUBLIC_SELECT],
12734 }
12735});
12736
12737pub static MZ_CLUSTER_DEPLOYMENT_LINEAGE: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
12760 name: "mz_cluster_deployment_lineage",
12761 schema: MZ_INTERNAL_SCHEMA,
12762 oid: oid::VIEW_MZ_CLUSTER_DEPLOYMENT_LINEAGE_OID,
12763 desc: RelationDesc::builder()
12764 .with_column("cluster_id", SqlScalarType::String.nullable(true))
12765 .with_column(
12766 "current_deployment_cluster_id",
12767 SqlScalarType::String.nullable(false),
12768 )
12769 .with_column("cluster_name", SqlScalarType::String.nullable(false))
12770 .with_key(vec![0, 1, 2])
12771 .finish(),
12772 column_comments: BTreeMap::from_iter([
12773 (
12774 "cluster_id",
12775 "The ID of the cluster. Corresponds to `mz_clusters.id` (though the cluster may no longer exist).",
12776 ),
12777 (
12778 "current_deployment_cluster_id",
12779 "The cluster ID of the last cluster in `cluster_id`'s blue/green lineage (the cluster is guaranteed to exist).",
12780 ),
12781 ("cluster_name", "The name of the cluster"),
12782 ]),
12783 sql: r#"WITH MUTUALLY RECURSIVE cluster_events (
12784 cluster_id text,
12785 cluster_name text,
12786 event_type text,
12787 occurred_at timestamptz
12788) AS (
12789 SELECT coalesce(details->>'id', details->>'cluster_id') AS cluster_id,
12790 coalesce(details->>'name', details->>'new_name') AS cluster_name,
12791 event_type,
12792 occurred_at
12793 FROM mz_audit_events
12794 WHERE (
12795 event_type IN ('create', 'drop')
12796 OR (
12797 event_type = 'alter'
12798 AND details ? 'new_name'
12799 )
12800 )
12801 AND object_type = 'cluster'
12802 AND mz_now() < occurred_at + INTERVAL '30 days'
12803),
12804mz_cluster_deployment_lineage (
12805 cluster_id text,
12806 current_deployment_cluster_id text,
12807 cluster_name text
12808) AS (
12809 SELECT c.id,
12810 c.id,
12811 c.name
12812 FROM mz_clusters c
12813 WHERE c.id LIKE 'u%'
12814 UNION
12815 SELECT *
12816 FROM dropped_clusters
12817),
12818-- Closest create or rename event based on the current clusters in the result set
12819most_recent_create_or_rename (
12820 cluster_id text,
12821 current_deployment_cluster_id text,
12822 cluster_name text,
12823 occurred_at timestamptz
12824) AS (
12825 SELECT DISTINCT ON (e.cluster_id) e.cluster_id,
12826 c.current_deployment_cluster_id,
12827 e.cluster_name,
12828 e.occurred_at
12829 FROM mz_cluster_deployment_lineage c
12830 JOIN cluster_events e ON c.cluster_id = e.cluster_id
12831 AND c.cluster_name = e.cluster_name
12832 WHERE e.event_type <> 'drop'
12833 ORDER BY e.cluster_id,
12834 e.occurred_at DESC
12835),
12836-- Clusters that were dropped most recently within 1 minute of most_recent_create_or_rename
12837dropped_clusters (
12838 cluster_id text,
12839 current_deployment_cluster_id text,
12840 cluster_name text
12841) AS (
12842 SELECT DISTINCT ON (cr.cluster_id) e.cluster_id,
12843 cr.current_deployment_cluster_id,
12844 cr.cluster_name
12845 FROM most_recent_create_or_rename cr
12846 JOIN cluster_events e ON e.occurred_at BETWEEN cr.occurred_at - interval '1 minute'
12847 AND cr.occurred_at + interval '1 minute'
12848 AND (
12849 e.cluster_name = cr.cluster_name
12850 OR e.cluster_name = cr.cluster_name || '_dbt_deploy'
12851 )
12852 WHERE e.event_type = 'drop'
12853 ORDER BY cr.cluster_id,
12854 abs(
12855 extract(
12856 epoch
12857 FROM cr.occurred_at - e.occurred_at
12858 )
12859 )
12860)
12861SELECT *
12862FROM mz_cluster_deployment_lineage"#,
12863 access: vec![PUBLIC_SELECT],
12864});
12865
12866pub const MZ_SHOW_DATABASES_IND: BuiltinIndex = BuiltinIndex {
12867 name: "mz_show_databases_ind",
12868 schema: MZ_INTERNAL_SCHEMA,
12869 oid: oid::INDEX_MZ_SHOW_DATABASES_IND_OID,
12870 sql: "IN CLUSTER mz_catalog_server
12871ON mz_internal.mz_show_databases (name)",
12872 is_retained_metrics_object: false,
12873};
12874
12875pub const MZ_SHOW_SCHEMAS_IND: BuiltinIndex = BuiltinIndex {
12876 name: "mz_show_schemas_ind",
12877 schema: MZ_INTERNAL_SCHEMA,
12878 oid: oid::INDEX_MZ_SHOW_SCHEMAS_IND_OID,
12879 sql: "IN CLUSTER mz_catalog_server
12880ON mz_internal.mz_show_schemas (database_id)",
12881 is_retained_metrics_object: false,
12882};
12883
12884pub const MZ_SHOW_CONNECTIONS_IND: BuiltinIndex = BuiltinIndex {
12885 name: "mz_show_connections_ind",
12886 schema: MZ_INTERNAL_SCHEMA,
12887 oid: oid::INDEX_MZ_SHOW_CONNECTIONS_IND_OID,
12888 sql: "IN CLUSTER mz_catalog_server
12889ON mz_internal.mz_show_connections (schema_id)",
12890 is_retained_metrics_object: false,
12891};
12892
12893pub const MZ_SHOW_TABLES_IND: BuiltinIndex = BuiltinIndex {
12894 name: "mz_show_tables_ind",
12895 schema: MZ_INTERNAL_SCHEMA,
12896 oid: oid::INDEX_MZ_SHOW_TABLES_IND_OID,
12897 sql: "IN CLUSTER mz_catalog_server
12898ON mz_internal.mz_show_tables (schema_id)",
12899 is_retained_metrics_object: false,
12900};
12901
12902pub const MZ_SHOW_SOURCES_IND: BuiltinIndex = BuiltinIndex {
12903 name: "mz_show_sources_ind",
12904 schema: MZ_INTERNAL_SCHEMA,
12905 oid: oid::INDEX_MZ_SHOW_SOURCES_IND_OID,
12906 sql: "IN CLUSTER mz_catalog_server
12907ON mz_internal.mz_show_sources (schema_id)",
12908 is_retained_metrics_object: false,
12909};
12910
12911pub const MZ_SHOW_VIEWS_IND: BuiltinIndex = BuiltinIndex {
12912 name: "mz_show_views_ind",
12913 schema: MZ_INTERNAL_SCHEMA,
12914 oid: oid::INDEX_MZ_SHOW_VIEWS_IND_OID,
12915 sql: "IN CLUSTER mz_catalog_server
12916ON mz_internal.mz_show_views (schema_id)",
12917 is_retained_metrics_object: false,
12918};
12919
12920pub const MZ_SHOW_MATERIALIZED_VIEWS_IND: BuiltinIndex = BuiltinIndex {
12921 name: "mz_show_materialized_views_ind",
12922 schema: MZ_INTERNAL_SCHEMA,
12923 oid: oid::INDEX_MZ_SHOW_MATERIALIZED_VIEWS_IND_OID,
12924 sql: "IN CLUSTER mz_catalog_server
12925ON mz_internal.mz_show_materialized_views (schema_id)",
12926 is_retained_metrics_object: false,
12927};
12928
12929pub const MZ_SHOW_SINKS_IND: BuiltinIndex = BuiltinIndex {
12930 name: "mz_show_sinks_ind",
12931 schema: MZ_INTERNAL_SCHEMA,
12932 oid: oid::INDEX_MZ_SHOW_SINKS_IND_OID,
12933 sql: "IN CLUSTER mz_catalog_server
12934ON mz_internal.mz_show_sinks (schema_id)",
12935 is_retained_metrics_object: false,
12936};
12937
12938pub const MZ_SHOW_TYPES_IND: BuiltinIndex = BuiltinIndex {
12939 name: "mz_show_types_ind",
12940 schema: MZ_INTERNAL_SCHEMA,
12941 oid: oid::INDEX_MZ_SHOW_TYPES_IND_OID,
12942 sql: "IN CLUSTER mz_catalog_server
12943ON mz_internal.mz_show_types (schema_id)",
12944 is_retained_metrics_object: false,
12945};
12946
12947pub const MZ_SHOW_ROLES_IND: BuiltinIndex = BuiltinIndex {
12948 name: "mz_show_roles_ind",
12949 schema: MZ_INTERNAL_SCHEMA,
12950 oid: oid::INDEX_MZ_SHOW_ROLES_IND_OID,
12951 sql: "IN CLUSTER mz_catalog_server
12952ON mz_internal.mz_show_roles (name)",
12953 is_retained_metrics_object: false,
12954};
12955
12956pub const MZ_SHOW_ALL_OBJECTS_IND: BuiltinIndex = BuiltinIndex {
12957 name: "mz_show_all_objects_ind",
12958 schema: MZ_INTERNAL_SCHEMA,
12959 oid: oid::INDEX_MZ_SHOW_ALL_OBJECTS_IND_OID,
12960 sql: "IN CLUSTER mz_catalog_server
12961ON mz_internal.mz_show_all_objects (schema_id)",
12962 is_retained_metrics_object: false,
12963};
12964
12965pub const MZ_SHOW_INDEXES_IND: BuiltinIndex = BuiltinIndex {
12966 name: "mz_show_indexes_ind",
12967 schema: MZ_INTERNAL_SCHEMA,
12968 oid: oid::INDEX_MZ_SHOW_INDEXES_IND_OID,
12969 sql: "IN CLUSTER mz_catalog_server
12970ON mz_internal.mz_show_indexes (schema_id)",
12971 is_retained_metrics_object: false,
12972};
12973
12974pub const MZ_SHOW_COLUMNS_IND: BuiltinIndex = BuiltinIndex {
12975 name: "mz_show_columns_ind",
12976 schema: MZ_INTERNAL_SCHEMA,
12977 oid: oid::INDEX_MZ_SHOW_COLUMNS_IND_OID,
12978 sql: "IN CLUSTER mz_catalog_server
12979ON mz_internal.mz_show_columns (id)",
12980 is_retained_metrics_object: false,
12981};
12982
12983pub const MZ_SHOW_CLUSTERS_IND: BuiltinIndex = BuiltinIndex {
12984 name: "mz_show_clusters_ind",
12985 schema: MZ_INTERNAL_SCHEMA,
12986 oid: oid::INDEX_MZ_SHOW_CLUSTERS_IND_OID,
12987 sql: "IN CLUSTER mz_catalog_server
12988ON mz_internal.mz_show_clusters (name)",
12989 is_retained_metrics_object: false,
12990};
12991
12992pub const MZ_SHOW_CLUSTER_REPLICAS_IND: BuiltinIndex = BuiltinIndex {
12993 name: "mz_show_cluster_replicas_ind",
12994 schema: MZ_INTERNAL_SCHEMA,
12995 oid: oid::INDEX_MZ_SHOW_CLUSTER_REPLICAS_IND_OID,
12996 sql: "IN CLUSTER mz_catalog_server
12997ON mz_internal.mz_show_cluster_replicas (cluster)",
12998 is_retained_metrics_object: false,
12999};
13000
13001pub const MZ_SHOW_SECRETS_IND: BuiltinIndex = BuiltinIndex {
13002 name: "mz_show_secrets_ind",
13003 schema: MZ_INTERNAL_SCHEMA,
13004 oid: oid::INDEX_MZ_SHOW_SECRETS_IND_OID,
13005 sql: "IN CLUSTER mz_catalog_server
13006ON mz_internal.mz_show_secrets (schema_id)",
13007 is_retained_metrics_object: false,
13008};
13009
13010pub const MZ_DATABASES_IND: BuiltinIndex = BuiltinIndex {
13011 name: "mz_databases_ind",
13012 schema: MZ_CATALOG_SCHEMA,
13013 oid: oid::INDEX_MZ_DATABASES_IND_OID,
13014 sql: "IN CLUSTER mz_catalog_server
13015ON mz_catalog.mz_databases (name)",
13016 is_retained_metrics_object: false,
13017};
13018
13019pub const MZ_SCHEMAS_IND: BuiltinIndex = BuiltinIndex {
13020 name: "mz_schemas_ind",
13021 schema: MZ_CATALOG_SCHEMA,
13022 oid: oid::INDEX_MZ_SCHEMAS_IND_OID,
13023 sql: "IN CLUSTER mz_catalog_server
13024ON mz_catalog.mz_schemas (database_id)",
13025 is_retained_metrics_object: false,
13026};
13027
13028pub const MZ_CONNECTIONS_IND: BuiltinIndex = BuiltinIndex {
13029 name: "mz_connections_ind",
13030 schema: MZ_CATALOG_SCHEMA,
13031 oid: oid::INDEX_MZ_CONNECTIONS_IND_OID,
13032 sql: "IN CLUSTER mz_catalog_server
13033ON mz_catalog.mz_connections (schema_id)",
13034 is_retained_metrics_object: false,
13035};
13036
13037pub const MZ_TABLES_IND: BuiltinIndex = BuiltinIndex {
13038 name: "mz_tables_ind",
13039 schema: MZ_CATALOG_SCHEMA,
13040 oid: oid::INDEX_MZ_TABLES_IND_OID,
13041 sql: "IN CLUSTER mz_catalog_server
13042ON mz_catalog.mz_tables (schema_id)",
13043 is_retained_metrics_object: false,
13044};
13045
13046pub const MZ_TYPES_IND: BuiltinIndex = BuiltinIndex {
13047 name: "mz_types_ind",
13048 schema: MZ_CATALOG_SCHEMA,
13049 oid: oid::INDEX_MZ_TYPES_IND_OID,
13050 sql: "IN CLUSTER mz_catalog_server
13051ON mz_catalog.mz_types (schema_id)",
13052 is_retained_metrics_object: false,
13053};
13054
13055pub const MZ_OBJECTS_IND: BuiltinIndex = BuiltinIndex {
13056 name: "mz_objects_ind",
13057 schema: MZ_CATALOG_SCHEMA,
13058 oid: oid::INDEX_MZ_OBJECTS_IND_OID,
13059 sql: "IN CLUSTER mz_catalog_server
13060ON mz_catalog.mz_objects (schema_id)",
13061 is_retained_metrics_object: false,
13062};
13063
13064pub const MZ_COLUMNS_IND: BuiltinIndex = BuiltinIndex {
13065 name: "mz_columns_ind",
13066 schema: MZ_CATALOG_SCHEMA,
13067 oid: oid::INDEX_MZ_COLUMNS_IND_OID,
13068 sql: "IN CLUSTER mz_catalog_server
13069ON mz_catalog.mz_columns (name)",
13070 is_retained_metrics_object: false,
13071};
13072
13073pub const MZ_SECRETS_IND: BuiltinIndex = BuiltinIndex {
13074 name: "mz_secrets_ind",
13075 schema: MZ_CATALOG_SCHEMA,
13076 oid: oid::INDEX_MZ_SECRETS_IND_OID,
13077 sql: "IN CLUSTER mz_catalog_server
13078ON mz_catalog.mz_secrets (name)",
13079 is_retained_metrics_object: false,
13080};
13081
13082pub const MZ_VIEWS_IND: BuiltinIndex = BuiltinIndex {
13083 name: "mz_views_ind",
13084 schema: MZ_CATALOG_SCHEMA,
13085 oid: oid::INDEX_MZ_VIEWS_IND_OID,
13086 sql: "IN CLUSTER mz_catalog_server
13087ON mz_catalog.mz_views (schema_id)",
13088 is_retained_metrics_object: false,
13089};
13090
13091pub const MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW_IND: BuiltinIndex = BuiltinIndex {
13092 name: "mz_console_cluster_utilization_overview_ind",
13093 schema: MZ_INTERNAL_SCHEMA,
13094 oid: oid::INDEX_MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW_IND_OID,
13095 sql: "IN CLUSTER mz_catalog_server
13096ON mz_internal.mz_console_cluster_utilization_overview (cluster_id)",
13097 is_retained_metrics_object: false,
13098};
13099
13100pub const MZ_CLUSTER_DEPLOYMENT_LINEAGE_IND: BuiltinIndex = BuiltinIndex {
13101 name: "mz_cluster_deployment_lineage_ind",
13102 schema: MZ_INTERNAL_SCHEMA,
13103 oid: oid::INDEX_MZ_CLUSTER_DEPLOYMENT_LINEAGE_IND_OID,
13104 sql: "IN CLUSTER mz_catalog_server
13105ON mz_internal.mz_cluster_deployment_lineage (cluster_id)",
13106 is_retained_metrics_object: false,
13107};
13108
13109pub const MZ_CLUSTERS_IND: BuiltinIndex = BuiltinIndex {
13110 name: "mz_clusters_ind",
13111 schema: MZ_CATALOG_SCHEMA,
13112 oid: oid::INDEX_MZ_CLUSTERS_IND_OID,
13113 sql: "IN CLUSTER mz_catalog_server
13114ON mz_catalog.mz_clusters (id)",
13115 is_retained_metrics_object: false,
13116};
13117
13118pub const MZ_INDEXES_IND: BuiltinIndex = BuiltinIndex {
13119 name: "mz_indexes_ind",
13120 schema: MZ_CATALOG_SCHEMA,
13121 oid: oid::INDEX_MZ_INDEXES_IND_OID,
13122 sql: "IN CLUSTER mz_catalog_server
13123ON mz_catalog.mz_indexes (id)",
13124 is_retained_metrics_object: false,
13125};
13126
13127pub const MZ_ROLES_IND: BuiltinIndex = BuiltinIndex {
13128 name: "mz_roles_ind",
13129 schema: MZ_CATALOG_SCHEMA,
13130 oid: oid::INDEX_MZ_ROLES_IND_OID,
13131 sql: "IN CLUSTER mz_catalog_server
13132ON mz_catalog.mz_roles (id)",
13133 is_retained_metrics_object: false,
13134};
13135
13136pub const MZ_SOURCES_IND: BuiltinIndex = BuiltinIndex {
13137 name: "mz_sources_ind",
13138 schema: MZ_CATALOG_SCHEMA,
13139 oid: oid::INDEX_MZ_SOURCES_IND_OID,
13140 sql: "IN CLUSTER mz_catalog_server
13141ON mz_catalog.mz_sources (id)",
13142 is_retained_metrics_object: true,
13143};
13144
13145pub const MZ_SINKS_IND: BuiltinIndex = BuiltinIndex {
13146 name: "mz_sinks_ind",
13147 schema: MZ_CATALOG_SCHEMA,
13148 oid: oid::INDEX_MZ_SINKS_IND_OID,
13149 sql: "IN CLUSTER mz_catalog_server
13150ON mz_catalog.mz_sinks (id)",
13151 is_retained_metrics_object: true,
13152};
13153
13154pub const MZ_MATERIALIZED_VIEWS_IND: BuiltinIndex = BuiltinIndex {
13155 name: "mz_materialized_views_ind",
13156 schema: MZ_CATALOG_SCHEMA,
13157 oid: oid::INDEX_MZ_MATERIALIZED_VIEWS_IND_OID,
13158 sql: "IN CLUSTER mz_catalog_server
13159ON mz_catalog.mz_materialized_views (id)",
13160 is_retained_metrics_object: false,
13161};
13162
13163pub const MZ_CONTINUAL_TASKS_IND: BuiltinIndex = BuiltinIndex {
13164 name: "mz_continual_tasks_ind",
13165 schema: MZ_INTERNAL_SCHEMA,
13166 oid: oid::INDEX_MZ_CONTINUAL_TASKS_IND_OID,
13167 sql: "IN CLUSTER mz_catalog_server
13168ON mz_internal.mz_continual_tasks (id)",
13169 is_retained_metrics_object: false,
13170};
13171
13172pub const MZ_SOURCE_STATUSES_IND: BuiltinIndex = BuiltinIndex {
13173 name: "mz_source_statuses_ind",
13174 schema: MZ_INTERNAL_SCHEMA,
13175 oid: oid::INDEX_MZ_SOURCE_STATUSES_IND_OID,
13176 sql: "IN CLUSTER mz_catalog_server
13177ON mz_internal.mz_source_statuses (id)",
13178 is_retained_metrics_object: false,
13179};
13180
13181pub const MZ_SINK_STATUSES_IND: BuiltinIndex = BuiltinIndex {
13182 name: "mz_sink_statuses_ind",
13183 schema: MZ_INTERNAL_SCHEMA,
13184 oid: oid::INDEX_MZ_SINK_STATUSES_IND_OID,
13185 sql: "IN CLUSTER mz_catalog_server
13186ON mz_internal.mz_sink_statuses (id)",
13187 is_retained_metrics_object: false,
13188};
13189
13190pub const MZ_SOURCE_STATUS_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13191 name: "mz_source_status_history_ind",
13192 schema: MZ_INTERNAL_SCHEMA,
13193 oid: oid::INDEX_MZ_SOURCE_STATUS_HISTORY_IND_OID,
13194 sql: "IN CLUSTER mz_catalog_server
13195ON mz_internal.mz_source_status_history (source_id)",
13196 is_retained_metrics_object: false,
13197};
13198
13199pub const MZ_SINK_STATUS_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13200 name: "mz_sink_status_history_ind",
13201 schema: MZ_INTERNAL_SCHEMA,
13202 oid: oid::INDEX_MZ_SINK_STATUS_HISTORY_IND_OID,
13203 sql: "IN CLUSTER mz_catalog_server
13204ON mz_internal.mz_sink_status_history (sink_id)",
13205 is_retained_metrics_object: false,
13206};
13207
13208pub const MZ_SHOW_CONTINUAL_TASKS_IND: BuiltinIndex = BuiltinIndex {
13209 name: "mz_show_continual_tasks_ind",
13210 schema: MZ_INTERNAL_SCHEMA,
13211 oid: oid::INDEX_MZ_SHOW_CONTINUAL_TASKS_OID,
13212 sql: "IN CLUSTER mz_catalog_server
13213ON mz_internal.mz_show_continual_tasks (id)",
13214 is_retained_metrics_object: false,
13215};
13216
13217pub static MZ_SOURCE_STATISTICS_WITH_HISTORY: LazyLock<BuiltinView> =
13230 LazyLock::new(|| BuiltinView {
13231 name: "mz_source_statistics_with_history",
13232 schema: MZ_INTERNAL_SCHEMA,
13233 oid: oid::VIEW_MZ_SOURCE_STATISTICS_WITH_HISTORY_OID,
13234 desc: RelationDesc::builder()
13235 .with_column("id", SqlScalarType::String.nullable(false))
13236 .with_column("replica_id", SqlScalarType::String.nullable(true))
13237 .with_column("messages_received", SqlScalarType::UInt64.nullable(false))
13238 .with_column("bytes_received", SqlScalarType::UInt64.nullable(false))
13239 .with_column("updates_staged", SqlScalarType::UInt64.nullable(false))
13240 .with_column("updates_committed", SqlScalarType::UInt64.nullable(false))
13241 .with_column("records_indexed", SqlScalarType::UInt64.nullable(false))
13242 .with_column("bytes_indexed", SqlScalarType::UInt64.nullable(false))
13243 .with_column(
13244 "rehydration_latency",
13245 SqlScalarType::Interval.nullable(true),
13246 )
13247 .with_column(
13248 "snapshot_records_known",
13249 SqlScalarType::UInt64.nullable(true),
13250 )
13251 .with_column(
13252 "snapshot_records_staged",
13253 SqlScalarType::UInt64.nullable(true),
13254 )
13255 .with_column("snapshot_committed", SqlScalarType::Bool.nullable(false))
13256 .with_column("offset_known", SqlScalarType::UInt64.nullable(true))
13257 .with_column("offset_committed", SqlScalarType::UInt64.nullable(true))
13258 .with_key(vec![0, 1])
13259 .finish(),
13260 column_comments: BTreeMap::new(),
13261 sql: "
13262WITH
13263 -- For each subsource, statistics are reported as its parent source
13264 subsource_to_parent AS
13265 (
13266 SELECT subsource.id AS id, parent.id AS report_id
13267 FROM mz_catalog.mz_sources AS subsource
13268 JOIN mz_internal.mz_object_dependencies AS dep ON subsource.id = dep.object_id
13269 JOIN mz_catalog.mz_sources AS parent ON parent.id = dep.referenced_object_id
13270 WHERE subsource.type = 'subsource'
13271 ),
13272 -- For each table from source, statistics are reported as its parent source
13273 table_to_parent AS
13274 (
13275 SELECT id, source_id AS report_id
13276 FROM mz_catalog.mz_tables
13277 WHERE source_id IS NOT NULL
13278 ),
13279 -- For each source and subsource, statistics are reported as itself
13280 source_refl AS
13281 (
13282 SELECT id, id AS report_id
13283 FROM mz_catalog.mz_sources
13284 WHERE type NOT IN ('progress', 'log')
13285 ),
13286 -- For each table from source, statistics are reported as itself
13287 table_refl AS
13288 (
13289 SELECT id, id AS report_id
13290 FROM mz_catalog.mz_tables
13291 WHERE source_id IS NOT NULL
13292 ),
13293 report_paths AS
13294 (
13295 SELECT id, report_id FROM subsource_to_parent
13296 UNION ALL SELECT id, report_id FROM table_to_parent
13297 UNION ALL SELECT id, report_id FROM source_refl
13298 UNION ALL SELECT id, report_id FROM table_refl
13299 )
13300SELECT
13301 report_paths.report_id AS id,
13302 replica_id,
13303 -- Counters
13304 SUM(messages_received)::uint8 AS messages_received,
13305 SUM(bytes_received)::uint8 AS bytes_received,
13306 SUM(updates_staged)::uint8 AS updates_staged,
13307 SUM(updates_committed)::uint8 AS updates_committed,
13308 -- Resetting Gauges
13309 SUM(records_indexed)::uint8 AS records_indexed,
13310 SUM(bytes_indexed)::uint8 AS bytes_indexed,
13311 -- Ensure we aggregate to NULL when not all workers are done rehydrating.
13312 CASE
13313 WHEN bool_or(rehydration_latency IS NULL) THEN NULL
13314 ELSE MAX(rehydration_latency)::interval
13315 END AS rehydration_latency,
13316 SUM(snapshot_records_known)::uint8 AS snapshot_records_known,
13317 SUM(snapshot_records_staged)::uint8 AS snapshot_records_staged,
13318 bool_and(snapshot_committed) as snapshot_committed,
13319 -- Gauges
13320 MAX(offset_known)::uint8 AS offset_known,
13321 MIN(offset_committed)::uint8 AS offset_committed
13322FROM mz_internal.mz_source_statistics_raw
13323 JOIN report_paths USING (id)
13324GROUP BY report_paths.report_id, replica_id",
13325 access: vec![PUBLIC_SELECT],
13326 });
13327
13328pub const MZ_SOURCE_STATISTICS_WITH_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13329 name: "mz_source_statistics_with_history_ind",
13330 schema: MZ_INTERNAL_SCHEMA,
13331 oid: oid::INDEX_MZ_SOURCE_STATISTICS_WITH_HISTORY_IND_OID,
13332 sql: "IN CLUSTER mz_catalog_server
13333ON mz_internal.mz_source_statistics_with_history (id, replica_id)",
13334 is_retained_metrics_object: true,
13335};
13336
13337pub static MZ_SOURCE_STATISTICS: LazyLock<BuiltinView> = LazyLock::new(|| {
13340 BuiltinView {
13341 name: "mz_source_statistics",
13342 schema: MZ_INTERNAL_SCHEMA,
13343 oid: oid::VIEW_MZ_SOURCE_STATISTICS_OID,
13344 desc: RelationDesc::builder()
13346 .with_column("id", SqlScalarType::String.nullable(false))
13347 .with_column("replica_id", SqlScalarType::String.nullable(true))
13348 .with_column("messages_received", SqlScalarType::UInt64.nullable(false))
13349 .with_column("bytes_received", SqlScalarType::UInt64.nullable(false))
13350 .with_column("updates_staged", SqlScalarType::UInt64.nullable(false))
13351 .with_column("updates_committed", SqlScalarType::UInt64.nullable(false))
13352 .with_column("records_indexed", SqlScalarType::UInt64.nullable(false))
13353 .with_column("bytes_indexed", SqlScalarType::UInt64.nullable(false))
13354 .with_column(
13355 "rehydration_latency",
13356 SqlScalarType::Interval.nullable(true),
13357 )
13358 .with_column(
13359 "snapshot_records_known",
13360 SqlScalarType::UInt64.nullable(true),
13361 )
13362 .with_column(
13363 "snapshot_records_staged",
13364 SqlScalarType::UInt64.nullable(true),
13365 )
13366 .with_column("snapshot_committed", SqlScalarType::Bool.nullable(false))
13367 .with_column("offset_known", SqlScalarType::UInt64.nullable(true))
13368 .with_column("offset_committed", SqlScalarType::UInt64.nullable(true))
13369 .with_key(vec![0, 1])
13370 .finish(),
13371 column_comments: BTreeMap::from_iter([
13372 (
13373 "id",
13374 "The ID of the source. Corresponds to `mz_catalog.mz_sources.id`.",
13375 ),
13376 (
13377 "replica_id",
13378 "The ID of a replica running the source. Corresponds to `mz_catalog.mz_cluster_replicas.id`.",
13379 ),
13380 (
13381 "messages_received",
13382 "The number of messages the source has received from the external system. Messages are counted in a source type-specific manner. Messages do not correspond directly to updates: some messages produce multiple updates, while other messages may be coalesced into a single update.",
13383 ),
13384 (
13385 "bytes_received",
13386 "The number of bytes the source has read from the external system. Bytes are counted in a source type-specific manner and may or may not include protocol overhead.",
13387 ),
13388 (
13389 "updates_staged",
13390 "The number of updates (insertions plus deletions) the source has written but not yet committed to the storage layer.",
13391 ),
13392 (
13393 "updates_committed",
13394 "The number of updates (insertions plus deletions) the source has committed to the storage layer.",
13395 ),
13396 (
13397 "records_indexed",
13398 "The number of individual records indexed in the source envelope state.",
13399 ),
13400 (
13401 "bytes_indexed",
13402 "The number of bytes stored in the source's internal index, if any.",
13403 ),
13404 (
13405 "rehydration_latency",
13406 "The amount of time it took for the source to rehydrate its internal index, if any, after the source last restarted.",
13407 ),
13408 (
13409 "snapshot_records_known",
13410 "The size of the source's snapshot, measured in number of records. See below to learn what constitutes a record.",
13411 ),
13412 (
13413 "snapshot_records_staged",
13414 "The number of records in the source's snapshot that Materialize has read. See below to learn what constitutes a record.",
13415 ),
13416 (
13417 "snapshot_committed",
13418 "Whether the source has committed the initial snapshot for a source.",
13419 ),
13420 (
13421 "offset_known",
13422 "The offset of the most recent data in the source's upstream service that Materialize knows about. See below to learn what constitutes an offset.",
13423 ),
13424 (
13425 "offset_committed",
13426 "The offset of the the data that Materialize has durably ingested. See below to learn what constitutes an offset.",
13427 ),
13428 ]),
13429 sql: "SELECT * FROM mz_internal.mz_source_statistics_with_history WHERE length(id) > 0",
13430 access: vec![PUBLIC_SELECT],
13431 }
13432});
13433
13434pub const MZ_SOURCE_STATISTICS_IND: BuiltinIndex = BuiltinIndex {
13435 name: "mz_source_statistics_ind",
13436 schema: MZ_INTERNAL_SCHEMA,
13437 oid: oid::INDEX_MZ_SOURCE_STATISTICS_IND_OID,
13438 sql: "IN CLUSTER mz_catalog_server
13439ON mz_internal.mz_source_statistics (id, replica_id)",
13440 is_retained_metrics_object: false,
13441};
13442
13443pub static MZ_SINK_STATISTICS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
13444 name: "mz_sink_statistics",
13445 schema: MZ_INTERNAL_SCHEMA,
13446 oid: oid::VIEW_MZ_SINK_STATISTICS_OID,
13447 desc: RelationDesc::builder()
13448 .with_column("id", SqlScalarType::String.nullable(false))
13449 .with_column("replica_id", SqlScalarType::String.nullable(true))
13450 .with_column("messages_staged", SqlScalarType::UInt64.nullable(false))
13451 .with_column("messages_committed", SqlScalarType::UInt64.nullable(false))
13452 .with_column("bytes_staged", SqlScalarType::UInt64.nullable(false))
13453 .with_column("bytes_committed", SqlScalarType::UInt64.nullable(false))
13454 .with_key(vec![0, 1])
13455 .finish(),
13456 column_comments: BTreeMap::from_iter([
13457 (
13458 "id",
13459 "The ID of the sink. Corresponds to `mz_catalog.mz_sinks.id`.",
13460 ),
13461 (
13462 "replica_id",
13463 "The ID of a replica running the sink. Corresponds to `mz_catalog.mz_cluster_replicas.id`.",
13464 ),
13465 (
13466 "messages_staged",
13467 "The number of messages staged but possibly not committed to the sink.",
13468 ),
13469 (
13470 "messages_committed",
13471 "The number of messages committed to the sink.",
13472 ),
13473 (
13474 "bytes_staged",
13475 "The number of bytes staged but possibly not committed to the sink. This counts both keys and values, if applicable.",
13476 ),
13477 (
13478 "bytes_committed",
13479 "The number of bytes committed to the sink. This counts both keys and values, if applicable.",
13480 ),
13481 ]),
13482 sql: "
13483SELECT
13484 id,
13485 replica_id,
13486 SUM(messages_staged)::uint8 AS messages_staged,
13487 SUM(messages_committed)::uint8 AS messages_committed,
13488 SUM(bytes_staged)::uint8 AS bytes_staged,
13489 SUM(bytes_committed)::uint8 AS bytes_committed
13490FROM mz_internal.mz_sink_statistics_raw
13491GROUP BY id, replica_id",
13492 access: vec![PUBLIC_SELECT],
13493});
13494
13495pub const MZ_SINK_STATISTICS_IND: BuiltinIndex = BuiltinIndex {
13496 name: "mz_sink_statistics_ind",
13497 schema: MZ_INTERNAL_SCHEMA,
13498 oid: oid::INDEX_MZ_SINK_STATISTICS_IND_OID,
13499 sql: "IN CLUSTER mz_catalog_server
13500ON mz_internal.mz_sink_statistics (id, replica_id)",
13501 is_retained_metrics_object: true,
13502};
13503
13504pub const MZ_CLUSTER_REPLICAS_IND: BuiltinIndex = BuiltinIndex {
13505 name: "mz_cluster_replicas_ind",
13506 schema: MZ_CATALOG_SCHEMA,
13507 oid: oid::INDEX_MZ_CLUSTER_REPLICAS_IND_OID,
13508 sql: "IN CLUSTER mz_catalog_server
13509ON mz_catalog.mz_cluster_replicas (id)",
13510 is_retained_metrics_object: true,
13511};
13512
13513pub const MZ_CLUSTER_REPLICA_SIZES_IND: BuiltinIndex = BuiltinIndex {
13514 name: "mz_cluster_replica_sizes_ind",
13515 schema: MZ_CATALOG_SCHEMA,
13516 oid: oid::INDEX_MZ_CLUSTER_REPLICA_SIZES_IND_OID,
13517 sql: "IN CLUSTER mz_catalog_server
13518ON mz_catalog.mz_cluster_replica_sizes (size)",
13519 is_retained_metrics_object: true,
13520};
13521
13522pub const MZ_CLUSTER_REPLICA_STATUSES_IND: BuiltinIndex = BuiltinIndex {
13523 name: "mz_cluster_replica_statuses_ind",
13524 schema: MZ_INTERNAL_SCHEMA,
13525 oid: oid::INDEX_MZ_CLUSTER_REPLICA_STATUSES_IND_OID,
13526 sql: "IN CLUSTER mz_catalog_server
13527ON mz_internal.mz_cluster_replica_statuses (replica_id)",
13528 is_retained_metrics_object: false,
13529};
13530
13531pub const MZ_CLUSTER_REPLICA_STATUS_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13532 name: "mz_cluster_replica_status_history_ind",
13533 schema: MZ_INTERNAL_SCHEMA,
13534 oid: oid::INDEX_MZ_CLUSTER_REPLICA_STATUS_HISTORY_IND_OID,
13535 sql: "IN CLUSTER mz_catalog_server
13536ON mz_internal.mz_cluster_replica_status_history (replica_id)",
13537 is_retained_metrics_object: false,
13538};
13539
13540pub const MZ_CLUSTER_REPLICA_METRICS_IND: BuiltinIndex = BuiltinIndex {
13541 name: "mz_cluster_replica_metrics_ind",
13542 schema: MZ_INTERNAL_SCHEMA,
13543 oid: oid::INDEX_MZ_CLUSTER_REPLICA_METRICS_IND_OID,
13544 sql: "IN CLUSTER mz_catalog_server
13545ON mz_internal.mz_cluster_replica_metrics (replica_id)",
13546 is_retained_metrics_object: false,
13547};
13548
13549pub const MZ_CLUSTER_REPLICA_METRICS_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13550 name: "mz_cluster_replica_metrics_history_ind",
13551 schema: MZ_INTERNAL_SCHEMA,
13552 oid: oid::INDEX_MZ_CLUSTER_REPLICA_METRICS_HISTORY_IND_OID,
13553 sql: "IN CLUSTER mz_catalog_server
13554ON mz_internal.mz_cluster_replica_metrics_history (replica_id)",
13555 is_retained_metrics_object: false,
13556};
13557
13558pub const MZ_CLUSTER_REPLICA_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13559 name: "mz_cluster_replica_history_ind",
13560 schema: MZ_INTERNAL_SCHEMA,
13561 oid: oid::INDEX_MZ_CLUSTER_REPLICA_HISTORY_IND_OID,
13562 sql: "IN CLUSTER mz_catalog_server
13563ON mz_internal.mz_cluster_replica_history (dropped_at)",
13564 is_retained_metrics_object: true,
13565};
13566
13567pub const MZ_CLUSTER_REPLICA_NAME_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13568 name: "mz_cluster_replica_name_history_ind",
13569 schema: MZ_INTERNAL_SCHEMA,
13570 oid: oid::INDEX_MZ_CLUSTER_REPLICA_NAME_HISTORY_IND_OID,
13571 sql: "IN CLUSTER mz_catalog_server
13572ON mz_internal.mz_cluster_replica_name_history (id)",
13573 is_retained_metrics_object: false,
13574};
13575
13576pub const MZ_OBJECT_LIFETIMES_IND: BuiltinIndex = BuiltinIndex {
13577 name: "mz_object_lifetimes_ind",
13578 schema: MZ_INTERNAL_SCHEMA,
13579 oid: oid::INDEX_MZ_OBJECT_LIFETIMES_IND_OID,
13580 sql: "IN CLUSTER mz_catalog_server
13581ON mz_internal.mz_object_lifetimes (id)",
13582 is_retained_metrics_object: false,
13583};
13584
13585pub const MZ_OBJECT_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13586 name: "mz_object_history_ind",
13587 schema: MZ_INTERNAL_SCHEMA,
13588 oid: oid::INDEX_MZ_OBJECT_HISTORY_IND_OID,
13589 sql: "IN CLUSTER mz_catalog_server
13590ON mz_internal.mz_object_history (id)",
13591 is_retained_metrics_object: false,
13592};
13593
13594pub const MZ_OBJECT_DEPENDENCIES_IND: BuiltinIndex = BuiltinIndex {
13595 name: "mz_object_dependencies_ind",
13596 schema: MZ_INTERNAL_SCHEMA,
13597 oid: oid::INDEX_MZ_OBJECT_DEPENDENCIES_IND_OID,
13598 sql: "IN CLUSTER mz_catalog_server
13599ON mz_internal.mz_object_dependencies (object_id)",
13600 is_retained_metrics_object: true,
13601};
13602
13603pub const MZ_COMPUTE_DEPENDENCIES_IND: BuiltinIndex = BuiltinIndex {
13604 name: "mz_compute_dependencies_ind",
13605 schema: MZ_INTERNAL_SCHEMA,
13606 oid: oid::INDEX_MZ_COMPUTE_DEPENDENCIES_IND_OID,
13607 sql: "IN CLUSTER mz_catalog_server
13608ON mz_internal.mz_compute_dependencies (dependency_id)",
13609 is_retained_metrics_object: false,
13610};
13611
13612pub const MZ_OBJECT_TRANSITIVE_DEPENDENCIES_IND: BuiltinIndex = BuiltinIndex {
13613 name: "mz_object_transitive_dependencies_ind",
13614 schema: MZ_INTERNAL_SCHEMA,
13615 oid: oid::INDEX_MZ_OBJECT_TRANSITIVE_DEPENDENCIES_IND_OID,
13616 sql: "IN CLUSTER mz_catalog_server
13617ON mz_internal.mz_object_transitive_dependencies (object_id)",
13618 is_retained_metrics_object: false,
13619};
13620
13621pub const MZ_FRONTIERS_IND: BuiltinIndex = BuiltinIndex {
13622 name: "mz_frontiers_ind",
13623 schema: MZ_INTERNAL_SCHEMA,
13624 oid: oid::INDEX_MZ_FRONTIERS_IND_OID,
13625 sql: "IN CLUSTER mz_catalog_server
13626ON mz_internal.mz_frontiers (object_id)",
13627 is_retained_metrics_object: false,
13628};
13629
13630pub const MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY_IND: BuiltinIndex = BuiltinIndex {
13631 name: "mz_wallclock_global_lag_recent_history_ind",
13632 schema: MZ_INTERNAL_SCHEMA,
13633 oid: oid::INDEX_MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY_IND_OID,
13634 sql: "IN CLUSTER mz_catalog_server
13635ON mz_internal.mz_wallclock_global_lag_recent_history (object_id)",
13636 is_retained_metrics_object: false,
13637};
13638
13639pub const MZ_RECENT_ACTIVITY_LOG_THINNED_IND: BuiltinIndex = BuiltinIndex {
13640 name: "mz_recent_activity_log_thinned_ind",
13641 schema: MZ_INTERNAL_SCHEMA,
13642 oid: oid::INDEX_MZ_RECENT_ACTIVITY_LOG_THINNED_IND_OID,
13643 sql: "IN CLUSTER mz_catalog_server
13644-- sql_hash because we plan to join
13645-- this against mz_internal.mz_sql_text
13646ON mz_internal.mz_recent_activity_log_thinned (sql_hash)",
13647 is_retained_metrics_object: false,
13648};
13649
13650pub const MZ_KAFKA_SOURCES_IND: BuiltinIndex = BuiltinIndex {
13651 name: "mz_kafka_sources_ind",
13652 schema: MZ_CATALOG_SCHEMA,
13653 oid: oid::INDEX_MZ_KAFKA_SOURCES_IND_OID,
13654 sql: "IN CLUSTER mz_catalog_server
13655ON mz_catalog.mz_kafka_sources (id)",
13656 is_retained_metrics_object: true,
13657};
13658
13659pub const MZ_WEBHOOK_SOURCES_IND: BuiltinIndex = BuiltinIndex {
13660 name: "mz_webhook_sources_ind",
13661 schema: MZ_INTERNAL_SCHEMA,
13662 oid: oid::INDEX_MZ_WEBHOOK_SOURCES_IND_OID,
13663 sql: "IN CLUSTER mz_catalog_server
13664ON mz_internal.mz_webhook_sources (id)",
13665 is_retained_metrics_object: true,
13666};
13667
13668pub const MZ_COMMENTS_IND: BuiltinIndex = BuiltinIndex {
13669 name: "mz_comments_ind",
13670 schema: MZ_INTERNAL_SCHEMA,
13671 oid: oid::INDEX_MZ_COMMENTS_IND_OID,
13672 sql: "IN CLUSTER mz_catalog_server
13673ON mz_internal.mz_comments (id)",
13674 is_retained_metrics_object: true,
13675};
13676
13677pub static MZ_ANALYTICS: BuiltinConnection = BuiltinConnection {
13678 name: "mz_analytics",
13679 schema: MZ_INTERNAL_SCHEMA,
13680 oid: oid::CONNECTION_MZ_ANALYTICS_OID,
13681 sql: "CREATE CONNECTION mz_internal.mz_analytics TO AWS (ASSUME ROLE ARN = '')",
13682 access: &[MzAclItem {
13683 grantee: MZ_SYSTEM_ROLE_ID,
13684 grantor: MZ_ANALYTICS_ROLE_ID,
13685 acl_mode: rbac::all_object_privileges(SystemObjectType::Object(ObjectType::Connection)),
13686 }],
13687 owner_id: &MZ_ANALYTICS_ROLE_ID,
13688 runtime_alterable: true,
13689};
13690
13691pub const MZ_SYSTEM_ROLE: BuiltinRole = BuiltinRole {
13692 id: MZ_SYSTEM_ROLE_ID,
13693 name: SYSTEM_USER_NAME,
13694 oid: oid::ROLE_MZ_SYSTEM_OID,
13695 attributes: RoleAttributesRaw::new().with_all(),
13696};
13697
13698pub const MZ_SUPPORT_ROLE: BuiltinRole = BuiltinRole {
13699 id: MZ_SUPPORT_ROLE_ID,
13700 name: SUPPORT_USER_NAME,
13701 oid: oid::ROLE_MZ_SUPPORT_OID,
13702 attributes: RoleAttributesRaw::new(),
13703};
13704
13705pub const MZ_ANALYTICS_ROLE: BuiltinRole = BuiltinRole {
13706 id: MZ_ANALYTICS_ROLE_ID,
13707 name: ANALYTICS_USER_NAME,
13708 oid: oid::ROLE_MZ_ANALYTICS_OID,
13709 attributes: RoleAttributesRaw::new(),
13710};
13711
13712pub const MZ_MONITOR_ROLE: BuiltinRole = BuiltinRole {
13715 id: MZ_MONITOR_ROLE_ID,
13716 name: "mz_monitor",
13717 oid: oid::ROLE_MZ_MONITOR_OID,
13718 attributes: RoleAttributesRaw::new(),
13719};
13720
13721pub const MZ_MONITOR_REDACTED: BuiltinRole = BuiltinRole {
13724 id: MZ_MONITOR_REDACTED_ROLE_ID,
13725 name: "mz_monitor_redacted",
13726 oid: oid::ROLE_MZ_MONITOR_REDACTED_OID,
13727 attributes: RoleAttributesRaw::new(),
13728};
13729
13730pub const MZ_SYSTEM_CLUSTER: BuiltinCluster = BuiltinCluster {
13731 name: SYSTEM_USER_NAME,
13732 owner_id: &MZ_SYSTEM_ROLE_ID,
13733 privileges: &[
13734 MzAclItem {
13735 grantee: MZ_SUPPORT_ROLE_ID,
13736 grantor: MZ_SYSTEM_ROLE_ID,
13737 acl_mode: AclMode::USAGE,
13738 },
13739 rbac::owner_privilege(ObjectType::Cluster, MZ_SYSTEM_ROLE_ID),
13740 ],
13741};
13742
13743pub const MZ_SYSTEM_CLUSTER_REPLICA: BuiltinClusterReplica = BuiltinClusterReplica {
13744 name: BUILTIN_CLUSTER_REPLICA_NAME,
13745 cluster_name: MZ_SYSTEM_CLUSTER.name,
13746};
13747
13748pub const MZ_CATALOG_SERVER_CLUSTER: BuiltinCluster = BuiltinCluster {
13749 name: "mz_catalog_server",
13750 owner_id: &MZ_SYSTEM_ROLE_ID,
13751 privileges: &[
13752 MzAclItem {
13753 grantee: RoleId::Public,
13754 grantor: MZ_SYSTEM_ROLE_ID,
13755 acl_mode: AclMode::USAGE,
13756 },
13757 MzAclItem {
13758 grantee: MZ_SUPPORT_ROLE_ID,
13759 grantor: MZ_SYSTEM_ROLE_ID,
13760 acl_mode: AclMode::USAGE.union(AclMode::CREATE),
13761 },
13762 rbac::owner_privilege(ObjectType::Cluster, MZ_SYSTEM_ROLE_ID),
13763 ],
13764};
13765
13766pub const MZ_CATALOG_SERVER_CLUSTER_REPLICA: BuiltinClusterReplica = BuiltinClusterReplica {
13767 name: BUILTIN_CLUSTER_REPLICA_NAME,
13768 cluster_name: MZ_CATALOG_SERVER_CLUSTER.name,
13769};
13770
13771pub const MZ_PROBE_CLUSTER: BuiltinCluster = BuiltinCluster {
13772 name: "mz_probe",
13773 owner_id: &MZ_SYSTEM_ROLE_ID,
13774 privileges: &[
13775 MzAclItem {
13776 grantee: MZ_SUPPORT_ROLE_ID,
13777 grantor: MZ_SYSTEM_ROLE_ID,
13778 acl_mode: AclMode::USAGE,
13779 },
13780 MzAclItem {
13781 grantee: MZ_MONITOR_ROLE_ID,
13782 grantor: MZ_SYSTEM_ROLE_ID,
13783 acl_mode: AclMode::USAGE,
13784 },
13785 rbac::owner_privilege(ObjectType::Cluster, MZ_SYSTEM_ROLE_ID),
13786 ],
13787};
13788pub const MZ_PROBE_CLUSTER_REPLICA: BuiltinClusterReplica = BuiltinClusterReplica {
13789 name: BUILTIN_CLUSTER_REPLICA_NAME,
13790 cluster_name: MZ_PROBE_CLUSTER.name,
13791};
13792
13793pub const MZ_SUPPORT_CLUSTER: BuiltinCluster = BuiltinCluster {
13794 name: "mz_support",
13795 owner_id: &MZ_SUPPORT_ROLE_ID,
13796 privileges: &[
13797 MzAclItem {
13798 grantee: MZ_SYSTEM_ROLE_ID,
13799 grantor: MZ_SUPPORT_ROLE_ID,
13800 acl_mode: rbac::all_object_privileges(SystemObjectType::Object(ObjectType::Cluster)),
13801 },
13802 rbac::owner_privilege(ObjectType::Cluster, MZ_SUPPORT_ROLE_ID),
13803 ],
13804};
13805
13806pub const MZ_ANALYTICS_CLUSTER: BuiltinCluster = BuiltinCluster {
13807 name: "mz_analytics",
13808 owner_id: &MZ_ANALYTICS_ROLE_ID,
13809 privileges: &[
13810 MzAclItem {
13811 grantee: MZ_SYSTEM_ROLE_ID,
13812 grantor: MZ_ANALYTICS_ROLE_ID,
13813 acl_mode: rbac::all_object_privileges(SystemObjectType::Object(ObjectType::Cluster)),
13814 },
13815 rbac::owner_privilege(ObjectType::Cluster, MZ_ANALYTICS_ROLE_ID),
13816 ],
13817};
13818
13819pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::new(|| {
13821 let mut builtins = vec![
13822 Builtin::Type(&TYPE_ANY),
13823 Builtin::Type(&TYPE_ANYARRAY),
13824 Builtin::Type(&TYPE_ANYELEMENT),
13825 Builtin::Type(&TYPE_ANYNONARRAY),
13826 Builtin::Type(&TYPE_ANYRANGE),
13827 Builtin::Type(&TYPE_BOOL),
13828 Builtin::Type(&TYPE_BOOL_ARRAY),
13829 Builtin::Type(&TYPE_BYTEA),
13830 Builtin::Type(&TYPE_BYTEA_ARRAY),
13831 Builtin::Type(&TYPE_BPCHAR),
13832 Builtin::Type(&TYPE_BPCHAR_ARRAY),
13833 Builtin::Type(&TYPE_CHAR),
13834 Builtin::Type(&TYPE_CHAR_ARRAY),
13835 Builtin::Type(&TYPE_DATE),
13836 Builtin::Type(&TYPE_DATE_ARRAY),
13837 Builtin::Type(&TYPE_FLOAT4),
13838 Builtin::Type(&TYPE_FLOAT4_ARRAY),
13839 Builtin::Type(&TYPE_FLOAT8),
13840 Builtin::Type(&TYPE_FLOAT8_ARRAY),
13841 Builtin::Type(&TYPE_INT4),
13842 Builtin::Type(&TYPE_INT4_ARRAY),
13843 Builtin::Type(&TYPE_INT8),
13844 Builtin::Type(&TYPE_INT8_ARRAY),
13845 Builtin::Type(&TYPE_INTERVAL),
13846 Builtin::Type(&TYPE_INTERVAL_ARRAY),
13847 Builtin::Type(&TYPE_JSONB),
13848 Builtin::Type(&TYPE_JSONB_ARRAY),
13849 Builtin::Type(&TYPE_LIST),
13850 Builtin::Type(&TYPE_MAP),
13851 Builtin::Type(&TYPE_NAME),
13852 Builtin::Type(&TYPE_NAME_ARRAY),
13853 Builtin::Type(&TYPE_NUMERIC),
13854 Builtin::Type(&TYPE_NUMERIC_ARRAY),
13855 Builtin::Type(&TYPE_OID),
13856 Builtin::Type(&TYPE_OID_ARRAY),
13857 Builtin::Type(&TYPE_RECORD),
13858 Builtin::Type(&TYPE_RECORD_ARRAY),
13859 Builtin::Type(&TYPE_REGCLASS),
13860 Builtin::Type(&TYPE_REGCLASS_ARRAY),
13861 Builtin::Type(&TYPE_REGPROC),
13862 Builtin::Type(&TYPE_REGPROC_ARRAY),
13863 Builtin::Type(&TYPE_REGTYPE),
13864 Builtin::Type(&TYPE_REGTYPE_ARRAY),
13865 Builtin::Type(&TYPE_INT2),
13866 Builtin::Type(&TYPE_INT2_ARRAY),
13867 Builtin::Type(&TYPE_TEXT),
13868 Builtin::Type(&TYPE_TEXT_ARRAY),
13869 Builtin::Type(&TYPE_TIME),
13870 Builtin::Type(&TYPE_TIME_ARRAY),
13871 Builtin::Type(&TYPE_TIMESTAMP),
13872 Builtin::Type(&TYPE_TIMESTAMP_ARRAY),
13873 Builtin::Type(&TYPE_TIMESTAMPTZ),
13874 Builtin::Type(&TYPE_TIMESTAMPTZ_ARRAY),
13875 Builtin::Type(&TYPE_UUID),
13876 Builtin::Type(&TYPE_UUID_ARRAY),
13877 Builtin::Type(&TYPE_VARCHAR),
13878 Builtin::Type(&TYPE_VARCHAR_ARRAY),
13879 Builtin::Type(&TYPE_INT2_VECTOR),
13880 Builtin::Type(&TYPE_INT2_VECTOR_ARRAY),
13881 Builtin::Type(&TYPE_ANYCOMPATIBLE),
13882 Builtin::Type(&TYPE_ANYCOMPATIBLEARRAY),
13883 Builtin::Type(&TYPE_ANYCOMPATIBLENONARRAY),
13884 Builtin::Type(&TYPE_ANYCOMPATIBLELIST),
13885 Builtin::Type(&TYPE_ANYCOMPATIBLEMAP),
13886 Builtin::Type(&TYPE_ANYCOMPATIBLERANGE),
13887 Builtin::Type(&TYPE_UINT2),
13888 Builtin::Type(&TYPE_UINT2_ARRAY),
13889 Builtin::Type(&TYPE_UINT4),
13890 Builtin::Type(&TYPE_UINT4_ARRAY),
13891 Builtin::Type(&TYPE_UINT8),
13892 Builtin::Type(&TYPE_UINT8_ARRAY),
13893 Builtin::Type(&TYPE_MZ_TIMESTAMP),
13894 Builtin::Type(&TYPE_MZ_TIMESTAMP_ARRAY),
13895 Builtin::Type(&TYPE_INT4_RANGE),
13896 Builtin::Type(&TYPE_INT4_RANGE_ARRAY),
13897 Builtin::Type(&TYPE_INT8_RANGE),
13898 Builtin::Type(&TYPE_INT8_RANGE_ARRAY),
13899 Builtin::Type(&TYPE_DATE_RANGE),
13900 Builtin::Type(&TYPE_DATE_RANGE_ARRAY),
13901 Builtin::Type(&TYPE_NUM_RANGE),
13902 Builtin::Type(&TYPE_NUM_RANGE_ARRAY),
13903 Builtin::Type(&TYPE_TS_RANGE),
13904 Builtin::Type(&TYPE_TS_RANGE_ARRAY),
13905 Builtin::Type(&TYPE_TSTZ_RANGE),
13906 Builtin::Type(&TYPE_TSTZ_RANGE_ARRAY),
13907 Builtin::Type(&TYPE_MZ_ACL_ITEM),
13908 Builtin::Type(&TYPE_MZ_ACL_ITEM_ARRAY),
13909 Builtin::Type(&TYPE_ACL_ITEM),
13910 Builtin::Type(&TYPE_ACL_ITEM_ARRAY),
13911 Builtin::Type(&TYPE_INTERNAL),
13912 ];
13913 for (schema, funcs) in &[
13914 (PG_CATALOG_SCHEMA, &*mz_sql::func::PG_CATALOG_BUILTINS),
13915 (
13916 INFORMATION_SCHEMA,
13917 &*mz_sql::func::INFORMATION_SCHEMA_BUILTINS,
13918 ),
13919 (MZ_CATALOG_SCHEMA, &*mz_sql::func::MZ_CATALOG_BUILTINS),
13920 (MZ_INTERNAL_SCHEMA, &*mz_sql::func::MZ_INTERNAL_BUILTINS),
13921 (MZ_UNSAFE_SCHEMA, &*mz_sql::func::MZ_UNSAFE_BUILTINS),
13922 ] {
13923 for (name, func) in funcs.iter() {
13924 builtins.push(Builtin::Func(BuiltinFunc {
13925 name,
13926 schema,
13927 inner: func,
13928 }));
13929 }
13930 }
13931 builtins.append(&mut vec![
13932 Builtin::Source(&MZ_CATALOG_RAW),
13933 Builtin::Log(&MZ_ARRANGEMENT_SHARING_RAW),
13934 Builtin::Log(&MZ_ARRANGEMENT_BATCHES_RAW),
13935 Builtin::Log(&MZ_ARRANGEMENT_RECORDS_RAW),
13936 Builtin::Log(&MZ_ARRANGEMENT_BATCHER_RECORDS_RAW),
13937 Builtin::Log(&MZ_ARRANGEMENT_BATCHER_SIZE_RAW),
13938 Builtin::Log(&MZ_ARRANGEMENT_BATCHER_CAPACITY_RAW),
13939 Builtin::Log(&MZ_ARRANGEMENT_BATCHER_ALLOCATIONS_RAW),
13940 Builtin::Log(&MZ_DATAFLOW_CHANNELS_PER_WORKER),
13941 Builtin::Log(&MZ_DATAFLOW_OPERATORS_PER_WORKER),
13942 Builtin::Log(&MZ_DATAFLOW_ADDRESSES_PER_WORKER),
13943 Builtin::Log(&MZ_DATAFLOW_OPERATOR_REACHABILITY_RAW),
13944 Builtin::Log(&MZ_COMPUTE_EXPORTS_PER_WORKER),
13945 Builtin::Log(&MZ_COMPUTE_DATAFLOW_GLOBAL_IDS_PER_WORKER),
13946 Builtin::Log(&MZ_MESSAGE_COUNTS_RECEIVED_RAW),
13947 Builtin::Log(&MZ_MESSAGE_COUNTS_SENT_RAW),
13948 Builtin::Log(&MZ_MESSAGE_BATCH_COUNTS_RECEIVED_RAW),
13949 Builtin::Log(&MZ_MESSAGE_BATCH_COUNTS_SENT_RAW),
13950 Builtin::Log(&MZ_ACTIVE_PEEKS_PER_WORKER),
13951 Builtin::Log(&MZ_PEEK_DURATIONS_HISTOGRAM_RAW),
13952 Builtin::Log(&MZ_ARRANGEMENT_HEAP_CAPACITY_RAW),
13953 Builtin::Log(&MZ_ARRANGEMENT_HEAP_ALLOCATIONS_RAW),
13954 Builtin::Log(&MZ_ARRANGEMENT_HEAP_SIZE_RAW),
13955 Builtin::Log(&MZ_SCHEDULING_ELAPSED_RAW),
13956 Builtin::Log(&MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_RAW),
13957 Builtin::Log(&MZ_SCHEDULING_PARKS_HISTOGRAM_RAW),
13958 Builtin::Log(&MZ_COMPUTE_FRONTIERS_PER_WORKER),
13959 Builtin::Log(&MZ_COMPUTE_IMPORT_FRONTIERS_PER_WORKER),
13960 Builtin::Log(&MZ_COMPUTE_ERROR_COUNTS_RAW),
13961 Builtin::Log(&MZ_COMPUTE_HYDRATION_TIMES_PER_WORKER),
13962 Builtin::Log(&MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES_PER_WORKER),
13963 Builtin::Table(&MZ_KAFKA_SINKS),
13964 Builtin::Table(&MZ_KAFKA_CONNECTIONS),
13965 Builtin::Table(&MZ_KAFKA_SOURCES),
13966 Builtin::Table(&MZ_OBJECT_DEPENDENCIES),
13967 Builtin::Table(&MZ_ICEBERG_SINKS),
13968 Builtin::Table(&MZ_DATABASES),
13969 Builtin::Table(&MZ_SCHEMAS),
13970 Builtin::Table(&MZ_COLUMNS),
13971 Builtin::Table(&MZ_INDEXES),
13972 Builtin::Table(&MZ_INDEX_COLUMNS),
13973 Builtin::Table(&MZ_TABLES),
13974 Builtin::Table(&MZ_SOURCES),
13975 Builtin::Table(&MZ_SOURCE_REFERENCES),
13976 Builtin::Table(&MZ_POSTGRES_SOURCES),
13977 Builtin::Table(&MZ_POSTGRES_SOURCE_TABLES),
13978 Builtin::Table(&MZ_MYSQL_SOURCE_TABLES),
13979 Builtin::Table(&MZ_SQL_SERVER_SOURCE_TABLES),
13980 Builtin::Table(&MZ_KAFKA_SOURCE_TABLES),
13981 Builtin::Table(&MZ_SINKS),
13982 Builtin::Table(&MZ_VIEWS),
13983 Builtin::Table(&MZ_MATERIALIZED_VIEWS),
13984 Builtin::Table(&MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES),
13985 Builtin::Table(&MZ_TYPES),
13986 Builtin::Table(&MZ_TYPE_PG_METADATA),
13987 Builtin::Table(&MZ_ARRAY_TYPES),
13988 Builtin::Table(&MZ_BASE_TYPES),
13989 Builtin::Table(&MZ_LIST_TYPES),
13990 Builtin::Table(&MZ_MAP_TYPES),
13991 Builtin::Table(&MZ_ROLES),
13992 Builtin::Table(&MZ_ROLE_AUTH),
13993 Builtin::Table(&MZ_ROLE_MEMBERS),
13994 Builtin::Table(&MZ_ROLE_PARAMETERS),
13995 Builtin::Table(&MZ_PSEUDO_TYPES),
13996 Builtin::Table(&MZ_FUNCTIONS),
13997 Builtin::Table(&MZ_OPERATORS),
13998 Builtin::Table(&MZ_AGGREGATES),
13999 Builtin::Table(&MZ_CLUSTERS),
14000 Builtin::Table(&MZ_CLUSTER_WORKLOAD_CLASSES),
14001 Builtin::Table(&MZ_CLUSTER_SCHEDULES),
14002 Builtin::Table(&MZ_SECRETS),
14003 Builtin::Table(&MZ_CONNECTIONS),
14004 Builtin::Table(&MZ_SSH_TUNNEL_CONNECTIONS),
14005 Builtin::Table(&MZ_CLUSTER_REPLICAS),
14006 Builtin::Source(&MZ_CLUSTER_REPLICA_METRICS_HISTORY),
14007 Builtin::View(&MZ_CLUSTER_REPLICA_METRICS),
14008 Builtin::Table(&MZ_CLUSTER_REPLICA_SIZES),
14009 Builtin::Source(&MZ_CLUSTER_REPLICA_STATUS_HISTORY),
14010 Builtin::View(&MZ_CLUSTER_REPLICA_STATUSES),
14011 Builtin::Table(&MZ_INTERNAL_CLUSTER_REPLICAS),
14012 Builtin::Table(&MZ_PENDING_CLUSTER_REPLICAS),
14013 Builtin::Table(&MZ_AUDIT_EVENTS),
14014 Builtin::Table(&MZ_STORAGE_USAGE_BY_SHARD),
14015 Builtin::Table(&MZ_EGRESS_IPS),
14016 Builtin::Table(&MZ_AWS_PRIVATELINK_CONNECTIONS),
14017 Builtin::Table(&MZ_AWS_CONNECTIONS),
14018 Builtin::Table(&MZ_SUBSCRIPTIONS),
14019 Builtin::Table(&MZ_SESSIONS),
14020 Builtin::Table(&MZ_DEFAULT_PRIVILEGES),
14021 Builtin::Table(&MZ_SYSTEM_PRIVILEGES),
14022 Builtin::Table(&MZ_COMMENTS),
14023 Builtin::Table(&MZ_WEBHOOKS_SOURCES),
14024 Builtin::Table(&MZ_HISTORY_RETENTION_STRATEGIES),
14025 Builtin::Table(&MZ_CONTINUAL_TASKS),
14026 Builtin::Table(&MZ_NETWORK_POLICIES),
14027 Builtin::Table(&MZ_NETWORK_POLICY_RULES),
14028 Builtin::Table(&MZ_LICENSE_KEYS),
14029 Builtin::Table(&MZ_REPLACEMENTS),
14030 Builtin::View(&MZ_RELATIONS),
14031 Builtin::View(&MZ_OBJECT_OID_ALIAS),
14032 Builtin::View(&MZ_OBJECTS),
14033 Builtin::View(&MZ_OBJECT_FULLY_QUALIFIED_NAMES),
14034 Builtin::View(&MZ_OBJECTS_ID_NAMESPACE_TYPES),
14035 Builtin::View(&MZ_OBJECT_HISTORY),
14036 Builtin::View(&MZ_OBJECT_LIFETIMES),
14037 Builtin::Table(&MZ_OBJECT_GLOBAL_IDS),
14038 Builtin::View(&MZ_ARRANGEMENT_SHARING_PER_WORKER),
14039 Builtin::View(&MZ_ARRANGEMENT_SHARING),
14040 Builtin::View(&MZ_ARRANGEMENT_SIZES_PER_WORKER),
14041 Builtin::View(&MZ_ARRANGEMENT_SIZES),
14042 Builtin::View(&MZ_DATAFLOWS_PER_WORKER),
14043 Builtin::View(&MZ_DATAFLOWS),
14044 Builtin::View(&MZ_DATAFLOW_ADDRESSES),
14045 Builtin::View(&MZ_DATAFLOW_CHANNELS),
14046 Builtin::View(&MZ_DATAFLOW_OPERATORS),
14047 Builtin::View(&MZ_DATAFLOW_GLOBAL_IDS),
14048 Builtin::View(&MZ_MAPPABLE_OBJECTS),
14049 Builtin::View(&MZ_DATAFLOW_OPERATOR_DATAFLOWS_PER_WORKER),
14050 Builtin::View(&MZ_DATAFLOW_OPERATOR_DATAFLOWS),
14051 Builtin::View(&MZ_OBJECT_TRANSITIVE_DEPENDENCIES),
14052 Builtin::View(&MZ_DATAFLOW_OPERATOR_REACHABILITY_PER_WORKER),
14053 Builtin::View(&MZ_DATAFLOW_OPERATOR_REACHABILITY),
14054 Builtin::View(&MZ_CLUSTER_REPLICA_UTILIZATION),
14055 Builtin::View(&MZ_CLUSTER_REPLICA_UTILIZATION_HISTORY),
14056 Builtin::View(&MZ_DATAFLOW_OPERATOR_PARENTS_PER_WORKER),
14057 Builtin::View(&MZ_DATAFLOW_OPERATOR_PARENTS),
14058 Builtin::View(&MZ_COMPUTE_EXPORTS),
14059 Builtin::View(&MZ_DATAFLOW_ARRANGEMENT_SIZES),
14060 Builtin::View(&MZ_EXPECTED_GROUP_SIZE_ADVICE),
14061 Builtin::View(&MZ_COMPUTE_FRONTIERS),
14062 Builtin::View(&MZ_DATAFLOW_CHANNEL_OPERATORS_PER_WORKER),
14063 Builtin::View(&MZ_DATAFLOW_CHANNEL_OPERATORS),
14064 Builtin::View(&MZ_COMPUTE_IMPORT_FRONTIERS),
14065 Builtin::View(&MZ_MESSAGE_COUNTS_PER_WORKER),
14066 Builtin::View(&MZ_MESSAGE_COUNTS),
14067 Builtin::View(&MZ_ACTIVE_PEEKS),
14068 Builtin::View(&MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM_PER_WORKER),
14069 Builtin::View(&MZ_COMPUTE_OPERATOR_DURATIONS_HISTOGRAM),
14070 Builtin::View(&MZ_RECORDS_PER_DATAFLOW_OPERATOR_PER_WORKER),
14071 Builtin::View(&MZ_RECORDS_PER_DATAFLOW_OPERATOR),
14072 Builtin::View(&MZ_RECORDS_PER_DATAFLOW_PER_WORKER),
14073 Builtin::View(&MZ_RECORDS_PER_DATAFLOW),
14074 Builtin::View(&MZ_PEEK_DURATIONS_HISTOGRAM_PER_WORKER),
14075 Builtin::View(&MZ_PEEK_DURATIONS_HISTOGRAM),
14076 Builtin::View(&MZ_SCHEDULING_ELAPSED_PER_WORKER),
14077 Builtin::View(&MZ_SCHEDULING_ELAPSED),
14078 Builtin::View(&MZ_SCHEDULING_PARKS_HISTOGRAM_PER_WORKER),
14079 Builtin::View(&MZ_SCHEDULING_PARKS_HISTOGRAM),
14080 Builtin::View(&MZ_SHOW_ALL_OBJECTS),
14081 Builtin::View(&MZ_SHOW_COLUMNS),
14082 Builtin::View(&MZ_SHOW_CLUSTERS),
14083 Builtin::View(&MZ_SHOW_SECRETS),
14084 Builtin::View(&MZ_SHOW_DATABASES),
14085 Builtin::View(&MZ_SHOW_SCHEMAS),
14086 Builtin::View(&MZ_SHOW_TABLES),
14087 Builtin::View(&MZ_SHOW_VIEWS),
14088 Builtin::View(&MZ_SHOW_TYPES),
14089 Builtin::View(&MZ_SHOW_ROLES),
14090 Builtin::View(&MZ_SHOW_CONNECTIONS),
14091 Builtin::View(&MZ_SHOW_SOURCES),
14092 Builtin::View(&MZ_SHOW_SINKS),
14093 Builtin::View(&MZ_SHOW_MATERIALIZED_VIEWS),
14094 Builtin::View(&MZ_SHOW_INDEXES),
14095 Builtin::View(&MZ_SHOW_CONTINUAL_TASKS),
14096 Builtin::View(&MZ_MCP_DATA_PRODUCTS),
14097 Builtin::View(&MZ_CLUSTER_REPLICA_HISTORY),
14098 Builtin::View(&MZ_CLUSTER_REPLICA_NAME_HISTORY),
14099 Builtin::View(&MZ_TIMEZONE_NAMES),
14100 Builtin::View(&MZ_TIMEZONE_ABBREVIATIONS),
14101 Builtin::View(&PG_NAMESPACE_ALL_DATABASES),
14102 Builtin::Index(&PG_NAMESPACE_ALL_DATABASES_IND),
14103 Builtin::View(&PG_NAMESPACE),
14104 Builtin::View(&PG_CLASS_ALL_DATABASES),
14105 Builtin::Index(&PG_CLASS_ALL_DATABASES_IND),
14106 Builtin::View(&PG_CLASS),
14107 Builtin::View(&PG_DEPEND),
14108 Builtin::View(&PG_DATABASE),
14109 Builtin::View(&PG_INDEX),
14110 Builtin::View(&PG_TYPE_ALL_DATABASES),
14111 Builtin::Index(&PG_TYPE_ALL_DATABASES_IND),
14112 Builtin::View(&PG_TYPE),
14113 Builtin::View(&PG_DESCRIPTION_ALL_DATABASES),
14114 Builtin::Index(&PG_DESCRIPTION_ALL_DATABASES_IND),
14115 Builtin::View(&PG_DESCRIPTION),
14116 Builtin::View(&PG_ATTRIBUTE_ALL_DATABASES),
14117 Builtin::Index(&PG_ATTRIBUTE_ALL_DATABASES_IND),
14118 Builtin::View(&PG_ATTRIBUTE),
14119 Builtin::View(&PG_PROC),
14120 Builtin::View(&PG_OPERATOR),
14121 Builtin::View(&PG_RANGE),
14122 Builtin::View(&PG_ENUM),
14123 Builtin::View(&PG_ATTRDEF_ALL_DATABASES),
14124 Builtin::Index(&PG_ATTRDEF_ALL_DATABASES_IND),
14125 Builtin::View(&PG_ATTRDEF),
14126 Builtin::View(&PG_SETTINGS),
14127 Builtin::View(&PG_AUTH_MEMBERS),
14128 Builtin::View(&PG_CONSTRAINT),
14129 Builtin::View(&PG_TABLES),
14130 Builtin::View(&PG_TABLESPACE),
14131 Builtin::View(&PG_ACCESS_METHODS),
14132 Builtin::View(&PG_LOCKS),
14133 Builtin::View(&PG_AUTHID_CORE),
14134 Builtin::Index(&PG_AUTHID_CORE_IND),
14135 Builtin::View(&PG_AUTHID),
14136 Builtin::View(&PG_ROLES),
14137 Builtin::View(&PG_USER),
14138 Builtin::View(&PG_VIEWS),
14139 Builtin::View(&PG_MATVIEWS),
14140 Builtin::View(&PG_COLLATION),
14141 Builtin::View(&PG_POLICY),
14142 Builtin::View(&PG_INHERITS),
14143 Builtin::View(&PG_AGGREGATE),
14144 Builtin::View(&PG_TRIGGER),
14145 Builtin::View(&PG_REWRITE),
14146 Builtin::View(&PG_EXTENSION),
14147 Builtin::View(&PG_EVENT_TRIGGER),
14148 Builtin::View(&PG_LANGUAGE),
14149 Builtin::View(&PG_SHDESCRIPTION),
14150 Builtin::View(&PG_INDEXES),
14151 Builtin::View(&PG_TIMEZONE_ABBREVS),
14152 Builtin::View(&PG_TIMEZONE_NAMES),
14153 Builtin::View(&INFORMATION_SCHEMA_APPLICABLE_ROLES),
14154 Builtin::View(&INFORMATION_SCHEMA_COLUMNS),
14155 Builtin::View(&INFORMATION_SCHEMA_ENABLED_ROLES),
14156 Builtin::View(&INFORMATION_SCHEMA_KEY_COLUMN_USAGE),
14157 Builtin::View(&INFORMATION_SCHEMA_REFERENTIAL_CONSTRAINTS),
14158 Builtin::View(&INFORMATION_SCHEMA_ROUTINES),
14159 Builtin::View(&INFORMATION_SCHEMA_SCHEMATA),
14160 Builtin::View(&INFORMATION_SCHEMA_TABLES),
14161 Builtin::View(&INFORMATION_SCHEMA_TABLE_CONSTRAINTS),
14162 Builtin::View(&INFORMATION_SCHEMA_TABLE_PRIVILEGES),
14163 Builtin::View(&INFORMATION_SCHEMA_ROLE_TABLE_GRANTS),
14164 Builtin::View(&INFORMATION_SCHEMA_TRIGGERS),
14165 Builtin::View(&INFORMATION_SCHEMA_VIEWS),
14166 Builtin::View(&INFORMATION_SCHEMA_CHARACTER_SETS),
14167 Builtin::View(&MZ_SHOW_ROLE_MEMBERS),
14168 Builtin::View(&MZ_SHOW_MY_ROLE_MEMBERS),
14169 Builtin::View(&MZ_SHOW_SYSTEM_PRIVILEGES),
14170 Builtin::View(&MZ_SHOW_MY_SYSTEM_PRIVILEGES),
14171 Builtin::View(&MZ_SHOW_CLUSTER_PRIVILEGES),
14172 Builtin::View(&MZ_SHOW_MY_CLUSTER_PRIVILEGES),
14173 Builtin::View(&MZ_SHOW_DATABASE_PRIVILEGES),
14174 Builtin::View(&MZ_SHOW_MY_DATABASE_PRIVILEGES),
14175 Builtin::View(&MZ_SHOW_SCHEMA_PRIVILEGES),
14176 Builtin::View(&MZ_SHOW_MY_SCHEMA_PRIVILEGES),
14177 Builtin::View(&MZ_SHOW_OBJECT_PRIVILEGES),
14178 Builtin::View(&MZ_SHOW_MY_OBJECT_PRIVILEGES),
14179 Builtin::View(&MZ_SHOW_ALL_PRIVILEGES),
14180 Builtin::View(&MZ_SHOW_ALL_MY_PRIVILEGES),
14181 Builtin::View(&MZ_SHOW_DEFAULT_PRIVILEGES),
14182 Builtin::View(&MZ_SHOW_MY_DEFAULT_PRIVILEGES),
14183 Builtin::Source(&MZ_SINK_STATUS_HISTORY),
14184 Builtin::View(&MZ_SINK_STATUSES),
14185 Builtin::Source(&MZ_SOURCE_STATUS_HISTORY),
14186 Builtin::Source(&MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY),
14187 Builtin::View(&MZ_AWS_PRIVATELINK_CONNECTION_STATUSES),
14188 Builtin::Source(&MZ_STATEMENT_EXECUTION_HISTORY),
14189 Builtin::View(&MZ_STATEMENT_EXECUTION_HISTORY_REDACTED),
14190 Builtin::Source(&MZ_PREPARED_STATEMENT_HISTORY),
14191 Builtin::Source(&MZ_SESSION_HISTORY),
14192 Builtin::Source(&MZ_SQL_TEXT),
14193 Builtin::View(&MZ_SQL_TEXT_REDACTED),
14194 Builtin::View(&MZ_RECENT_SQL_TEXT),
14195 Builtin::View(&MZ_RECENT_SQL_TEXT_REDACTED),
14196 Builtin::Index(&MZ_RECENT_SQL_TEXT_IND),
14197 Builtin::View(&MZ_ACTIVITY_LOG_THINNED),
14198 Builtin::View(&MZ_RECENT_ACTIVITY_LOG_THINNED),
14199 Builtin::View(&MZ_RECENT_ACTIVITY_LOG),
14200 Builtin::View(&MZ_RECENT_ACTIVITY_LOG_REDACTED),
14201 Builtin::Index(&MZ_RECENT_ACTIVITY_LOG_THINNED_IND),
14202 Builtin::View(&MZ_SOURCE_STATUSES),
14203 Builtin::Source(&MZ_STATEMENT_LIFECYCLE_HISTORY),
14204 Builtin::Source(&MZ_STORAGE_SHARDS),
14205 Builtin::Source(&MZ_SOURCE_STATISTICS_RAW),
14206 Builtin::Source(&MZ_SINK_STATISTICS_RAW),
14207 Builtin::View(&MZ_SOURCE_STATISTICS_WITH_HISTORY),
14208 Builtin::Index(&MZ_SOURCE_STATISTICS_WITH_HISTORY_IND),
14209 Builtin::View(&MZ_SOURCE_STATISTICS),
14210 Builtin::Index(&MZ_SOURCE_STATISTICS_IND),
14211 Builtin::View(&MZ_SINK_STATISTICS),
14212 Builtin::Index(&MZ_SINK_STATISTICS_IND),
14213 Builtin::View(&MZ_STORAGE_USAGE),
14214 Builtin::Source(&MZ_FRONTIERS),
14215 Builtin::View(&MZ_GLOBAL_FRONTIERS),
14216 Builtin::Source(&MZ_WALLCLOCK_LAG_HISTORY),
14217 Builtin::View(&MZ_WALLCLOCK_GLOBAL_LAG_HISTORY),
14218 Builtin::View(&MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY),
14219 Builtin::View(&MZ_WALLCLOCK_GLOBAL_LAG),
14220 Builtin::Source(&MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW),
14221 Builtin::View(&MZ_WALLCLOCK_GLOBAL_LAG_HISTOGRAM),
14222 Builtin::Source(&MZ_MATERIALIZED_VIEW_REFRESHES),
14223 Builtin::Source(&MZ_COMPUTE_DEPENDENCIES),
14224 Builtin::View(&MZ_MATERIALIZATION_DEPENDENCIES),
14225 Builtin::View(&MZ_MATERIALIZATION_LAG),
14226 Builtin::View(&MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW),
14227 Builtin::View(&MZ_COMPUTE_ERROR_COUNTS_PER_WORKER),
14228 Builtin::View(&MZ_COMPUTE_ERROR_COUNTS),
14229 Builtin::Source(&MZ_COMPUTE_ERROR_COUNTS_RAW_UNIFIED),
14230 Builtin::Source(&MZ_COMPUTE_HYDRATION_TIMES),
14231 Builtin::Log(&MZ_COMPUTE_LIR_MAPPING_PER_WORKER),
14232 Builtin::View(&MZ_LIR_MAPPING),
14233 Builtin::Source(&MZ_COMPUTE_OPERATOR_HYDRATION_STATUSES),
14234 Builtin::Source(&MZ_CLUSTER_REPLICA_FRONTIERS),
14235 Builtin::View(&MZ_COMPUTE_HYDRATION_STATUSES),
14236 Builtin::View(&MZ_HYDRATION_STATUSES),
14237 Builtin::Index(&MZ_HYDRATION_STATUSES_IND),
14238 Builtin::View(&MZ_SHOW_CLUSTER_REPLICAS),
14239 Builtin::View(&MZ_SHOW_NETWORK_POLICIES),
14240 Builtin::View(&MZ_CLUSTER_DEPLOYMENT_LINEAGE),
14241 Builtin::Index(&MZ_SHOW_DATABASES_IND),
14242 Builtin::Index(&MZ_SHOW_SCHEMAS_IND),
14243 Builtin::Index(&MZ_SHOW_CONNECTIONS_IND),
14244 Builtin::Index(&MZ_SHOW_TABLES_IND),
14245 Builtin::Index(&MZ_SHOW_SOURCES_IND),
14246 Builtin::Index(&MZ_SHOW_VIEWS_IND),
14247 Builtin::Index(&MZ_SHOW_MATERIALIZED_VIEWS_IND),
14248 Builtin::Index(&MZ_SHOW_SINKS_IND),
14249 Builtin::Index(&MZ_SHOW_TYPES_IND),
14250 Builtin::Index(&MZ_SHOW_ALL_OBJECTS_IND),
14251 Builtin::Index(&MZ_SHOW_INDEXES_IND),
14252 Builtin::Index(&MZ_SHOW_COLUMNS_IND),
14253 Builtin::Index(&MZ_SHOW_CLUSTERS_IND),
14254 Builtin::Index(&MZ_SHOW_CLUSTER_REPLICAS_IND),
14255 Builtin::Index(&MZ_SHOW_SECRETS_IND),
14256 Builtin::Index(&MZ_SHOW_ROLES_IND),
14257 Builtin::Index(&MZ_CLUSTERS_IND),
14258 Builtin::Index(&MZ_INDEXES_IND),
14259 Builtin::Index(&MZ_ROLES_IND),
14260 Builtin::Index(&MZ_SOURCES_IND),
14261 Builtin::Index(&MZ_SINKS_IND),
14262 Builtin::Index(&MZ_MATERIALIZED_VIEWS_IND),
14263 Builtin::Index(&MZ_CONTINUAL_TASKS_IND),
14264 Builtin::Index(&MZ_SOURCE_STATUSES_IND),
14265 Builtin::Index(&MZ_SOURCE_STATUS_HISTORY_IND),
14266 Builtin::Index(&MZ_SINK_STATUSES_IND),
14267 Builtin::Index(&MZ_SINK_STATUS_HISTORY_IND),
14268 Builtin::Index(&MZ_CLUSTER_REPLICAS_IND),
14269 Builtin::Index(&MZ_CLUSTER_REPLICA_SIZES_IND),
14270 Builtin::Index(&MZ_CLUSTER_REPLICA_STATUSES_IND),
14271 Builtin::Index(&MZ_CLUSTER_REPLICA_STATUS_HISTORY_IND),
14272 Builtin::Index(&MZ_CLUSTER_REPLICA_METRICS_IND),
14273 Builtin::Index(&MZ_CLUSTER_REPLICA_METRICS_HISTORY_IND),
14274 Builtin::Index(&MZ_CLUSTER_REPLICA_HISTORY_IND),
14275 Builtin::Index(&MZ_CLUSTER_REPLICA_NAME_HISTORY_IND),
14276 Builtin::Index(&MZ_OBJECT_LIFETIMES_IND),
14277 Builtin::Index(&MZ_OBJECT_HISTORY_IND),
14278 Builtin::Index(&MZ_OBJECT_DEPENDENCIES_IND),
14279 Builtin::Index(&MZ_COMPUTE_DEPENDENCIES_IND),
14280 Builtin::Index(&MZ_OBJECT_TRANSITIVE_DEPENDENCIES_IND),
14281 Builtin::Index(&MZ_FRONTIERS_IND),
14282 Builtin::Index(&MZ_WALLCLOCK_GLOBAL_LAG_RECENT_HISTORY_IND),
14283 Builtin::Index(&MZ_KAFKA_SOURCES_IND),
14284 Builtin::Index(&MZ_WEBHOOK_SOURCES_IND),
14285 Builtin::Index(&MZ_COMMENTS_IND),
14286 Builtin::Index(&MZ_DATABASES_IND),
14287 Builtin::Index(&MZ_SCHEMAS_IND),
14288 Builtin::Index(&MZ_CONNECTIONS_IND),
14289 Builtin::Index(&MZ_TABLES_IND),
14290 Builtin::Index(&MZ_TYPES_IND),
14291 Builtin::Index(&MZ_OBJECTS_IND),
14292 Builtin::Index(&MZ_COLUMNS_IND),
14293 Builtin::Index(&MZ_SECRETS_IND),
14294 Builtin::Index(&MZ_VIEWS_IND),
14295 Builtin::Index(&MZ_CONSOLE_CLUSTER_UTILIZATION_OVERVIEW_IND),
14296 Builtin::Index(&MZ_CLUSTER_DEPLOYMENT_LINEAGE_IND),
14297 Builtin::Index(&MZ_CLUSTER_REPLICA_FRONTIERS_IND),
14298 Builtin::Index(&MZ_COMPUTE_HYDRATION_TIMES_IND),
14299 Builtin::View(&MZ_RECENT_STORAGE_USAGE),
14300 Builtin::Index(&MZ_RECENT_STORAGE_USAGE_IND),
14301 Builtin::Connection(&MZ_ANALYTICS),
14302 Builtin::ContinualTask(&MZ_CLUSTER_REPLICA_METRICS_HISTORY_CT),
14303 Builtin::ContinualTask(&MZ_CLUSTER_REPLICA_STATUS_HISTORY_CT),
14304 Builtin::ContinualTask(&MZ_WALLCLOCK_LAG_HISTORY_CT),
14305 Builtin::View(&MZ_INDEX_ADVICE),
14306 ]);
14307
14308 builtins.extend(notice::builtins());
14309
14310 builtins
14311});
14312pub const BUILTIN_ROLES: &[&BuiltinRole] = &[
14313 &MZ_SYSTEM_ROLE,
14314 &MZ_SUPPORT_ROLE,
14315 &MZ_ANALYTICS_ROLE,
14316 &MZ_MONITOR_ROLE,
14317 &MZ_MONITOR_REDACTED,
14318];
14319pub const BUILTIN_CLUSTERS: &[&BuiltinCluster] = &[
14320 &MZ_SYSTEM_CLUSTER,
14321 &MZ_CATALOG_SERVER_CLUSTER,
14322 &MZ_PROBE_CLUSTER,
14323 &MZ_SUPPORT_CLUSTER,
14324 &MZ_ANALYTICS_CLUSTER,
14325];
14326pub const BUILTIN_CLUSTER_REPLICAS: &[&BuiltinClusterReplica] = &[
14327 &MZ_SYSTEM_CLUSTER_REPLICA,
14328 &MZ_CATALOG_SERVER_CLUSTER_REPLICA,
14329 &MZ_PROBE_CLUSTER_REPLICA,
14330];
14331
14332#[allow(non_snake_case)]
14333pub mod BUILTINS {
14334 use mz_sql::catalog::BuiltinsConfig;
14335
14336 use super::*;
14337
14338 pub fn logs() -> impl Iterator<Item = &'static BuiltinLog> {
14339 BUILTINS_STATIC.iter().filter_map(|b| match b {
14340 Builtin::Log(log) => Some(*log),
14341 _ => None,
14342 })
14343 }
14344
14345 pub fn types() -> impl Iterator<Item = &'static BuiltinType<NameReference>> {
14346 BUILTINS_STATIC.iter().filter_map(|b| match b {
14347 Builtin::Type(typ) => Some(*typ),
14348 _ => None,
14349 })
14350 }
14351
14352 pub fn views() -> impl Iterator<Item = &'static BuiltinView> {
14353 BUILTINS_STATIC.iter().filter_map(|b| match b {
14354 Builtin::View(view) => Some(*view),
14355 _ => None,
14356 })
14357 }
14358
14359 pub fn funcs() -> impl Iterator<Item = &'static BuiltinFunc> {
14360 BUILTINS_STATIC.iter().filter_map(|b| match b {
14361 Builtin::Func(func) => Some(func),
14362 _ => None,
14363 })
14364 }
14365
14366 pub fn iter(cfg: &BuiltinsConfig) -> impl Iterator<Item = &'static Builtin<NameReference>> {
14367 let include_continual_tasks = cfg.include_continual_tasks;
14368 BUILTINS_STATIC.iter().filter(move |x| match x {
14369 Builtin::ContinualTask(_) if !include_continual_tasks => false,
14370 _ => true,
14371 })
14372 }
14373}
14374
14375pub static BUILTIN_LOG_LOOKUP: LazyLock<HashMap<&'static str, &'static BuiltinLog>> =
14376 LazyLock::new(|| BUILTINS::logs().map(|log| (log.name, log)).collect());
14377pub static BUILTIN_LOOKUP: LazyLock<
14380 HashMap<SystemObjectDescription, (usize, &'static Builtin<NameReference>)>,
14381> = LazyLock::new(|| {
14382 BUILTINS_STATIC
14387 .iter()
14388 .enumerate()
14389 .map(|(idx, builtin)| {
14390 (
14391 SystemObjectDescription {
14392 schema_name: builtin.schema().to_string(),
14393 object_type: builtin.catalog_item_type(),
14394 object_name: builtin.name().to_string(),
14395 },
14396 (idx, builtin),
14397 )
14398 })
14399 .collect()
14400});
14401
14402#[mz_ore::test]
14403#[cfg_attr(miri, ignore)] fn test_builtin_type_schema() {
14405 use mz_pgrepr::oid::FIRST_MATERIALIZE_OID;
14406
14407 for typ in BUILTINS::types() {
14408 if typ.oid < FIRST_MATERIALIZE_OID {
14409 assert_eq!(
14410 typ.schema, PG_CATALOG_SCHEMA,
14411 "{typ:?} should be in {PG_CATALOG_SCHEMA} schema"
14412 );
14413 } else {
14414 assert_eq!(
14417 typ.schema, MZ_CATALOG_SCHEMA,
14418 "{typ:?} should be in {MZ_CATALOG_SCHEMA} schema"
14419 );
14420 }
14421 }
14422}