go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
264 stars 56 forks source link

full text query macth not work #139

Open foolishlittlefox opened 10 months ago

foolishlittlefox commented 10 months ago
_ = db.Use(sharding.Register(sharding.Config{
        ShardingKey:         "ymd",
        NumberOfShards:      100,
        PrimaryKeyGenerator: sharding.PKCustom,
        ShardingAlgorithm: func(columnValue any) (suffix string, err error) {
            parentId := cast.ToInt(columnValue)
            suffix = fmt.Sprintf("_%v", parentId)
            return
        },
        PrimaryKeyGeneratorFn: func(tableIdx int64) int64 {
            return 0
        },
        // This case for show up give notifications, audit_logs table use same sharding rule.
    }, ChatMsg{}))

qb.Where(fmt.Sprintf("(MATCH(body) AGAINST('%s'))", req.Key))

can not fond table

huacnlee commented 10 months ago

All query must include the sharding key.

You have used ymd column as the sharding key, but there is not include in there where conditions.

foolishlittlefox commented 10 months ago

This is the complete sql statement

SELECT * FROM t_chat_msg WHERE ymd = 202311 AND to = '1025359' AND (MATCH(body) AGAINST('在' IN BOOLEAN MODE)) LIMIT 20

I found that it should be caused by the sqlparser package not being able to correctly parse SQL statements.

foolishlittlefox commented 10 months ago

It should be that this statement was not parsed successfully. expr, err := sqlparser.NewParser(strings.NewReader(query)).ParseStatement()

huacnlee commented 10 months ago

@hyperphoton 这个应该是 SQLParser 解析不了