Skip to content

Commit ca79ae2

Browse files
authored
Merge pull request #34332 from teskje/mz_replacements
catalog: add mz_replacements system relation
2 parents 6ef1bf2 + f5952b4 commit ca79ae2

File tree

23 files changed

+197
-647
lines changed

23 files changed

+197
-647
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ The `mz_webhook_sources` table contains a row for each webhook source in the sys
13441344
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_prepared_statement_history -->
13451345
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_recent_sql_text -->
13461346
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_recent_sql_text_redacted -->
1347+
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_replacements -->
13471348
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_show_all_objects -->
13481349
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_show_clusters -->
13491350
<!-- RELATION_SPEC_UNDOCUMENTED mz_internal.mz_show_cluster_replicas -->

src/adapter/src/catalog/builtin_table_updates.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use mz_catalog::builtin::{
2626
MZ_MATERIALIZED_VIEW_REFRESH_STRATEGIES, MZ_MATERIALIZED_VIEWS, MZ_MYSQL_SOURCE_TABLES,
2727
MZ_NETWORK_POLICIES, MZ_NETWORK_POLICY_RULES, MZ_OBJECT_DEPENDENCIES, MZ_OBJECT_GLOBAL_IDS,
2828
MZ_OPERATORS, MZ_PENDING_CLUSTER_REPLICAS, MZ_POSTGRES_SOURCE_TABLES, MZ_POSTGRES_SOURCES,
29-
MZ_PSEUDO_TYPES, MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES, MZ_SCHEMAS,
30-
MZ_SECRETS, MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES,
29+
MZ_PSEUDO_TYPES, MZ_REPLACEMENTS, MZ_ROLE_AUTH, MZ_ROLE_MEMBERS, MZ_ROLE_PARAMETERS, MZ_ROLES,
30+
MZ_SCHEMAS, MZ_SECRETS, MZ_SESSIONS, MZ_SINKS, MZ_SOURCE_REFERENCES, MZ_SOURCES,
3131
MZ_SQL_SERVER_SOURCE_TABLES, MZ_SSH_TUNNEL_CONNECTIONS, MZ_STORAGE_USAGE_BY_SHARD,
3232
MZ_SUBSCRIPTIONS, MZ_SYSTEM_PRIVILEGES, MZ_TABLES, MZ_TYPE_PG_METADATA, MZ_TYPES, MZ_VIEWS,
3333
MZ_WEBHOOKS_SOURCES,
@@ -1537,6 +1537,17 @@ impl CatalogState {
15371537
));
15381538
}
15391539

1540+
if let Some(target_id) = mview.replacement_target {
1541+
updates.push(BuiltinTableUpdate::row(
1542+
&*MZ_REPLACEMENTS,
1543+
Row::pack_slice(&[
1544+
Datum::String(&id.to_string()),
1545+
Datum::String(&target_id.to_string()),
1546+
]),
1547+
diff,
1548+
));
1549+
}
1550+
15401551
updates
15411552
}
15421553

src/catalog/src/builtin.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5545,6 +5545,28 @@ pub static MZ_LICENSE_KEYS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTab
55455545
access: vec![PUBLIC_SELECT],
55465546
});
55475547

5548+
pub static MZ_REPLACEMENTS: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
5549+
name: "mz_replacements",
5550+
schema: MZ_INTERNAL_SCHEMA,
5551+
oid: oid::TABLE_MZ_REPLACEMENTS_OID,
5552+
desc: RelationDesc::builder()
5553+
.with_column("id", SqlScalarType::String.nullable(false))
5554+
.with_column("target_id", SqlScalarType::String.nullable(false))
5555+
.finish(),
5556+
column_comments: BTreeMap::from_iter([
5557+
(
5558+
"id",
5559+
"The ID of the replacement object. Corresponds to `mz_objects.id`.",
5560+
),
5561+
(
5562+
"target_id",
5563+
"The ID of the replacement target. Corresponds to `mz_objects.id`.",
5564+
),
5565+
]),
5566+
is_retained_metrics_object: false,
5567+
access: vec![PUBLIC_SELECT],
5568+
});
5569+
55485570
// These will be replaced with per-replica tables once source/sink multiplexing on
55495571
// a single cluster is supported.
55505572
pub static MZ_SOURCE_STATISTICS_RAW: LazyLock<BuiltinSource> = LazyLock::new(|| BuiltinSource {
@@ -11105,25 +11127,34 @@ pub static MZ_SHOW_MATERIALIZED_VIEWS: LazyLock<BuiltinView> = LazyLock::new(||
1110511127
.with_column("schema_id", SqlScalarType::String.nullable(false))
1110611128
.with_column("cluster_id", SqlScalarType::String.nullable(false))
1110711129
.with_column("comment", SqlScalarType::String.nullable(false))
11130+
.with_column("replacing", SqlScalarType::String.nullable(true))
1110811131
.finish(),
1110911132
column_comments: BTreeMap::new(),
1111011133
sql: "
11111-
WITH comments AS (
11112-
SELECT id, comment
11113-
FROM mz_internal.mz_comments
11114-
WHERE object_type = 'materialized-view' AND object_sub_id IS NULL
11115-
)
11134+
WITH
11135+
comments AS (
11136+
SELECT id, comment
11137+
FROM mz_internal.mz_comments
11138+
WHERE object_type = 'materialized-view' AND object_sub_id IS NULL
11139+
),
11140+
replacements AS (
11141+
SELECT r.id, mv.name AS target_name
11142+
FROM mz_internal.mz_replacements r
11143+
JOIN mz_materialized_views mv ON r.target_id = mv.id
11144+
)
1111611145
SELECT
1111711146
mviews.id as id,
1111811147
mviews.name,
1111911148
clusters.name AS cluster,
1112011149
schema_id,
1112111150
cluster_id,
11122-
COALESCE(comments.comment, '') as comment
11151+
COALESCE(comments.comment, '') as comment,
11152+
replacements.target_name as replacing
1112311153
FROM
1112411154
mz_catalog.mz_materialized_views AS mviews
1112511155
JOIN mz_catalog.mz_clusters AS clusters ON clusters.id = mviews.cluster_id
11126-
LEFT JOIN comments ON mviews.id = comments.id",
11156+
LEFT JOIN comments ON mviews.id = comments.id
11157+
LEFT JOIN replacements ON mviews.id = replacements.id",
1112711158
access: vec![PUBLIC_SELECT],
1112811159
});
1112911160

@@ -13839,6 +13870,7 @@ pub static BUILTINS_STATIC: LazyLock<Vec<Builtin<NameReference>>> = LazyLock::ne
1383913870
Builtin::Table(&MZ_NETWORK_POLICIES),
1384013871
Builtin::Table(&MZ_NETWORK_POLICY_RULES),
1384113872
Builtin::Table(&MZ_LICENSE_KEYS),
13873+
Builtin::Table(&MZ_REPLACEMENTS),
1384213874
Builtin::View(&MZ_RELATIONS),
1384313875
Builtin::View(&MZ_OBJECT_OID_ALIAS),
1384413876
Builtin::View(&MZ_OBJECTS),

src/environmentd/tests/testdata/http/ws

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/pgrepr-consts/src/oid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ pub const VIEW_MZ_STORAGE_USAGE_OID: u32 = 16771;
497497
pub const VIEW_MZ_RELATIONS_OID: u32 = 16772;
498498
pub const VIEW_MZ_OBJECT_OID_ALIAS_OID: u32 = 16773;
499499
pub const VIEW_MZ_OBJECTS_OID: u32 = 16774;
500-
pub const VIEW_MZ_OBJECT_GLOBAL_IDS_OID: u32 = 17061;
501500
pub const VIEW_MZ_OBJECT_FULLY_QUALIFIED_NAMES_OID: u32 = 16775;
502501
pub const VIEW_MZ_OBJECT_LIFETIMES_OID: u32 = 16776;
503502
pub const VIEW_MZ_DATAFLOWS_PER_WORKER_OID: u32 = 16777;
@@ -782,3 +781,5 @@ pub const TABLE_MZ_SQL_SERVER_SOURCE_TABLES_OID: u32 = 17057;
782781
pub const TABLE_MZ_LICENSE_KEYS_OID: u32 = 17058;
783782
pub const TABLE_MZ_ROLE_AUTH_OID: u32 = 17059;
784783
pub const TABLE_MZ_ICEBERG_SINKS_OID: u32 = 17060;
784+
pub const VIEW_MZ_OBJECT_GLOBAL_IDS_OID: u32 = 17061;
785+
pub const TABLE_MZ_REPLACEMENTS_OID: u32 = 17062;

src/sql/src/plan/statement/show.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::plan::statement::{StatementContext, StatementDesc, dml};
4747
use crate::plan::{
4848
HirRelationExpr, Params, Plan, PlanError, ShowColumnsPlan, ShowCreatePlan, query, transform_ast,
4949
};
50+
use crate::session::vars::ENABLE_REPLACEMENT_MATERIALIZED_VIEWS;
5051

5152
pub fn describe_show_create_view(
5253
_: &StatementContext,
@@ -576,18 +577,17 @@ fn show_materialized_views<'a>(
576577
}
577578

578579
let query = format!(
579-
"SELECT name, cluster, comment
580-
FROM mz_internal.mz_show_materialized_views
581-
WHERE {where_clause}"
580+
"SELECT name, cluster, comment, replacing
581+
FROM mz_internal.mz_show_materialized_views
582+
WHERE {where_clause}"
582583
);
583584

584-
ShowSelect::new(
585-
scx,
586-
query,
587-
filter,
588-
None,
589-
Some(&["name", "cluster", "comment"]),
590-
)
585+
let mut projection = vec!["name", "cluster", "comment"];
586+
if scx.is_feature_flag_enabled(&ENABLE_REPLACEMENT_MATERIALIZED_VIEWS) {
587+
projection.push("replacing");
588+
}
589+
590+
ShowSelect::new(scx, query, filter, None, Some(&projection))
591591
}
592592

593593
fn show_sinks<'a>(

test/mysql-cdc-old-syntax/alter-source.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ INSERT INTO table_e VALUES (3, 'three');
179179
3
180180
4
181181

182-
> SHOW MATERIALIZED VIEWS
183-
mv_e quickstart ""
184-
mv_f quickstart ""
182+
> SELECT name FROM mz_materialized_views
183+
mv_e
184+
mv_f
185185

186186
# RESTRICT works
187187
! DROP SOURCE table_e RESTRICT;
@@ -201,7 +201,7 @@ contains:cannot drop source "table_e": still depended upon by materialized view
201201
mz_source_progress progress
202202
table_g subsource
203203

204-
> SHOW MATERIALIZED VIEWS
204+
> SELECT name FROM mz_materialized_views
205205

206206
> DROP SOURCE table_g;
207207

test/mysql-cdc/alter-source.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ INSERT INTO table_e VALUES (3, 'three');
189189
3
190190
4
191191

192-
> SHOW MATERIALIZED VIEWS
193-
mv_e quickstart ""
194-
mv_f quickstart ""
192+
> SELECT name FROM mz_materialized_views
193+
mv_e
194+
mv_f
195195

196196
# RESTRICT works
197197
! DROP TABLE table_e RESTRICT;
@@ -208,7 +208,7 @@ contains:cannot drop table "table_e": still depended upon by materialized view "
208208
> SHOW TABLES
209209
table_g ""
210210

211-
> SHOW MATERIALIZED VIEWS
211+
> SELECT name FROM mz_materialized_views
212212

213213
> DROP TABLE table_g;
214214

test/pg-cdc-old-syntax/alter-source.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ INSERT INTO table_e VALUES (3, 'three');
194194
3
195195
4
196196

197-
> SHOW MATERIALIZED VIEWS
198-
mv_e quickstart ""
199-
mv_f quickstart ""
197+
> SELECT name FROM mz_materialized_views
198+
mv_e
199+
mv_f
200200

201201
# RESTRICT works
202202
! DROP SOURCE table_e RESTRICT;
@@ -216,7 +216,7 @@ contains:cannot drop source "table_e": still depended upon by materialized view
216216
mz_source_progress progress
217217
table_g subsource
218218

219-
> SHOW MATERIALIZED VIEWS
219+
> SELECT name FROM mz_materialized_views
220220

221221
> DROP SOURCE table_g;
222222

test/pg-cdc/alter-source.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ INSERT INTO table_e VALUES (3, 'three');
203203
3
204204
4
205205

206-
> SHOW MATERIALIZED VIEWS
207-
mv_e quickstart ""
208-
mv_f quickstart ""
206+
> SELECT name FROM mz_materialized_views
207+
mv_e
208+
mv_f
209209

210210
# RESTRICT works
211211
! DROP TABLE table_e RESTRICT;
@@ -226,7 +226,7 @@ contains:cannot drop table "table_e": still depended upon by materialized view "
226226
> SHOW TABLES
227227
table_g ""
228228

229-
> SHOW MATERIALIZED VIEWS
229+
> SELECT name FROM mz_materialized_views
230230

231231
> DROP TABLE table_g;
232232

0 commit comments

Comments
 (0)