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

[BUG]: TiDB Driver Generates Unsupported LEFT JOIN LATERAL Queries in Relational Query #3623

Open
1 task done
inaridiy opened this issue Nov 26, 2024 · 3 comments
Open
1 task done
Labels
bug Something isn't working driver/tidb rqb relational queries

Comments

@inaridiy
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.35.3

What version of drizzle-kit are you using?

0.26.2

Other packages

@tidbcloud/[email protected]

Describe the Bug

When using DrizzleORM to perform a relational query with TiDB, SQL containing LEFT JOIN LATERAL is automatically generated, leading to a syntax error in TiDB. Since TiDB does not support LATERAL joins, the query fails.

Undesired Behavior

Starting from [email protected], DrizzleORM generates LEFT JOIN LATERAL in relational query SQL. However, this syntax is not supported by TiDB, causing a syntax error.

Reference: DrizzleORM v0.28.0 release notes

Expected Behavior

For TiDB, queries should be generated without using LEFT JOIN LATERAL, similar to how the MySQL2 driver operates in Planetscale mode.

I think it might be a good idea to enable Planetscale mode in the TiDB driver internally, but I'm not sure. I am just now calling mysql-core code!

@inaridiy inaridiy added the bug Something isn't working label Nov 26, 2024
@inaridiy inaridiy changed the title [BUG]: ORM generates unsupported LEFT JOIN LATERAL queries for TiDB, causing SyntaxError [BUG]: TiDB Driver Generates Unsupported LEFT JOIN LATERAL Queries in Relational Query Nov 26, 2024
@inaridiy
Copy link
Author

It would be good to change the last argument of TiDBServerlessDatabase from default to plansclae. I'm using the forced replacement for now, but it works fine.

I'll build a PR later.

const session = new TiDBServerlessSession(client, dialect, undefined, schema, { logger });
const db = new TiDBServerlessDatabase(dialect, session, schema as any, 'default') as TiDBServerlessDatabase<TSchema>;
(<any> db).$client = client;

@inaridiy
Copy link
Author

PR opened #3629

@L-Mario564 L-Mario564 added driver/tidb rqb relational queries labels Nov 28, 2024
@inaridiy
Copy link
Author

Happy new year

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working driver/tidb rqb relational queries
Projects
None yet
Development

No branches or pull requests

2 participants