mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-02 14:15:46 +00:00
This is a rewrite of an old PR: #7582 `TOKEN()` restrictions don't work properly when a query uses an index. For example this returns both rows: ```cql CREATE TABLE t(pk int, ck int, v int, PRIMARY KEY(pk, ck)); CREATE INDEX ON t(v); INSERT INTO t (pk, ck, v) VALUES (0, 0, 0); INSERT INTO t (pk, ck, v) VALUES (1, 0, 0); SELECT token(pk), pk, ck, v FROM t WHERE v = 0 AND token(pk) = token(0) ALLOW FILTERING; ``` This functionality is supported on both old and new indexes. In old indexes the type of the token column was `blob`. This causes problems, because `blob` representation of tokens is ordered differently. Tokens represented as blobs are ordered like this: ``` 0, 1, 2, 3, 4, 5, ..., bigint_max, bigint_min, ...., -5, -4, -3, -2, -1 ``` Because of that clustering range for `token()` restrictions needs to be translated to two clustering ranges on the `blob` column. To create old indexes disable the feature called: `CORRECT_IDX_TOKEN_IN_SECONDARY_INDEX` or run scylla version from branch [`cvybhu/si-token2-old-index`](https://github.com/cvybhu/scylla/commits/si-token2-old-index) I'm not sure if it's possible to create automatic tests with old indexes. I ran `dev-test` manually on the `si-token2-old-index` branch, and the only tests that failed were the ones testing row ordering. Rows should be ordered by `token`, but because in old indexes the token is represented as a `blob` this ordering breaks. This is a known issue (#7443), that has been fixed by introducing new indexes. To sum up: * `token()` restrictions are fixed on both new and old indexes. * When using old indexes, the rows are not properly ordered by token. * With new indexes the rows are properly ordered by token. Fixes #7043 Closes #9067 * github.com:scylladb/scylla: tests: add secondary index tests with TOKEN clause secondary_index_test: extract test data secondary_index: Fix TOKEN() restrictions in indexed SELECTs expression: Add replace_token function