go-gorm / sharding

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

When DoubleWrite is on, is the query also run twice? #115

Open unix2dos opened 1 year ago

unix2dos commented 1 year ago

Your Question

func (pool ConnPool) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
    ftQuery, stQuery, table, err := pool.sharding.resolve(query, args...)
    if err != nil {
        return nil, err
    }

    pool.sharding.querys.Store("last_query", stQuery)

    if table != "" {
        if r, ok := pool.sharding.configs[table]; ok {
            if r.DoubleWrite {
                pool.ConnPool.ExecContext(ctx, ftQuery, args...)
            }
        }
    }

    return pool.ConnPool.QueryContext(ctx, stQuery, args...)
}

The document you expected this should be explained

Expected answer