-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
…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.
…dibase into fix/mysql-correlated-queries
… 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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
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.