Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mixing token, multi- and single-column restrictions #4244

Open
1 task done
psarna opened this issue Feb 19, 2019 · 23 comments
Open
1 task done

Add support for mixing token, multi- and single-column restrictions #4244

psarna opened this issue Feb 19, 2019 · 23 comments

Comments

@psarna
Copy link
Contributor

psarna commented Feb 19, 2019

This is Scylla's bug tracker, to be used for reporting bugs only.
If you have a question about Scylla, and not a bug, please ask it in
our mailing-list at scylladb-dev@googlegroups.com or in our slack channel.

  • I have read the disclaimer above, and I am reporting a suspected malfunction in Scylla.

Installation details
Scylla version (or git commit hash): master (e37e095)

Currently it's not possible to restrict columns by multi-column restrictions, token restrictions and single-column ones at the same time. We should allow that in order to make it possible to execute queries like:

select * from t1 where col1=k11 and token(col1) >= lower_range and token(col1) < upper_range allow filtering

SELECT * FROM t WHERE (ck1, ck2) IN ((1,2),(2,3)) AND ck3 < 3 ALLOW FILTERING
@psarna
Copy link
Contributor Author

psarna commented Feb 19, 2019

Refs #3574

@slivne
Copy link
Contributor

slivne commented Oct 8, 2019

@psarna - with regards to this one:

SELECT * FROM t WHERE (ck1, ck2) IN ((1,2),(2,3)) AND ck3 < 3

I think you are missing ALLOW FILTERING - right ?

@tarzanek
Copy link
Contributor

tarzanek commented Oct 8, 2019

Are we able to support queries like

SELECT * FROM cycling.last_3_days WHERE TOKEN(year) < TOKEN('2015-05-26') AND year IN ('2015-05-24','2015-05-25');
(or from https://docs.datastax.com/en/archived/cql/3.3/cql/cql_using/useToken.html ? )
?

@psarna
Copy link
Contributor Author

psarna commented Oct 8, 2019

@slivne yes, definitely, I'll fix it in the issue body for completeness.
@tarzanek nope, currently a token restriction always screams if it's used along with a non-token restriction in the same statement.

@dekimir
Copy link
Contributor

dekimir commented Feb 1, 2020

For the record, Cassandra supports mixing single- and multi-column relations.

Cassandra:

cqlsh:ks> DESCRIBE TABLE tbl ;

CREATE TABLE ks.tbl (
    p1 int,
    p2 int,
    c1 int,
    c2 int,
    t text,
    PRIMARY KEY ((p1, p2), c1, c2)
) WITH CLUSTERING ORDER BY (c1 ASC, c2 ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
    AND comment = ''
    AND compaction = {'class': 'SizeTieredCompactionStrategy'}
    AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99.0PERCENTILE';

cqlsh:ks> SELECT * FROM tbl WHERE (c1,c2) > (0,1) and c1<10 ALLOW FILTERING;

 p1 | p2 | c1 | c2 | t
----+----+----+----+---

(0 rows)

Scylla:

cqlsh:ks> SELECT * FROM tbl WHERE (c1,c2) > (0,1) and c1<10 ALLOW FILTERING;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Mixing single column relations and multi column relations on clustering columns is not allowed"

@dekimir
Copy link
Contributor

dekimir commented Apr 22, 2020

For multi-column restrictions, there are two failure modes:

  1. When the query is rejected because the same column participates in multi- and single-column relations (eg, (c1,c2) > (0,1) and c1<10 as shown above).
  2. When the query is accepted, but only the multi-column relation is evaluated. This is Other restrictions ignored when clustering key is constrained #6200.

@avikivity
Copy link
Member

We imported this error message in 792f606, Dec 2014. Cassandra subsequently gained support for mixing single and multiple column constraints in apache/cassandra@90a012a (2.0.13/2.1.5) . Although that itself is marked as fixing a regression.

So we're compatible with some version of Cassandra, not randomly losing a feature.

avikivity pushed a commit that referenced this issue May 31, 2021
…index_test

In this patch, we port validation/entities/secondary_index_test.java,
resulting in 41 tests for various aspects of secondary indexes.
Some of the original Java tests required direct access to the Cassandra
internals not available through CQL, so those tests were omitted.

In porting these tests, I uncovered 9 previously-unknown bugs in Scylla:

Refs #8600: IndexInfo system table lists MV name instead of index name
Refs #8627: Cleanly reject updates with indexed values where value > 64k
Refs #8708: Secondary index is missing partitions with only a static row
Refs #8711: Finding or filtering with an empty string with a secondary
            index seems to be broken
Refs #8714: Improve error message on unsupported restriction on partition
            key
Refs #8717: Recent fix accidentally broke CREATE INDEX IF NOT EXISTS
Refs #8724: Wrong error message when attempting index of UDT column with
            a duration
Refs #8744: Index-creation error message wrongly refers to "map" - it can
            be any collection
Refs #8745: Secondary index CREATE INDEX syntax is missing the "values"
            option

These tests also provide additional reproducers for already known issues:

Refs #2203: Add support for SASI
Refs #2962: Collection column indexing
Refs #2963: Static column indexing
Refs #4244: Add support for mixing token, multi- and single-column
            restrictions

Due to these bugs, 15 out of the 41 tests here currently xfail. We actually
had more failing tests, but we fixed a few of the above issues before this
patch went in, so their tests are passing at the time of this submission.

All 41 tests pass when running against Cassandra.

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
Message-Id: <20210531112354.970028-1-nyh@scylladb.com>
@nyh
Copy link
Contributor

nyh commented Jun 29, 2021

A user reported that Apache Beam CassandraIO divides queries into sub-queries split into token ranges, which results in queries including both normal restrictions and token restrictions - which breaks on Scylla but works on Cassandra since 2015, as @avikivity noted above.

@nyh
Copy link
Contributor

nyh commented Jun 29, 2021

So we're compatible with some version of Cassandra, not randomly losing a feature.

At this point, the Cassandra feature is 6 years old and exists on Cassandra 2, 3 and 4 - so users with existing applications or Cassandra-oriented tools which need it will not be content knowing that Cassandra also didn't have this feature once.

@dekimir
Copy link
Contributor

dekimir commented Sep 13, 2021

Ongoing work on #3815 will naturally fix this issue.

@slivne slivne removed this from the 5.0 milestone Apr 13, 2022
@nyh
Copy link
Contributor

nyh commented Jan 8, 2023

Two more translated Cassandra test exposes this issue (the multi/single case) -

  • cassandra_tests/validation/operations/compact_storage_test.py::testDeleteWithTwoClusteringColumns
  • cassandra_tests/validation/operations/delete_test.py::testDeleteWithTwoClusteringColumns

Both have the same command:

DELETE FROM tbl WHERE partitionKey = ? AND (clustering_1) IN ((?), (?)) AND clustering_2 = ?"

In this case one of the restrictions only looks like a multi-column restriction but it isn't really, which makes this error even more silly.

nyh added a commit to nyh/scylla that referenced this issue Feb 12, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/CompactStorageTest.java into our cql-pytest
framework.

This very large test file includes 86 tests for various types of
operations and corner cases of WITH COMPACT STORAGE tables.

All 86 tests pass on Cassandra (except one using a deprecated feature
that needs to be specially enabled). 30 of the tests fail on Scylla
reproducing 7 already-known Scylla issues and 7 previously-unknown issues:

Already known issues:

Refs scylladb#3882: Support "ALTER TABLE DROP COMPACT STORAGE"
Refs scylladb#4244: Add support for mixing token, multi- and single-column
            restrictions
Refs scylladb#5361: LIMIT doesn't work when using GROUP BY
Refs scylladb#5362: LIMIT is not doing it right when using GROUP BY
Refs scylladb#5363: PER PARTITION LIMIT doesn't work right when using GROUP BY
Refs scylladb#7735: CQL parser missing support for Cassandra 3.10's new "+=" syntax
Refs scylladb#8627: Cleanly reject updates with indexed values where value > 64k

New issues:

Refs scylladb#12471: Range deletions on COMPACT STORAGE is not supported
Refs scylladb#12474: DELETE prints misleading error message suggesting
             ALLOW FILTERING would work
Refs scylladb#12477: Combination of COUNT with GROUP BY is different from
             Cassandra in case of no matches
Refs scylladb#12479: SELECT DISTINCT should refuse GROUP BY with clustering column
Refs scylladb#12526: Support filtering on COMPACT tables
Refs scylladb#12749: Unsupported empty clustering key in COMPACT table
Refs scylladb#12815: Hidden column "value" in compact table isn't completely hidden

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
denesb pushed a commit that referenced this issue Feb 20, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/CompactStorageTest.java into our cql-pytest
framework.

This very large test file includes 86 tests for various types of
operations and corner cases of WITH COMPACT STORAGE tables.

All 86 tests pass on Cassandra (except one using a deprecated feature
that needs to be specially enabled). 30 of the tests fail on Scylla
reproducing 7 already-known Scylla issues and 7 previously-unknown issues:

Already known issues:

Refs #3882: Support "ALTER TABLE DROP COMPACT STORAGE"
Refs #4244: Add support for mixing token, multi- and single-column
            restrictions
Refs #5361: LIMIT doesn't work when using GROUP BY
Refs #5362: LIMIT is not doing it right when using GROUP BY
Refs #5363: PER PARTITION LIMIT doesn't work right when using GROUP BY
Refs #7735: CQL parser missing support for Cassandra 3.10's new "+=" syntax
Refs #8627: Cleanly reject updates with indexed values where value > 64k

New issues:

Refs #12471: Range deletions on COMPACT STORAGE is not supported
Refs #12474: DELETE prints misleading error message suggesting
             ALLOW FILTERING would work
Refs #12477: Combination of COUNT with GROUP BY is different from
             Cassandra in case of no matches
Refs #12479: SELECT DISTINCT should refuse GROUP BY with clustering column
Refs #12526: Support filtering on COMPACT tables
Refs #12749: Unsupported empty clustering key in COMPACT table
Refs #12815: Hidden column "value" in compact table isn't completely hidden

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #12816
tgrabiec pushed a commit that referenced this issue Feb 20, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/CompactStorageTest.java into our cql-pytest
framework.

This very large test file includes 86 tests for various types of
operations and corner cases of WITH COMPACT STORAGE tables.

All 86 tests pass on Cassandra (except one using a deprecated feature
that needs to be specially enabled). 30 of the tests fail on Scylla
reproducing 7 already-known Scylla issues and 7 previously-unknown issues:

Already known issues:

Refs #3882: Support "ALTER TABLE DROP COMPACT STORAGE"
Refs #4244: Add support for mixing token, multi- and single-column
            restrictions
Refs #5361: LIMIT doesn't work when using GROUP BY
Refs #5362: LIMIT is not doing it right when using GROUP BY
Refs #5363: PER PARTITION LIMIT doesn't work right when using GROUP BY
Refs #7735: CQL parser missing support for Cassandra 3.10's new "+=" syntax
Refs #8627: Cleanly reject updates with indexed values where value > 64k

New issues:

Refs #12471: Range deletions on COMPACT STORAGE is not supported
Refs #12474: DELETE prints misleading error message suggesting
             ALLOW FILTERING would work
Refs #12477: Combination of COUNT with GROUP BY is different from
             Cassandra in case of no matches
Refs #12479: SELECT DISTINCT should refuse GROUP BY with clustering column
Refs #12526: Support filtering on COMPACT tables
Refs #12749: Unsupported empty clustering key in COMPACT table
Refs #12815: Hidden column "value" in compact table isn't completely hidden

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #12816
nyh added a commit to nyh/scylla that referenced this issue Mar 21, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/SelectMultiColumnRelationTest.java into our
cql-pytest framework.

The tests reproduce four already-known Scylla bugs and three new bugs.
All tests pass on Cassandra. Because of these bugs 9 of the 22 tests
are marked xfail, and one is marked skip (it crashes Scylla).

Already known issues:

Refs    scylladb#64: CQL Multi column restrictions are allowed only on a clustering
             key prefix
Refs  scylladb#4178: Not covered corner case for key prefix optimization in filtering
Refs  scylladb#4244: Add support for mixing token, multi- and single-column
             restrictions
Refs  scylladb#8627: Cleanly reject updates with indexed values where value > 64k

New issue discovered by these tests:

Refs scylladb#13217: Internal server error when null is used in multi-column relation
Refs scylladb#13241: Multi-column IN restriction with tuples of different lengths
             crashes Scylla
Refs scylladb#13250: One-element multi-column restriction should be handled like a
             single-column restriction

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
denesb pushed a commit that referenced this issue Mar 22, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/SelectMultiColumnRelationTest.java into our
cql-pytest framework.

The tests reproduce four already-known Scylla bugs and three new bugs.
All tests pass on Cassandra. Because of these bugs 9 of the 22 tests
are marked xfail, and one is marked skip (it crashes Scylla).

Already known issues:

Refs    #64: CQL Multi column restrictions are allowed only on a clustering
             key prefix
Refs  #4178: Not covered corner case for key prefix optimization in filtering
Refs  #4244: Add support for mixing token, multi- and single-column
             restrictions
Refs  #8627: Cleanly reject updates with indexed values where value > 64k

New issue discovered by these tests:

Refs #13217: Internal server error when null is used in multi-column relation
Refs #13241: Multi-column IN restriction with tuples of different lengths
             crashes Scylla
Refs #13250: One-element multi-column restriction should be handled like a
             single-column restriction

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #13265
nyh added a commit to nyh/scylla that referenced this issue Apr 4, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/DeleteText.java into our cql-pytest framework.

There are 51 tests, and they did not reproduce any previously-unknown
bug, but did provide additional reproducers for three known issues:

Refs  scylladb#4244 Add support for mixing token, multi- and single-column
            restrictions

Refs scylladb#12474 DELETE prints misleading error message suggesting ALLOW
            FILTERING would work

Refs scylladb#13250 one-element multi-column restriction should be handled like
            a single-column restriction

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
nyh added a commit to nyh/scylla that referenced this issue Apr 9, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/DeleteTest.java into our cql-pytest framework.

There are 51 tests, and they did not reproduce any previously-unknown
bug, but did provide additional reproducers for three known issues:

Refs  scylladb#4244 Add support for mixing token, multi- and single-column
            restrictions

Refs scylladb#12474 DELETE prints misleading error message suggesting ALLOW
            FILTERING would work

Refs scylladb#13250 one-element multi-column restriction should be handled like
            a single-column restriction

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
denesb pushed a commit that referenced this issue Apr 11, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/DeleteTest.java into our cql-pytest framework.

There are 51 tests, and they did not reproduce any previously-unknown
bug, but did provide additional reproducers for three known issues:

Refs  #4244 Add support for mixing token, multi- and single-column
            restrictions

Refs #12474 DELETE prints misleading error message suggesting ALLOW
            FILTERING would work

Refs #13250 one-element multi-column restriction should be handled like
            a single-column restriction

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #13436
nyh added a commit that referenced this issue Aug 13, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/CompactStorageTest.java into our cql-pytest
framework.

This very large test file includes 86 tests for various types of
operations and corner cases of WITH COMPACT STORAGE tables.

All 86 tests pass on Cassandra (except one using a deprecated feature
that needs to be specially enabled). 30 of the tests fail on Scylla
reproducing 7 already-known Scylla issues and 7 previously-unknown issues:

Already known issues:

Refs #3882: Support "ALTER TABLE DROP COMPACT STORAGE"
Refs #4244: Add support for mixing token, multi- and single-column
            restrictions
Refs #5361: LIMIT doesn't work when using GROUP BY
Refs #5362: LIMIT is not doing it right when using GROUP BY
Refs #5363: PER PARTITION LIMIT doesn't work right when using GROUP BY
Refs #7735: CQL parser missing support for Cassandra 3.10's new "+=" syntax
Refs #8627: Cleanly reject updates with indexed values where value > 64k

New issues:

Refs #12471: Range deletions on COMPACT STORAGE is not supported
Refs #12474: DELETE prints misleading error message suggesting
             ALLOW FILTERING would work
Refs #12477: Combination of COUNT with GROUP BY is different from
             Cassandra in case of no matches
Refs #12479: SELECT DISTINCT should refuse GROUP BY with clustering column
Refs #12526: Support filtering on COMPACT tables
Refs #12749: Unsupported empty clustering key in COMPACT table
Refs #12815: Hidden column "value" in compact table isn't completely hidden

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #12816

(cherry picked from commit 328cdb2)
nyh added a commit that referenced this issue Aug 13, 2023
This is a translation of Cassandra's CQL unit test source file
validation/operations/CompactStorageTest.java into our cql-pytest
framework.

This very large test file includes 86 tests for various types of
operations and corner cases of WITH COMPACT STORAGE tables.

All 86 tests pass on Cassandra (except one using a deprecated feature
that needs to be specially enabled). 30 of the tests fail on Scylla
reproducing 7 already-known Scylla issues and 7 previously-unknown issues:

Already known issues:

Refs #3882: Support "ALTER TABLE DROP COMPACT STORAGE"
Refs #4244: Add support for mixing token, multi- and single-column
            restrictions
Refs #5361: LIMIT doesn't work when using GROUP BY
Refs #5362: LIMIT is not doing it right when using GROUP BY
Refs #5363: PER PARTITION LIMIT doesn't work right when using GROUP BY
Refs #7735: CQL parser missing support for Cassandra 3.10's new "+=" syntax
Refs #8627: Cleanly reject updates with indexed values where value > 64k

New issues:

Refs #12471: Range deletions on COMPACT STORAGE is not supported
Refs #12474: DELETE prints misleading error message suggesting
             ALLOW FILTERING would work
Refs #12477: Combination of COUNT with GROUP BY is different from
             Cassandra in case of no matches
Refs #12479: SELECT DISTINCT should refuse GROUP BY with clustering column
Refs #12526: Support filtering on COMPACT tables
Refs #12749: Unsupported empty clustering key in COMPACT table
Refs #12815: Hidden column "value" in compact table isn't completely hidden

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #12816

(cherry picked from commit 328cdb2)
(cherry picked from commit e11561e)
Modified for 5.1 to comment out error-path tests for "unset" values what
are silently ignored (instead of being detected) in this version.
@cvybhu cvybhu removed their assignment Oct 19, 2023
@ptrsmrn
Copy link
Contributor

ptrsmrn commented Apr 2, 2024

The issue is still valid (5.4 OSS):

cqlsh> CREATE TABLE ms.t (ck1 int PRIMARY KEY, ck2 int, ck3 int);
cqlsh> SELECT * FROM ms.t WHERE (ck1, ck2) IN ((1,2),(2,3)) AND ck3 < 3 ALLOW FILTERING;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Multi-column relations can only be applied to clustering columns but was applied to: ck1"

Queuing for Q3'24, but with low priority.

@nyh
Copy link
Contributor

nyh commented Apr 2, 2024

The error message you saw is really weird, and even worse than the situation before :-(
Please note above a list of tests for this feature and its Cassandra compatibility. By now this feature is 9 years old (!) in Cassandra and we still haven't implemented it.

@dekimir
Copy link
Contributor

dekimir commented Apr 2, 2024

@nyh that message doesn't seem weird at all. Look at how the code above created the table -- ck1 and ck2 aren't clustering keys. Only clustering keys are allowed in multi-column relations.

@denesb
Copy link
Contributor

denesb commented Apr 2, 2024

You are right @dekimir (long time no see :D). Those are regular columns.

@ptrsmrn
Copy link
Contributor

ptrsmrn commented Apr 2, 2024

Thanks, correcting (the issue still present):

cqlsh> CREATE TABLE ms.tbl (
    p1 int,
    p2 int,
    c1 int,
    c2 int,
    t text,
    PRIMARY KEY ((p1, p2), c1, c2)
) WITH CLUSTERING ORDER BY (c1 ASC, c2 ASC);
cqlsh> SELECT * FROM ms.tbl WHERE (c1,c2) > (0,1) and c1<10 ALLOW FILTERING;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Mixing single column relations and multi column relations on clustering columns is not allowed"

@nyh
Copy link
Contributor

nyh commented Apr 2, 2024

@ptrsmrn please take a look at the cql-pytest tests mentioned above and learn how to run them quickly with test/cql-pytest/run - and then you won't need to invent new and incorrect way to reproduce such issues that already have reproducers :-)

@nyh
Copy link
Contributor

nyh commented Apr 2, 2024

Summary of cql-pytest tests that reproduce this issue. You can also grep the issue number (#4244) in the tests to find tests that reproduce it:

  • test_scan.py::test_multi_column_restrictions_ck
  • test_scan.py::test_multi_column_and_single_column_restriction_same_ck
  • test_scan.py::test_restriction_token_and_nontoken
  • cassandra_tests/validation/operations/select_test.py::testFilteringWithMultiColumnSlices
  • cassandra_tests/validation/operations/compact_storage_test.py::testDeleteWithTwoClusteringColumns
  • cassandra_tests/validation/operations/select_multi_column_relation_test.py::testMultiClusteringInvalidQueries
  • cassandra_tests/validation/operations/compact_storage_test.py::testDeleteWithTwoClusteringColumns
  • cassandra_tests/validation/operations/delete_test.py::testDeleteWithTwoClusteringColumns

These different tests exercises different subcases and variants of the same issue, so it's worth to check that we solve them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment