如何在锡拉和go中查询带偏移量的限制

pod7payv  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(270)

使用 gocql 或者 gocqlx ,没有获取第n页的示例:

CREATE TABLE IF NOT EXISTS users (
    id    BIGINT, -- unique using distributed synchronous counter (redis-like), since Scylla doesn't support RETURNING on counter
    email TEXT, -- to enforce uniqueness
    PRIMARY KEY(email)
);
CREATE INDEX IF NOT EXISTS ON users(id);

查询功能:

func QueryRows(cql string) (res []M.SX) { // M.SX is map[string]interface{}
    q := Database.Query(cql) // database is the connection to scylla
    defer q.Release()
    res = []M.SX{}
    iter := q.Iter()
    for {
        row := M.SX{}
        if !iter.MapScan(row) {
            break
        }
        res = append(res, row)
    }
    return
}

有没有简单但性能好(没有 ALLOW FILTERING )取第n页(按顺序) email 或者 id )?

SELECT * FROM users WHERE id > 44 LIMIT 10 ALLOW FILTERING; 
-- eg. 44 is last id of current page
1l5u6lss

1l5u6lss1#

嗨,你尝试过基于令牌的分页吗?
“锡拉卜”公司/gocqlx的例子
https://github.com/scylladb/gocqlx/blob/master/example_test.go#l168

相关问题