Skip to content

Commit 2ecb80d

Browse files
committed
adapter: add enable_mz_notices feature flag
Gate tracking of optimizer notices in the catalog behind a feature flag.
1 parent 57ee8f8 commit 2ecb80d

File tree

7 files changed

+89
-53
lines changed

7 files changed

+89
-53
lines changed

misc/python/materialize/checks/all_checks/optimizer_notices.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,30 @@
1313
from materialize.checks.executors import Executor
1414
from materialize.mz_version import MzVersion
1515

16-
SCHEMA = "check_optimzier_notices"
17-
1816

1917
class OptimizerNotices(Check):
18+
SCHEMA = "check_optimzier_notices"
19+
2020
def _can_run(self, e: Executor) -> bool:
2121
return self.base_version >= MzVersion.parse_mz("v0.80.0-dev")
2222

2323
def initialize(self) -> Testdrive:
2424
return Testdrive(
2525
dedent(
2626
"""
27+
$postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
28+
ALTER SYSTEM SET enable_mz_notices = true
2729
> DROP SCHEMA IF EXISTS {sch} CASCADE;
2830
> CREATE SCHEMA {sch};
2931
> CREATE TABLE {sch}.t1(x INTEGER, y INTEGER);
3032
> CREATE INDEX t1_idx ON {sch}.t1(x, y);
3133
"""
32-
).format(sch=SCHEMA)
34+
).format(sch=self.__class__.SCHEMA)
3335
)
3436

3537
def manipulate(self) -> list[Testdrive]:
3638
return [
37-
Testdrive(dedent(s).format(sch=SCHEMA))
39+
Testdrive(dedent(s).format(sch=self.__class__.SCHEMA))
3840
for s in [
3941
"""
4042
# emits one "index too wide" notice

src/adapter/src/catalog.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,14 @@ impl Catalog {
11961196

11971197
for id in drop_ids {
11981198
if let Some(df_meta) = self.try_get_dataflow_metainfo(&id) {
1199-
// Generate retractions for the Builtin tables.
1200-
self.pack_optimizer_notices(
1201-
&mut builtin_table_updates,
1202-
df_meta.optimizer_notices.iter(),
1203-
-1,
1204-
);
1199+
if self.state().system_config().enable_mz_notices() {
1200+
// Generate retractions for the Builtin tables.
1201+
self.pack_optimizer_notices(
1202+
&mut builtin_table_updates,
1203+
df_meta.optimizer_notices.iter(),
1204+
-1,
1205+
);
1206+
}
12051207
}
12061208
// Drop in-memory planning metadata.
12071209
self.drop_plans_and_metainfos(id);

src/adapter/src/coord.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,12 +1312,14 @@ impl Coordinator {
13121312
.try_get_dataflow_metainfo(&entry.id())
13131313
.expect("added in `bootstrap_dataflow_plans`");
13141314

1315-
// Collect optimization hint updates.
1316-
self.catalog().pack_optimizer_notices(
1317-
&mut builtin_table_updates,
1318-
df_meta.optimizer_notices.iter(),
1319-
1,
1320-
);
1315+
if self.catalog().state().system_config().enable_mz_notices() {
1316+
// Collect optimization hint updates.
1317+
self.catalog().pack_optimizer_notices(
1318+
&mut builtin_table_updates,
1319+
df_meta.optimizer_notices.iter(),
1320+
1,
1321+
);
1322+
}
13211323

13221324
// What follows is morally equivalent to `self.ship_dataflow(df, idx.cluster_id)`,
13231325
// but we cannot call that as it will also downgrade the read hold on the index.
@@ -1356,12 +1358,14 @@ impl Coordinator {
13561358
.try_get_dataflow_metainfo(&entry.id())
13571359
.expect("added in `bootstrap_dataflow_plans`");
13581360

1359-
// Collect optimization hint updates.
1360-
self.catalog().pack_optimizer_notices(
1361-
&mut builtin_table_updates,
1362-
df_meta.optimizer_notices.iter(),
1363-
1,
1364-
);
1361+
if self.catalog().state().system_config().enable_mz_notices() {
1362+
// Collect optimization hint updates.
1363+
self.catalog().pack_optimizer_notices(
1364+
&mut builtin_table_updates,
1365+
df_meta.optimizer_notices.iter(),
1366+
1,
1367+
);
1368+
}
13651369

13661370
self.ship_dataflow(df_desc, mview.cluster_id).await;
13671371
}

src/adapter/src/coord/sequencer/inner.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,20 +1063,6 @@ impl Coordinator {
10631063
.catalog_mut()
10641064
.set_dataflow_metainfo(id, df_meta.clone());
10651065

1066-
// Initialize a container for builtin table updates.
1067-
let mut builtin_table_updates = Vec::with_capacity(df_meta.optimizer_notices.len());
1068-
// Collect optimization hint updates.
1069-
coord.catalog().pack_optimizer_notices(
1070-
&mut builtin_table_updates,
1071-
df_meta.optimizer_notices.iter(),
1072-
1,
1073-
);
1074-
// Write collected optimization hints to the builtin tables.
1075-
let builtin_updates_fut = coord
1076-
.builtin_table_update()
1077-
.execute(builtin_table_updates)
1078-
.await;
1079-
10801066
// Announce the creation of the materialized view source.
10811067
coord
10821068
.controller
@@ -1100,9 +1086,29 @@ impl Coordinator {
11001086
.initialize_storage_read_policies(vec![id], CompactionWindow::Default)
11011087
.await;
11021088

1103-
let ship_dataflow_fut = coord.ship_dataflow(df_desc, cluster_id);
1089+
if coord.catalog().state().system_config().enable_mz_notices() {
1090+
// Initialize a container for builtin table updates.
1091+
let mut builtin_table_updates =
1092+
Vec::with_capacity(df_meta.optimizer_notices.len());
1093+
// Collect optimization hint updates.
1094+
coord.catalog().pack_optimizer_notices(
1095+
&mut builtin_table_updates,
1096+
df_meta.optimizer_notices.iter(),
1097+
1,
1098+
);
1099+
// Write collected optimization hints to the builtin tables.
1100+
let builtin_updates_fut = coord
1101+
.builtin_table_update()
1102+
.execute(builtin_table_updates)
1103+
.await;
1104+
1105+
let ship_dataflow_fut = coord.ship_dataflow(df_desc, cluster_id);
11041106

1105-
let ((), ()) = futures::future::join(builtin_updates_fut, ship_dataflow_fut).await;
1107+
let ((), ()) =
1108+
futures::future::join(builtin_updates_fut, ship_dataflow_fut).await;
1109+
} else {
1110+
coord.ship_dataflow(df_desc, cluster_id).await;
1111+
}
11061112
})
11071113
.await;
11081114

@@ -1214,23 +1220,28 @@ impl Coordinator {
12141220
.catalog_mut()
12151221
.set_dataflow_metainfo(id, df_meta.clone());
12161222

1217-
// Initialize a container for builtin table updates.
1218-
let mut builtin_table_updates = Vec::with_capacity(df_meta.optimizer_notices.len());
1219-
// Collect optimization hint updates.
1220-
coord.catalog().pack_optimizer_notices(
1221-
&mut builtin_table_updates,
1222-
df_meta.optimizer_notices.iter(),
1223-
1,
1224-
);
1225-
// Write collected optimization hints to the builtin tables.
1226-
let builtin_updates_fut = coord
1227-
.builtin_table_update()
1228-
.execute(builtin_table_updates)
1229-
.await;
1223+
if coord.catalog().state().system_config().enable_mz_notices() {
1224+
// Initialize a container for builtin table updates.
1225+
let mut builtin_table_updates =
1226+
Vec::with_capacity(df_meta.optimizer_notices.len());
1227+
// Collect optimization hint updates.
1228+
coord.catalog().pack_optimizer_notices(
1229+
&mut builtin_table_updates,
1230+
df_meta.optimizer_notices.iter(),
1231+
1,
1232+
);
1233+
// Write collected optimization hints to the builtin tables.
1234+
let builtin_updates_fut = coord
1235+
.builtin_table_update()
1236+
.execute(builtin_table_updates)
1237+
.await;
12301238

1231-
let ship_dataflow_fut = coord.ship_dataflow(df_desc, cluster_id);
1239+
let ship_dataflow_fut = coord.ship_dataflow(df_desc, cluster_id);
12321240

1233-
futures::future::join(builtin_updates_fut, ship_dataflow_fut).await;
1241+
futures::future::join(builtin_updates_fut, ship_dataflow_fut).await;
1242+
} else {
1243+
coord.ship_dataflow(df_desc, cluster_id).await;
1244+
}
12341245

12351246
coord.set_index_options(id, options).expect("index enabled");
12361247
})

src/sql/src/session/vars.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,13 @@ feature_flags!(
21342134
internal: true,
21352135
enable_for_item_parsing: true,
21362136
},
2137+
{
2138+
name: enable_mz_notices,
2139+
desc: "Populate the contents of `mz_internal.mz_notices`",
2140+
default: true,
2141+
internal: true,
2142+
enable_for_item_parsing: false,
2143+
},
21372144
);
21382145

21392146
/// Represents the input to a variable.

test/sqllogictest/transform/notice/index_key_empty.slt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ ALTER SYSTEM SET enable_table_keys = true
1212
----
1313
COMPLETE 0
1414

15+
simple conn=mz_system,user=mz_system
16+
ALTER SYSTEM SET enable_mz_notices = true
17+
----
18+
COMPLETE 0
19+
1520
statement ok
1621
CREATE TABLE t (
1722
a int,

test/sqllogictest/transform/notice/index_too_wide_for_literal_constraints.slt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ ALTER SYSTEM SET enable_table_keys = true
1414
----
1515
COMPLETE 0
1616

17+
simple conn=mz_system,user=mz_system
18+
ALTER SYSTEM SET enable_mz_notices = true
19+
----
20+
COMPLETE 0
21+
1722
statement ok
1823
CREATE TABLE t6(x int, y int, z int, w text);
1924

0 commit comments

Comments
 (0)