Table-1:
create table mylistofitems (listid int,
itemid int,
quantity int,
itemdesc text,
primary key ((listid, itemid), itemdesc));
In the above table I'm doing the following inserts:
insert into mylistofitems (listid, itemid, itemdesc, quantity) values (1, 1000, 'apple', 5);
insert into mylistofitems (listid, itemid, itemdesc, quantity) values (1, 1000, 'banana', 10);
insert into mylistofitems (listid, itemid, itemdesc, quantity) values (1, 1000, 'orange', 6);
insert into mylistofitems (listid, itemid, itemdesc, quantity) values (1, 1000, 'orange', 50);
when I do select * from mylistofitems I get the following:
listid | itemid | itemdesc | quantity
--------+--------+----------+----------
1 | 1000 | apple | 5
1 | 1000 | banana | 10
1 | 1000 | orange | 50
Second insert statement did NOT overwrite the 1st row. But the fourth insert statement has overwritten the third row.
In this context what is the meaning of clustering key?
Table-2:
create table myitems (listid int,
itemid int,
idesc text,
qty int,
primary key (listid, itemid));
I insert the following records into table-2:
insert into myitems (listid, itemid, idesc, qty) values (1, 1000,
'apple', 5);
insert into myitems (listid, itemid, idesc, qty) values (1, 1000, 'banana', 10);
insert into myitems (listid, itemid, idesc, qty) values (1, 1000, 'orange', 6);
insert into myitems (listid, itemid, idesc, qty) values (1, 1000, 'orange', 50);
Insert queries in table-2 are exactly the same as table-1. But when I do select * from myitems I'm surprised to see only one row which was inserted last. Rest all rows are lost. ie., Every insert statement overwrote the previous record.
listid | itemid | idesc | qty
--------+--------+--------+-----
1 | 1000 | orange | 50
Question: Why is it behaving differently in table-2 compared to table-1? What is the meaning of clustering key in this context? Why clustering key has been named "Clustering key". Does it have anything to do with cassandra cluster?
Question on update: I tried doing an update on table-1:
update mylistofitems set quantity = 100 where listid = 1 and itemid = 1000;
This says error 2200 some clustering key are missing. Why this is restricted?