- No Joins #81
- No Referential Integrity
- ie Foreign key & Cascading deletes are not available
- Denormalized
- Can be achieved through,
- Classic Denormalization
- Materialized Views (Starting from Cassandra v3.0)
- Query first Design
- Data Storage Consideration
- In Cassandra, a table might be partitioned across multiple nodes
- A Query that only search for a data in a single partition(Single Node) will be more faster that searching in multiple partition(Multiple nodes) #83
- Sorting Order
- Is fixed in Cassandra (we cannot change the order of data using queries as we can do in RDBMS...Ex ; select * from ... ORDER BY)
- Is determined based on Clustering Columns #84
RDBMS vs Cassandra
How to create Secondary Index?
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 user defined data type (UDT)....
cqlsh:ks> // UDT can be created as part of keyspace cqlsh:ks> create type mark ( ... math text, ... science text ... ); cqlsh:ks> cqlsh:ks> // UDT can be utilized by using the 'frozen' keyword #74 cqlsh:ks> // Note : The concept of 'frozen' is given for forward cqlsh:ks> // compatibility cqlsh:ks> create table student( ... name text, ... class text, ... subjects frozen<mark>, ... primary key(name)); cqlsh:ks> cqlsh:ks> insert into student(name, class, subjects) values('bob', '3rd', ... {math: '70', science: '80'}); cqlsh:ks> select * from student; name | class | subjects ------+-------+----------------------------- bob | 3rd | {math: '70', science: '80'} (1 rows)
Some more data types : boolean, blob, inet, counter
- boolean #69
- blob
- inet
- To store IPV4 & IPV6 addresses
- counter
- Is a 64 bit Signed Integer
Text Data Types...
- text, varchar
- UTF-8 Character String. Recommended #67
- ascii
- ASCII Character String
Hints : $LANG, HELP TEXT_OUTPUT
Subscribe to:
Posts (Atom)