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

Secondary index query on partition key columns might not return partitions with only static data

    XMLWordPrintableJSON

    Details

      Description

      The problem can be reproduced with the following test in 3.0:

         @Test
          public void testIndexOnPartitionKeyWithPartitionWithoutRows() throws Throwable
          {
              createTable("CREATE TABLE %s (pk1 int, pk2 int, c int, s int static, v int, PRIMARY KEY((pk1, pk2), c))");
              createIndex("CREATE INDEX ON %s (pk2)");
      
              execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 1, 9, 1);
              execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 2, 9, 2);
              execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 3, 1, 1, 9, 1);
              execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 4, 1, 1, 9, 1);
              flush();
      
              assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 1),
                         row(1, 1, 1, 9, 1),
                         row(1, 1, 2, 9, 2),
                         row(3, 1, 1, 9, 1),
                         row(4, 1, 1, 9, 1));
      
              execute("DELETE FROM %s WHERE pk1 = ? AND pk2 = ? AND c = ?", 3, 1, 1);
      
              assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 1),
                         row(1, 1, 1, 9, 1),
                         row(1, 1, 2, 9, 2),
                         row(3, 1, null, 9, null),  // This row will not be returned
                         row(4, 1, 1, 9, 1));
          }
      

      The problem seems to be that the index entries for the static data are inserted with an empty clustering key. When the first SELECT is executed those entries are removed by CompositesSearcher::filterStaleEntries which consider that those entries are stales. When the second SELECT is executed the index ignore the (3, 1) partition as there is not entry for it anymore.

        Attachments

          Activity

            People

            • Assignee:
              Bereng Berenguer Blasi
              Reporter:
              blerer Benjamin Lerer
              Authors:
              Berenguer Blasi
              Reviewers:
              Benjamin Lerer
            • Votes:
              0 Vote for this issue
              Watchers:
              5 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 - 1.5h
                1.5h