Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MariaDB - avoid using correlated sub-queries #14630

Merged
merged 11 commits into from
Sep 24, 2024

Conversation

mike12345567
Copy link
Collaborator

Description

This is a problem that was raised by our QA MariaDB database which was hitting a limit around how much data can be returned from an aggregate response - the JSON that was being returned was malformed and not performing as expected.

The issue was that we did not apply a limit to MySQL/MariaDB queries as it wasn't possible to limit these without the use of a correlated sub-query, something which is not allowed - information about this here.

To get around this we have used a limit which can be applied within the aggregation itself, avoiding the malformed response. This is not as performant as using a correlated sub-query, but we were very limited in terms of options and this gave us the best set of fixed problems while performing within acceptable limits.

…QL, it needs to wrap the query the same as all other DBs, however it needs to apply the where statement in a slightly different manner.
…her than using a limited sub-query which is dis-allowed in MySQL/MariaDB due to the nature of the correlated sub-query.
@mike12345567 mike12345567 self-assigned this Sep 23, 2024
@mike12345567 mike12345567 requested a review from a team as a code owner September 23, 2024 17:41
@mike12345567 mike12345567 requested review from samwho and removed request for a team September 23, 2024 17:41
@github-actions github-actions bot added firestorm Data/Infra/Revenue Team size/m labels Sep 23, 2024
… problem, this solves for it by separating them and allowing us to use the special json_arrayagg for mariaDB, but use a correlated sub-query for MySQL.
@@ -210,16 +210,27 @@ function buildDeleteTable(knex: SchemaBuilder, table: Table): SchemaBuilder {

class SqlTableQueryBuilder {
private readonly sqlClient: SqlClient
private extendedSqlClient: SqlClient | undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh how come this is necessary? Why can't we just use sqlClient?

Copy link
Collaborator Author

@mike12345567 mike12345567 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to know that the implementation/dialect is MY_SQL - but also its MariaDB - for Knex it needs to know its MySQL, technically we could get around this by setting everywhere that needs to know its MySQL based on it being MariaDB when needed, but I like the idea of separating the difference in client here, since its still a MySQL datasource, it just reads a different version once it connects.

@mike12345567 mike12345567 changed the title MySQL - avoid using correlated sub-queries MariaDB - avoid using correlated sub-queries Sep 24, 2024
@mike12345567 mike12345567 merged commit d555b68 into master Sep 24, 2024
12 checks passed
@mike12345567 mike12345567 deleted the fix/mysql-correlated-queries branch September 24, 2024 13:15
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
firestorm Data/Infra/Revenue Team size/m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants