Skip to content

Commit 4f493e4

Browse files
Relax conditions for query pruning (#2873)
1 parent 1318e7e commit 4f493e4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

crates/core/src/subscription/module_subscription_actor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,9 @@ mod tests {
21892189
("b", AlgebraicType::U64),
21902190
],
21912191
&[0.into()],
2192-
&[0.into()],
2192+
// The join column for this table does not have to be unique,
2193+
// because pruning only requires us to probe the join index on `v`.
2194+
&[],
21932195
StAccess::Public,
21942196
)?;
21952197
let v_id = db.create_table_for_test_with_the_works(

crates/subscription/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use spacetimedb_execution::{
99
use spacetimedb_expr::check::SchemaView;
1010
use spacetimedb_lib::{identity::AuthCtx, metrics::ExecutionMetrics, query::Delta, AlgebraicValue};
1111
use spacetimedb_physical_plan::plan::{IxJoin, IxScan, Label, PhysicalPlan, ProjectPlan, Sarg, TableScan, TupleField};
12-
use spacetimedb_primitives::{ColId, IndexId, TableId};
12+
use spacetimedb_primitives::{ColId, ColList, IndexId, TableId};
1313
use spacetimedb_query::compile_subscription;
1414
use std::sync::Arc;
1515
use std::{collections::HashSet, ops::RangeBounds};
@@ -432,7 +432,6 @@ impl SubscriptionPlan {
432432
field_pos: rhs_join_col,
433433
..
434434
},
435-
unique: true,
436435
..
437436
},
438437
_,
@@ -445,7 +444,10 @@ impl SubscriptionPlan {
445444
..
446445
},
447446
_,
448-
) if schema.table_id != self.return_id && prefix.is_empty() => {
447+
) if schema.table_id != self.return_id
448+
&& prefix.is_empty()
449+
&& schema.is_unique(&ColList::new((*rhs_join_col).into())) =>
450+
{
449451
let lhs_table = self.return_id;
450452
let rhs_table = schema.table_id;
451453
let rhs_col = *rhs_col;

0 commit comments

Comments
 (0)