cqlsh:ks> -- Note : Secondary index are not recommended for, #76 #94 cqlsh:ks> -- - Columns with High Cardinality cqlsh:ks> -- - Columns with Low Cardinality cqlsh:ks> -- - Columns that are frequently updated or deleted cqlsh:ks> -- ** Better to have a denormalized table rather than secondary cqlsh:ks> -- index #77 cqlsh:ks> -- # a120 > a93 cqlsh:ks> cqlsh:ks> -- Create Table cqlsh:ks> drop table student; cqlsh:ks> drop type mark; cqlsh:ks> cqlsh:ks> create type mark ( ... math text, ... science text ... ); cqlsh:ks> cqlsh:ks> create table student( ... name text, ... class text, ... month_v_attendance map<text, text>, ... week_v_attendance map<text, text>, ... subjects frozen<mark>, ... primary key(name) ... ); cqlsh:ks> cqlsh:ks> -- Insert Data cqlsh:ks> insert into ... student( name, class, subjects, month_v_attendance, ... week_v_attendance) ... values('bob', '3rd', {math: '70', science: '80'}, ... {'jan': '90%'}, {'3rdweek' : '90%'}); cqlsh:ks> cqlsh:ks> select * from student; name | class | month_v_attendance | subjects | week_v_attendance ------+-------+--------------------+-----------------------------+-------------------- bob | 3rd | {'jan': '90%'} | {math: '70', science: '80'} | {'3rdweek': '90%'} (1 rows) cqlsh:ks> cqlsh:ks> select * from student where class='3rd'; InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING" cqlsh:ks> cqlsh:ks> -- Create Secondary Index cqlsh:ks> create index classindex on student (class); cqlsh:ks> select * from student where class='3rd'; name | class | month_v_attendance | subjects | week_v_attendance ------+-------+--------------------+-----------------------------+-------------------- bob | 3rd | {'jan': '90%'} | {math: '70', science: '80'} | {'3rdweek': '90%'} (1 rows) -- SASI : SSTable Attached Secondary Index : Read more...#78
How to create Secondary Index?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment