Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,16 @@ impl Coordinator {
// We don't have any way to "duplicate" the read hold of the actual collection, which we
// obtain below... but the current implementation of read holds guarantees that the storage
// holds we obtain here will not be any greater than the hold we actually want.
let read_holds =
Some(self.acquire_read_holds(&dataflow_import_id_bundle(&plan, mview.cluster_id)));
//
// We hold only the plan's storage imports, whose persist part stats the pushdown
// explanation reads. We must not acquire holds on the plan's compute imports: an index
// that the materialized view was planned against can be dropped while the view keeps
// running, and a dropped index no longer has a compute collection to hold.
let id_bundle = CollectionIdBundle {
storage_ids: plan.source_imports.keys().copied().collect(),
compute_ids: BTreeMap::new(),
};
let read_holds = Some(self.acquire_read_holds(&id_bundle));

let frontiers = self
.controller
Expand Down
21 changes: 21 additions & 0 deletions test/sqllogictest/explain/pushdown.slt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ EXPLAIN FILTER PUSHDOWN FOR MATERIALIZED VIEW big_numbers
----
materialize.public.numbers 1313 0 1 0

# Regression test for a panic (SQL-519): EXPLAIN FILTER PUSHDOWN FOR
# MATERIALIZED VIEW panicked with "missing compute collection" when the view's
# plan imported an index that was dropped after the view was created. The
# dropped index no longer has a compute collection, but the view's dataflow
# keeps running and reading from it.

statement ok
CREATE INDEX numbers_value_idx ON numbers (value);

statement ok
CREATE MATERIALIZED VIEW indexed_numbers AS SELECT * FROM numbers WHERE value > 10000;

statement ok
DROP INDEX numbers_value_idx;

# The view's plan reads entirely from the (dropped) index, so there are no
# storage imports to report stats for.
query TIIII
EXPLAIN FILTER PUSHDOWN FOR MATERIALIZED VIEW indexed_numbers
----

# EXPLAIN FILTER PUSHDOWN should work even if there are no replicas.
statement ok
CREATE CLUSTER no_replicas (SIZE 'scale=1,workers=1', REPLICATION FACTOR 0);
Expand Down
Loading