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

Sharding does not work with QualifiedRef ( which is the what the autogenerated dal does ) #172

Open
omer9564 opened this issue Aug 14, 2024 · 0 comments
Assignees

Comments

@omer9564
Copy link

omer9564 commented Aug 14, 2024

GORM Playground Link

https://github.com/omer9564/gorm-playground-sharding-issue

Description

I'm trying to use sharding combined with the autogenerated dal in gorm.
The autogenerated dal generates query that looks as:

SELECT * 
FROM `toys` 
WHERE `toys`.`name` = "shard1" AND `toys`.`owner_type` = "dummy" AND `toys`.`deleted_at` IS NULL ORDER BY `toys`.`id` LIMIT 1

In this commit @Gowa2017 fixed the "finding" whether or not there is a filter for the sharding column, but there is another issue.
This query is changed into

SELECT * 
FROM `toys_shard1` 
WHERE `toys`.`name` = "shard1" AND `toys`.`owner_type` = "dummy" AND `toys`.`deleted_at` IS NULL ORDER BY `toys`.`id` LIMIT 1

After the sharding plugin changes it, it then gets the error no such column: toys.name because the plugin doesn't change the where clauses.
I managed to trace back the actual error to this code.

I thought on a quick fix which is changing the from table but adding an "AS <origin_table>".

Don't mind to contribute this, I guess that it is simple as adding an alias like

newTable := &sqlparser.TableName{Name: &sqlparser.Ident{Name: tableName + suffix}, Alias: tableName}

Anyway would love a second eye on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants