-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mssql): varchar params should not cause high cpu usage (#4918)
- Loading branch information
Showing
10 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/native/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod mssql; | ||
mod mysql; | ||
mod postgres; |
117 changes: 117 additions & 0 deletions
117
...-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/native/mssql.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use indoc::indoc; | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(only(SqlServer))] | ||
mod string { | ||
fn schema_string() -> String { | ||
let schema = indoc! { | ||
r#" | ||
model Parent { | ||
#id(id, Int, @id) | ||
vChar String @test.VarChar | ||
vChar40 String @test.VarChar(40) | ||
vCharMax String @test.VarChar(max) | ||
}"# | ||
}; | ||
|
||
schema.to_owned() | ||
} | ||
|
||
// Regression test for https://github.com/prisma/prisma/issues/17565 | ||
#[connector_test(schema(schema_string))] | ||
async fn native_string(mut runner: Runner) -> TestResult<()> { | ||
create_row( | ||
&runner, | ||
r#"{ | ||
id: 1, | ||
vChar: "0" | ||
vChar40: "0123456789012345678901234567890123456789" | ||
vCharMax: "0123456789" | ||
}"#, | ||
) | ||
.await?; | ||
|
||
insta::assert_snapshot!( | ||
run_query!(&runner, r#"{ findManyParent { | ||
id | ||
vChar | ||
vChar40 | ||
vCharMax | ||
}}"#), | ||
@r###"{"data":{"findManyParent":[{"id":1,"vChar":"0","vChar40":"0123456789012345678901234567890123456789","vCharMax":"0123456789"}]}}"### | ||
); | ||
|
||
// VARCHAR | ||
// Ensure the VarChar is casted to VARCHAR to avoid implicit coercion | ||
runner.clear_logs().await; | ||
insta::assert_snapshot!( | ||
run_query!(&runner, r#"{ findManyParent(where: { vChar: "0" }) { | ||
id | ||
vChar | ||
}}"#), | ||
@r###"{"data":{"findManyParent":[{"id":1,"vChar":"0"}]}}"### | ||
); | ||
assert!(runner | ||
.get_logs() | ||
.await | ||
.iter() | ||
.any(|log| log.contains("WHERE [string_native_string].[Parent].[vChar] = CAST(@P1 AS VARCHAR)"))); | ||
|
||
// VARCHAR(40) | ||
runner.clear_logs().await; | ||
insta::assert_snapshot!( | ||
run_query!(&runner, r#"{ findManyParent(where: { vChar40: "0123456789012345678901234567890123456789" }) { | ||
id | ||
vChar40 | ||
}}"#), | ||
@r###"{"data":{"findManyParent":[{"id":1,"vChar40":"0123456789012345678901234567890123456789"}]}}"### | ||
); | ||
|
||
// Ensure the VarChar(40) is casted to VARCHAR(40) to avoid implicit coercion | ||
assert!(runner | ||
.get_logs() | ||
.await | ||
.iter() | ||
.any(|log| log.contains("WHERE [string_native_string].[Parent].[vChar40] = CAST(@P1 AS VARCHAR(40))"))); | ||
|
||
// VARCHAR(MAX) | ||
runner.clear_logs().await; | ||
insta::assert_snapshot!( | ||
run_query!(&runner, r#"{ findManyParent(where: { vCharMax: "0123456789" }) { | ||
id | ||
vCharMax | ||
}}"#), | ||
@r###"{"data":{"findManyParent":[{"id":1,"vCharMax":"0123456789"}]}}"### | ||
); | ||
|
||
// Ensure the VarChar is casted to VARCHAR(MAX) to avoid implicit coercion | ||
assert!(runner | ||
.get_logs() | ||
.await | ||
.iter() | ||
.any(|log| log.contains("WHERE [string_native_string].[Parent].[vCharMax] = CAST(@P1 AS VARCHAR(MAX))"))); | ||
|
||
// Ensure it works as well with gt | ||
runner.clear_logs().await; | ||
insta::assert_snapshot!( | ||
run_query!(&runner, r#"{ findManyParent(where: { vChar40: { gt: "0" } }) { id vChar40 } }"#), | ||
@r###"{"data":{"findManyParent":[{"id":1,"vChar40":"0123456789012345678901234567890123456789"}]}}"### | ||
); | ||
assert!(runner | ||
.get_logs() | ||
.await | ||
.iter() | ||
.any(|log| log.contains("WHERE [string_native_string].[Parent].[vChar40] > CAST(@P1 AS VARCHAR(40))"))); | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn create_row(runner: &Runner, data: &str) -> TestResult<()> { | ||
runner | ||
.query(format!("mutation {{ createOneParent(data: {}) {{ id }} }}", data)) | ||
.await? | ||
.assert_success(); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,4 +331,8 @@ impl TestLogCapture { | |
|
||
logs | ||
} | ||
|
||
pub async fn clear_logs(&mut self) { | ||
while self.rx.try_recv().is_ok() {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters