Skip to content

Commit 94a226b

Browse files
authored
feat: return a can_assume_strict_equality for in-memory joins (#5785)
[TML-1868](https://linear.app/prisma-company/issue/TML-1868/fix-mysql-bigint-relation-issue) /prisma-branch fix/strict-equality-joins Client PR: prisma/prisma#29251 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Joins now carry a flag to enable stricter equality assumptions when supported, improving cross-database join handling. * Validation expressions include richer context for clearer error reporting. * **Chores** * Connector implementations updated to advertise support for strict-equality joins where applicable, enabling optimized query generation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c6be8e6 commit 94a226b

9 files changed

Lines changed: 33 additions & 2 deletions

File tree

psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ impl Connector for CockroachDatamodelConnector {
355355
None => self.parse_json_bytes(str, Some(NativeTypeInstance::new::<CockroachType>(BYTES_DEFAULT))),
356356
}
357357
}
358+
359+
fn can_assume_strict_equality_in_joins(&self) -> bool {
360+
true
361+
}
358362
}
359363

360364
/// An `@default(sequence())` function.

psl/psl-core/src/builtin_connectors/mongodb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ impl Connector for MongoDbDatamodelConnector {
167167
fn flavour(&self) -> Flavour {
168168
Flavour::Mongo
169169
}
170+
171+
fn can_assume_strict_equality_in_joins(&self) -> bool {
172+
true
173+
}
170174
}

psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ impl Connector for MsSqlDatamodelConnector {
300300
fn does_manage_udts(&self) -> bool {
301301
true
302302
}
303+
304+
fn can_assume_strict_equality_in_joins(&self) -> bool {
305+
true
306+
}
303307
}
304308

305309
/// A collection of types stored outside of the row to the heap, having

psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ impl Connector for PostgresDatamodelConnector {
659659
None => self.parse_json_bytes(str, Some(NativeTypeInstance::new(PostgresType::Known(BYTES_DEFAULT)))),
660660
}
661661
}
662+
663+
fn can_assume_strict_equality_in_joins(&self) -> bool {
664+
true
665+
}
662666
}
663667

664668
fn allowed_index_operator_classes(algo: IndexAlgorithm, field: walkers::ScalarFieldWalker<'_>) -> Vec<OperatorClass> {

psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ impl Connector for SqliteDatamodelConnector {
126126
fn flavour(&self) -> Flavour {
127127
Flavour::Sqlite
128128
}
129+
130+
fn can_assume_strict_equality_in_joins(&self) -> bool {
131+
true
132+
}
129133
}

psl/psl-core/src/datamodel_connector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ pub trait Connector: Send + Sync {
309309
fn does_manage_udts(&self) -> bool {
310310
false
311311
}
312+
313+
fn can_assume_strict_equality_in_joins(&self) -> bool {
314+
false
315+
}
312316
}
313317

314318
#[derive(Copy, Clone, Debug, PartialEq)]

query-compiler/query-compiler/src/expression.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ pub enum Expression {
8383
Required(Box<Expression>),
8484

8585
/// Application-level join.
86+
#[serde(rename_all = "camelCase")]
8687
Join {
8788
parent: Box<Expression>,
8889
children: Vec<JoinExpression>,
90+
can_assume_strict_equality: bool,
8991
},
9092

9193
/// Get a field from a record or records. If the argument is a list of records,
@@ -103,6 +105,7 @@ pub enum Expression {
103105
},
104106

105107
/// Validates the expression according to the data rule and throws an error if it doesn't match.
108+
#[serde(rename_all = "camelCase")]
106109
Validate {
107110
expr: Box<Expression>,
108111
rules: Vec<DataRule>,
@@ -194,7 +197,7 @@ impl Expression {
194197
Expression::Required(expr) => {
195198
expr.simplify();
196199
}
197-
Expression::Join { parent, children } => {
200+
Expression::Join { parent, children, .. } => {
198201
parent.simplify();
199202
children.iter_mut().for_each(|child| child.child.simplify());
200203
}

query-compiler/query-compiler/src/expression/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
Expression::Concat(vec) => self.function("concat", vec),
6060
Expression::Unique(expression) => self.unary_function("unique", expression),
6161
Expression::Required(expression) => self.unary_function("required", expression),
62-
Expression::Join { parent, children } => self.join(parent, children),
62+
Expression::Join { parent, children, .. } => self.join(parent, children),
6363
Expression::MapField { field, records } => self.map_field(field, records),
6464
Expression::Transaction(expression) => self.transaction(expression),
6565
Expression::DataMap { expr, structure, enums } => self.data_map(expr, structure, enums),

query-compiler/query-compiler/src/translate/query/read.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ pub(super) fn add_inmemory_join(
143143
})
144144
.collect();
145145

146+
let can_assume_strict_equality = nested
147+
.iter()
148+
.all(|nested| nested.model().dm.schema.connector.can_assume_strict_equality_in_joins());
146149
let join_expressions = nested
147150
.into_iter()
148151
.filter_map(|nested| match nested {
@@ -197,6 +200,7 @@ pub(super) fn add_inmemory_join(
197200
name: binding::join_parent(),
198201
}),
199202
children: join_expressions,
203+
can_assume_strict_equality,
200204
}),
201205
}),
202206
})

0 commit comments

Comments
 (0)