Skip to content

Commit fa7b3d1

Browse files
authored
[observability] fix EXPLAIN ANALYZE to work on objects that are not in a database (#34216)
@ggevay noticed that `EXPLAIN ANALYZE CPU FOR INDEX mz_internal.mz_console_cluster_utilization_overview_ind;` was returning empty results. It turns out that `mz_internal.mz_mappable_objects` assumed that every object it worked with lived in a database, but this is not the case for objects in `mz_internal`. Changing the join on `mz_databases` to be a `LEFT JOIN` should resolve the issue. I did not bother doing something similar for the schema, as I believe every object must live in a schema. I extended the `EXPLAIN ANALYZE` testdrive to account for this bug. ### Motivation * This PR fixes a recognized bug. Original message: https://materializeinc.slack.com/archives/C08ACQNGSQK/p1763565268661699 Follow-up thread: https://materializeinc.slack.com/archives/C08ACQNGSQK/p1763565268661699 ### Checklist - [ ] This PR has adequate test coverage / QA involvement has been duly considered. ([trigger-ci for additional test/nightly runs](https://trigger-ci.dev.materialize.com/)) - [ ] This PR has an associated up-to-date [design doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md), is a design doc ([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)), or is sufficiently small to not require a design. <!-- Reference the design in the description. --> - [ ] If this PR evolves [an existing `$T ⇔ Proto$T` mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md) (possibly in a backwards-incompatible way), then it is tagged with a `T-proto` label. - [ ] If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label ([example](MaterializeInc/cloud#5021)). <!-- Ask in #team-cloud on Slack if you need help preparing the cloud PR. --> - [ ] If this PR includes major [user-facing behavior changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note), I have pinged the relevant PM to schedule a changelog post.
1 parent 66d8f67 commit fa7b3d1

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

src/catalog/src/builtin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6174,12 +6174,12 @@ pub static MZ_MAPPABLE_OBJECTS: LazyLock<BuiltinView> = LazyLock::new(|| {
61746174
("global_id", "The global ID of the object."),
61756175
]),
61766176
sql: "
6177-
SELECT quote_ident(md.name) || '.' || quote_ident(ms.name) || '.' || quote_ident(mo.name) AS name, mgi.global_id AS global_id
6177+
SELECT COALESCE(quote_ident(md.name) || '.', '') || quote_ident(ms.name) || '.' || quote_ident(mo.name) AS name, mgi.global_id AS global_id
61786178
FROM mz_catalog.mz_objects mo
6179-
JOIN mz_introspection.mz_compute_exports mce ON (mo.id = mce.export_id)
6180-
JOIN mz_catalog.mz_schemas ms ON (mo.schema_id = ms.id)
6181-
JOIN mz_catalog.mz_databases md ON (ms.database_id = md.id)
6182-
JOIN mz_introspection.mz_dataflow_global_ids mgi ON (mce.dataflow_id = mgi.id);",
6179+
JOIN mz_introspection.mz_compute_exports mce ON (mo.id = mce.export_id)
6180+
JOIN mz_catalog.mz_schemas ms ON (mo.schema_id = ms.id)
6181+
JOIN mz_introspection.mz_dataflow_global_ids mgi ON (mce.dataflow_id = mgi.id)
6182+
LEFT JOIN mz_catalog.mz_databases md ON (ms.database_id = md.id);",
61836183
access: vec![PUBLIC_SELECT],
61846184
}
61856185
});

test/testdrive/explain-analyze.td

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# the Business Source License, use of this software will be governed
88
# by the Apache License, Version 2.0.
99

10-
$ set-regex match=((\d+)\sbytes|u(\d+)|(\d+:\d+:\d+.\d+)) replacement=<XXX>
10+
$ set-regex match=((\d+)\sbytes|u(\d+)|s(\d+)|(\d+:\d+:\d+(.\d+)?)) replacement=<XXX>
1111

1212
# In case the environment has other replicas
1313
> SET cluster_replica = r1
@@ -58,3 +58,77 @@ operator total_memory total_records
5858
object global_id total_elapsed
5959
------------------------------------------------------
6060
materialize.blue.t_idx <XXX> <XXX>
61+
62+
# ensure we can explain mz_internal objects
63+
64+
> SET CLUSTER = mz_catalog_server;
65+
66+
> EXPLAIN ANALYZE CPU FOR INDEX mz_internal.mz_console_cluster_utilization_overview_ind;
67+
operator total_elapsed
68+
-----------------------------------------
69+
"Arrange (#17{cluster_id})" <XXX>
70+
" Stream <XXX>" <null>
71+
"Returning Map/Filter/Project" <XXX>
72+
" Union" <XXX>
73+
" Read l4" <XXX>
74+
" Map/Filter/Project" <XXX>
75+
" Consolidating Union" <XXX>
76+
" Read l3" <XXX>
77+
" Negate Diffs" <XXX>
78+
" Read l4" <XXX>
79+
"With l4 = Differential Join %1 » %0" <XXX>
80+
" Arrange (#1, #0)" <XXX>
81+
" Non-incremental GroupAggregate`" <XXX>
82+
" Arranged <XXX>" <XXX>
83+
" Arrange (#0{replica_id}, #3{bucket_start})" <XXX>
84+
" Stream l3" <null>
85+
"l3 = Differential Join %1 » %0" <XXX>
86+
" Arrange (#0, #1)" <XXX>
87+
" Map/Filter/Project" <XXX>
88+
" Non-monotonic TopK" <XXX>
89+
" Differential Join %1 » %0" <XXX>
90+
" Arranged <XXX>" <null>
91+
" Arrange (#0{replica_id})" <XXX>
92+
" Distinct GroupAggregate" <XXX>
93+
" Read l2" <XXX>
94+
" Arrange (#0, #3)" <XXX>
95+
" Stream l2" <null>
96+
"l2 = Delta Join [%0 » %1 » %2 » %3 » %4 » %5][%1 » %0 » %2 » %3 » %4 » %5][%2 » %0 » %1 » %3 » %4 » %5][%3 » %0 » %1 » %2 » %4 » %5][%4 » %0 » %1 » %2 » %3 » %5][%5 » %0 » %1 » %2 » %3 » %4]" <XXX>
97+
" Arrange (#0{replica_id})" <XXX>
98+
" Arranged l0" <null>
99+
" Arrange (#0{replica_id}, #3{bucket_start})" <XXX>
100+
" Map/Filter/Project" <XXX>
101+
" Non-monotonic TopK" <XXX>
102+
" Read l1" <XXX>
103+
" Arrange (#0{replica_id}, #4{bucket_start})" <XXX>
104+
" Map/Filter/Project" <XXX>
105+
" Non-monotonic TopK" <XXX>
106+
" Read l1" <XXX>
107+
" Arrange (#0{replica_id}, #3{bucket_start})" <XXX>
108+
" Map/Filter/Project" <XXX>
109+
" Non-monotonic TopK" <XXX>
110+
" Read l1" <XXX>
111+
" Arrange (#0{replica_id}, #3{bucket_start})" <XXX>
112+
" Map/Filter/Project" <XXX>
113+
" Non-monotonic TopK" <XXX>
114+
" Read l1" <XXX>
115+
" Arrange (#0{replica_id}) (#0{replica_id}, #3{bucket_start})" <XXX>
116+
" Map/Filter/Project" <XXX>
117+
" Non-monotonic TopK" <XXX>
118+
" Read l1" <XXX>
119+
"l1 = Differential Join %0 » %1" <XXX>
120+
" Arrange (#1{replica_id})" <XXX>
121+
" Map/Filter/Project" <XXX>
122+
" Accumulable GroupAggregate" <XXX>
123+
" Map/Filter/Project" <XXX>
124+
" Delta Join [%0 » %2 » %1][%1 » %0 » %2][%2 » %0 » %1]" <XXX>
125+
" Arranged <XXX>" <null>
126+
" Arranged <XXX>" <null>
127+
" Arrange (#0{replica_id}) (#1{size})" <XXX>
128+
" Arranged l0" <XXX>
129+
" Arrange (#0{replica_id})" <XXX>
130+
" Arranged l0" <XXX>
131+
"l0 = Distinct GroupAggregate" <XXX>
132+
" Union" <XXX>
133+
" Arranged <XXX>" <XXX>
134+
" Arranged <XXX>" <XXX>

0 commit comments

Comments
 (0)