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

Materialized Views: Index MV on TTL'ed column produces orphanized view entry if another column keeps entry live

    Details

      Description

      CREATE TABLE t (k int, a int, b int, PRIMARY KEY (k));
      CREATE MATERIALIZED VIEW mv AS SELECT * FROM t WHERE k IS NOT NULL AND a IS NOT NULL PRIMARY KEY (a, k);
      INSERT INTO t (k) VALUES (1);
      UPDATE t USING TTL 5 SET a = 10 WHERE k = 1;
      UPDATE t SET b = 100 WHERE k = 1;
      SELECT * from t; SELECT * from mv;
      
       k | a  | b
      ---+----+-----
       1 | 10 | 100
      
      (1 rows)
      
       a  | k | b
      ----+---+-----
       10 | 1 | 100
      
      (1 rows)
      
      -- 5 seconds later
      
      SELECT * from t; SELECT * from mv;
      
       k | a    | b
      ---+------+-----
       1 | null | 100
      
      (1 rows)
      
       a  | k | b
      ----+---+-----
       10 | 1 | 100
      
      (1 rows)
      
      -- that view entry's liveness-info is (probably) dead, but the entry is kept alive by b=100
      
      DELETE b FROM t WHERE k=1;
      SELECT * from t; SELECT * from mv;
      
       k | a    | b
      ---+------+------
       1 | null | null
      
      (1 rows)
      
       a  | k | b
      ----+---+-----
       10 | 1 | 100
      
      (1 rows)
      
      DELETE FROM t WHERE k=1;
      cqlsh:test> SELECT * from t; SELECT * from mv;
      
       k | a | b
      ---+---+---
      
      (0 rows)
      
       a  | k | b
      ----+---+-----
       10 | 1 | 100
      
      (1 rows)
      
      -- deleting the base-entry doesn't help, because the view-key can not be constructed anymore (a=10 already expired)
      

      The problem here is that although the view-entry's liveness-info (probably) expired correctly a regular column (`b`) keeps the view-entry live. It should have disappeared since it's indexed column (`a`) expired in the corresponding base-row. This is pretty severe, since that view-entry is now orphanized.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                krishna.koneru Krishna Dattu Koneru
                Reporter:
                fsander Fridtjof Sander
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: