Cassandra: Query with where clause containing greather- or lesser-than (< and>)

前端 未结 2 1466
情书的邮戳
情书的邮戳 2021-01-12 08:27

I\'m using Cassandra 1.1.2 I\'m trying to convert a RDBMS application to Cassandra. In my RDBMS application I have following table called table1:

| Col1 | C         


        
2条回答
  •  误落风尘
    2021-01-12 08:45

    If col3 is always known small values/ranges, you may be able to get away with a simpler table that also maps back to the initial table, ex:

     create table table2 (col3val int, table1key varchar,
                          primary key (col3val, table1key));
    

    and use

     insert into table2 (col3val, table1key) values (55, 'foreign_key');
     insert into table2 (col3val, table1key) values (55, 'foreign_key3');
     select * from table2 where col3val = 51;
     select * from table2 where col3val = 52;
     ...
    

    Or

     select * from table2 where col3val  in (51, 52, ...);
    

    Maybe OK if you don't have too large of ranges. (you could get the same effect with your secondary index as well, but secondary indexes aren't highly recommended?). Could theoretically parallelize it "locally on the client side" as well.

    It seems the "Cassandra way" is to have some key like "userid" and you use that as the first part of "all your queries" so you may need to rethink your data model, then you can have queries like select * from table1 where userid='X' and col3val > 3 and it can work (assuming a clustering key on col3val).

提交回复
热议问题