-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qe: fix pathological behaviour with many @Uniques
The quaint AST lets users keep track of unique index definitions in tables in order to generate `MERGE` statements in SQL Server. The SQL query connector diligently adds every unique index to the table definitions in the `AsTable` implementation for models. The concrete method used to add the indexes is `Table::add_unique_index()`. Its space complexity is `O(n!)` on the number of unique indexes on a model, which quickly leads to high memory usage, then hanging and out-of-memory errors. See the inline comment in the commit for more details on what happened exactly, and how this commit fixes the problem. The included regression test would consistently take multiple minutes, then OOM on a fast desktop machine with 32GB of RAM before the fix. closes prisma/prisma#20799
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_20799.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,65 @@ | ||
use query_engine_tests::*; | ||
|
||
// before the fix to https://github.com/prisma/prisma/issues/20799, this test would consistently | ||
// run for multiple minutes and crash with an OOM error on a fast desktop machine with 32GB of RAM. | ||
#[test_suite(schema(schema), only(Sqlite))] | ||
mod regression { | ||
fn schema() -> String { | ||
indoc!( | ||
r#" | ||
model Connection { | ||
id Int @id @default(autoincrement()) | ||
uid String @unique | ||
ownerId Int | ||
atlassianOnPremiseOAuthCredentialsId Int? @unique | ||
bitbucketCloudOAuthCredentialsId Int? @unique | ||
genericAppCredentialsId Int? @unique | ||
gitlabOAuthCredentialsId Int? @unique | ||
googleSheetsOAuthCredentialsId Int? @unique | ||
githubOAuthCredentialsId Int? @unique | ||
mondayOAuthCredentialsId Int? @unique | ||
serviceNowOAuthCredentialsId Int? @unique | ||
bitbucketOnPremiseOAuthCredentialsId Int? @unique | ||
salesforceOAuthCredentialsId Int? @unique | ||
tempoCloudOAuthCredentialsId Int? @unique | ||
slackCredentialsId Int? | ||
jsmCloudAssetsApiKeyCredentialsId Int? @unique | ||
googleCalendarOAuthCredentialsId Int? @unique | ||
microsoftOAuthCredentialsId Int? @unique | ||
zoomOAuthCredentialsId Int? @unique | ||
statuspageApiKeyCredentialsId Int? @unique | ||
trelloApiKeyCredentialsId Int? @unique | ||
opsgenieApiKeyCredentialsId Int? @unique | ||
one Int? @unique | ||
two Int? @unique | ||
three Int? @unique | ||
four Int? @unique | ||
five Int? @unique | ||
six Int? @unique | ||
seven Int? @unique | ||
eight Int? @unique | ||
nine Int? @unique | ||
ten Int? @unique | ||
} | ||
"# | ||
) | ||
.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn repro(runner: Runner) -> TestResult<()> { | ||
let query = indoc!( | ||
r#" | ||
query { | ||
findManyConnection( | ||
where: { | ||
ownerId: 100, | ||
}, | ||
) { id } | ||
} | ||
"# | ||
); | ||
runner.query(query).await?.assert_success(); | ||
Ok(()) | ||
} | ||
} |