Kokizzu
Kokizzu

Reputation: 26888

How to query limit with offset in Scylla and Go

Using gocql or gocqlx, there's no example to fetch nth page:

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);

Query function:

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
}

Is there no easy but with good performance (without ALLOW FILTERING) to fetch nth-page (order by email or id)?

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

Upvotes: 2

Views: 3522

Answers (1)

mmatczuk
mmatczuk

Reputation: 549

Hi did you try token based pagination?

Example from scylladb/gocqlx

https://github.com/scylladb/gocqlx/blob/master/example_test.go#L168

Upvotes: 3

Related Questions