Monday 15 March 2010

Cassandra UDTs as primary key -



Cassandra UDTs as primary key -

the official documentation tells not utilize udts primary keys. there particular reason this? potential downsides in doing this?

that sentence intended discourage users using udt pk columns indiscriminately. main motivation udt in it's current incarnation (that is, given cassandra supports "frozen" udt) storing more complex values within collections. outside collections, udt can have it's uses, it's worth asking twice if need it. example:

create type mytype (a text, b int);

create table mytable (id uuid primary key, v frozen<mytype>);

is not judicious in lose ability of updating v.a without updating v.b. it's more flexible straight do:

create table mytable (id uuid primary key, text, b int);

this trivial illustration points out udt outside of collections not thing, , extends primary key columns. it's not improve do:

create type mytype (a text, b int);

create table mytable (id frozen<mytype> primary key);

than more simply:

create table mytable (a text, b int, primary key ((a, b)))

furthermore, regarding primary key, complex udt doesn't create sense. consider moderately complex type like:

create type address ( number int, street text, city text, phones set<text> )

using such type within primary key certainly isn't useful since pk identifies rows , 2 addresses same except set of phones wouldn't identify same row. there not many situations desirable. more generally, pk tends relatively simple, , might want have fine-grained command on clustering columns, , udt candidates.

in summary, udt in pk columns not always bad, not useful in context, , users should not looking hard @ ways utilize udt pk columns because it's allowed.

cassandra

No comments:

Post a Comment