go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
276 stars 60 forks source link

does gorm sharding support JOIN ? #126

Open nkr-404-NotFound opened 1 year ago

nkr-404-NotFound commented 1 year ago

Your Question

in project when i use gorm sharding and my SQL contains JOIN, like A.col1, B.col2 the query will fail. the query trys to find the main table instead of sub table

The document you expected this should be explained

Expected answer

any help ? thanks

nkr-404-NotFound commented 1 year ago
image

use a.col in sql in select section not from section , found that table name not replaces by sub table name

nkr-404-NotFound commented 1 year ago
image

in join sql , here stmt.fromItems's type is func (JoinClause) source(), not func (TableName) source()

so currently , no join sql can be processed correctly

jiekun commented 1 year ago

We've done it couple years ago. check it here: https://github.com/go-gorm/sharding/pull/15 This repo aims to support both PG and MySQL. So it cannot be merged.

steve-hb commented 1 year ago

I just looked at the before mentioned PR and started looking for alternatives to sqlparser, but I can't find one actively maintained. Also I just looked into gorm and found gorm to build everything itself. Do I miss/not find something?

jiekun commented 1 year ago

I just looked at the before mentioned PR and started looking for alternatives to sqlparser, but I can't find one actively maintained. Also I just looked into gorm and found gorm to build everything itself. Do I miss/not find something?

Just try https://github.com/pingcap/parser . BTW I think a SQL parser doesn't need to be updated frequently. It should just remain as stable as possible.