1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use mz_repr::{RelationDesc, ScalarType};
use std::sync::LazyLock;

pub static MZ_PREPARED_STATEMENT_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("id", ScalarType::Uuid.nullable(false))
        .with_column("session_id", ScalarType::Uuid.nullable(false))
        .with_column("name", ScalarType::String.nullable(false))
        .with_column("sql_hash", ScalarType::Bytes.nullable(false))
        .with_column(
            "prepared_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column("statement_type", ScalarType::String.nullable(true))
        .with_column("throttled_count", ScalarType::UInt64.nullable(false))
        .finish()
});

pub static MZ_SQL_TEXT_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column(
            "prepared_day",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column("sql_hash", ScalarType::Bytes.nullable(false))
        .with_column("sql", ScalarType::String.nullable(false))
        .with_column("redacted_sql", ScalarType::String.nullable(false))
        .finish()
});

pub static MZ_SESSION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("session_id", ScalarType::Uuid.nullable(false))
        .with_column(
            "connected_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column(
            "initial_application_name",
            ScalarType::String.nullable(false),
        )
        .with_column("authenticated_user", ScalarType::String.nullable(false))
        .finish()
});

// NOTE: Update the views `mz_statement_execution_history_redacted`
// and `mz_activity_log`, and `mz_activity_log_redacted` whenever this
// is updated, to include the new columns where appropriate.
//
// The `redacted` views should contain only those columns that should
// be queryable by support.
pub static MZ_STATEMENT_EXECUTION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("id", ScalarType::Uuid.nullable(false))
        .with_column("prepared_statement_id", ScalarType::Uuid.nullable(false))
        .with_column("sample_rate", ScalarType::Float64.nullable(false))
        .with_column("cluster_id", ScalarType::String.nullable(true))
        .with_column("application_name", ScalarType::String.nullable(false))
        .with_column("cluster_name", ScalarType::String.nullable(true))
        .with_column("database_name", ScalarType::String.nullable(false))
        .with_column(
            "search_path",
            ScalarType::List {
                element_type: Box::new(ScalarType::String),
                custom_id: None,
            }
            .nullable(false),
        )
        .with_column("transaction_isolation", ScalarType::String.nullable(false))
        // Note that this can't be a timestamp, as it might be u64::max,
        // which is out of range.
        .with_column("execution_timestamp", ScalarType::UInt64.nullable(true))
        .with_column("transaction_id", ScalarType::UInt64.nullable(false))
        .with_column("transient_index_id", ScalarType::String.nullable(true))
        .with_column(
            "params",
            ScalarType::Array(Box::new(ScalarType::String)).nullable(false),
        )
        .with_column("mz_version", ScalarType::String.nullable(false))
        .with_column(
            "began_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column(
            "finished_at",
            ScalarType::TimestampTz { precision: None }.nullable(true),
        )
        .with_column("finished_status", ScalarType::String.nullable(true))
        .with_column("error_message", ScalarType::String.nullable(true))
        .with_column("result_size", ScalarType::Int64.nullable(true))
        .with_column("rows_returned", ScalarType::Int64.nullable(true))
        .with_column("execution_strategy", ScalarType::String.nullable(true))
        .finish()
});

pub static MZ_SOURCE_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column(
            "occurred_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column("source_id", ScalarType::String.nullable(false))
        .with_column("status", ScalarType::String.nullable(false))
        .with_column("error", ScalarType::String.nullable(true))
        .with_column("details", ScalarType::Jsonb.nullable(true))
        .finish()
});

pub static MZ_SINK_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column(
            "occurred_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .with_column("sink_id", ScalarType::String.nullable(false))
        .with_column("status", ScalarType::String.nullable(false))
        .with_column("error", ScalarType::String.nullable(true))
        .with_column("details", ScalarType::Jsonb.nullable(true))
        .finish()
});

pub static MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_DESC: LazyLock<RelationDesc> =
    LazyLock::new(|| {
        RelationDesc::builder()
            .with_column(
                "occurred_at",
                ScalarType::TimestampTz { precision: None }.nullable(false),
            )
            .with_column("connection_id", ScalarType::String.nullable(false))
            .with_column("status", ScalarType::String.nullable(false))
            .finish()
    });

pub static REPLICA_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("replica_id", ScalarType::String.nullable(false))
        .with_column("process_id", ScalarType::UInt64.nullable(false))
        .with_column("status", ScalarType::String.nullable(false))
        .with_column("reason", ScalarType::String.nullable(true))
        .with_column(
            "occurred_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .finish()
});

pub static REPLICA_METRICS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("replica_id", ScalarType::String.nullable(false))
        .with_column("process_id", ScalarType::UInt64.nullable(false))
        .with_column("cpu_nano_cores", ScalarType::UInt64.nullable(true))
        .with_column("memory_bytes", ScalarType::UInt64.nullable(true))
        .with_column("disk_bytes", ScalarType::UInt64.nullable(true))
        .with_column(
            "occurred_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .finish()
});

pub static WALLCLOCK_LAG_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
    RelationDesc::builder()
        .with_column("object_id", ScalarType::String.nullable(false))
        .with_column("replica_id", ScalarType::String.nullable(true))
        .with_column("lag", ScalarType::Interval.nullable(false))
        .with_column(
            "occurred_at",
            ScalarType::TimestampTz { precision: None }.nullable(false),
        )
        .finish()
});