Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-19040

Consider CONTAINS KEY in SAI unindexed index contexts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 5.0-beta1, 5.0, 5.1
    • Feature/SAI
    • None

    Description

      As reported by CASSANDRA-19034SelectTest#testContainsKeyAndContainsWithIndexOnMapValue fails when the default config uses SAI:

      [junit-timeout] Testcase: testContainsKeyAndContainsWithIndexOnMapValue(org.apache.cassandra.cql3.validation.operations.SelectTest)-_jdk11:	FAILED
      [junit-timeout] Got less rows than expected. Expected 1 but got 0
      [junit-timeout] junit.framework.AssertionFailedError: Got less rows than expected. Expected 1 but got 0
      [junit-timeout] 	at org.apache.cassandra.cql3.CQLTester.assertRows(CQLTester.java:1849)
      [junit-timeout] 	at org.apache.cassandra.cql3.validation.operations.SelectTest.lambda$testContainsKeyAndContainsWithIndexOnMapValue$9(SelectTest.java:625)
      [junit-timeout] 	at org.apache.cassandra.cql3.CQLTester.beforeAndAfterFlush(CQLTester.java:2238)
      [junit-timeout] 	at org.apache.cassandra.cql3.validation.operations.SelectTest.testContainsKeyAndContainsWithIndexOnMapValue(SelectTest.java:618)
      [junit-timeout] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [junit-timeout] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      [junit-timeout] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      [junit-timeout] 
      [junit-timeout] 
      

      This can also be reproduced with this simple test:

      createTable("CREATE TABLE %s (k int PRIMARY KEY, v int, m map<int,int>)");
      createIndex("CREATE INDEX ON %s(v) USING 'SAI'");
      execute("INSERT INTO %s (k, v, m) VALUES (?, ?, ?)", 0, 1, map(2, 3));
      assertRows(execute("SELECT k, v, m FROM %s WHERE v = 1 AND m CONTAINS KEY 2 ALLOW FILTERING"),
                 row(0, 1, map(2, 3)));
      

      I think the problem is that the index context created by the query planner for an unindexed column always has a VALUES index target type, here. This is problematic when there is a CONTAINS KEY expression that isn't backed by an index, since we'll be comparing the searched map key to scanned map values.

      Attachments

        Issue Links

          Activity

            People

              adelapena Andres de la Peña
              adelapena Andres de la Peña
              Andres de la Peña
              Maxwell Guo, Michael Semb Wever
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m