Skip to content

Commit 9da2794

Browse files
goffrieConvex, Inc.
authored andcommitted
Fix multitenant mysql index query (#41150)
GitOrigin-RevId: 3796198119631f38b60ed3d600c785fb8df53e83
1 parent a248d3b commit 9da2794

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/mysql/src/sql.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,19 @@ static INDEX_QUERIES: LazyLock<[HashMap<(BoundType, BoundType, Order), String>;
668668
let (
669669
select_instance_col,
670670
group_by_instance,
671-
join_instance_cond,
671+
join_instance_i1,
672+
join_instance_snapshot,
672673
doc_join_instance_cond,
673674
) = if *multitenant {
674675
(
675676
"I1.instance_name, ",
676677
"instance_name, ",
677678
"I1.instance_name, ",
679+
"snapshot.instance_name, ",
678680
"D.instance_name = I2.instance_name AND ",
679681
)
680682
} else {
681-
("", "", "", "")
683+
("", "", "", "", "")
682684
};
683685

684686
let query = format!(
@@ -699,7 +701,7 @@ SELECT I2.index_id, I2.key_prefix, I2.key_sha256, I2.key_suffix, I2.ts, I2.delet
699701
) snapshot
700702
LEFT JOIN @db_name.indexes I1 FORCE INDEX FOR JOIN (PRIMARY)
701703
ON
702-
({join_instance_cond}I1.index_id, I1.key_prefix, I1.key_sha256, I1.ts) = ({join_instance_cond}snapshot.index_id, snapshot.key_prefix, snapshot.key_sha256, snapshot.ts_at_snapshot)
704+
({join_instance_i1}I1.index_id, I1.key_prefix, I1.key_sha256, I1.ts) = ({join_instance_snapshot}snapshot.index_id, snapshot.key_prefix, snapshot.key_sha256, snapshot.ts_at_snapshot)
703705
) I2
704706
LEFT JOIN @db_name.documents D FORCE INDEX FOR JOIN (PRIMARY)
705707
ON

0 commit comments

Comments
 (0)