I'd the following Cassandra Model:-
class Automobile(Model):
manufacturer = columns.Text(primary_key=True)
year = columns.Integer(index=True)
model = columns.Text(index=True)
price = columns.Decimal(index=True)
I needed the following queries:-
q = Automobile.objects.filter(manufacturer='Tesla')
q = Automobile.objects.filter(year='something')
q = Automobile.objects.filter(model='something')
q = Automobile.objects.filter(price='something')
These all were working fine, until i wanted multiple column filtering, ie when I tried
q = Automobile.objects.filter(manufacturer='Tesla',year='2013')
it throws an error saying Cannot execute this query as it might involve data filtering and thus may have unpredictable performance.
I rewrote the query with allowed_filtering
, but this is not an optimal solution.
Then upon reading more, I edited my model as follow:-
class Automobile(Model):
manufacturer = columns.Text(primary_key=True)
year = columns.Integer(primary_key=True)
model = columns.Text(primary_key=True)
price = columns.Decimal()
With this I was able to filter multiple coulms as well, without any warning.
When I did DESCRIBE TABLE automobile
, it shows this creates composite key PRIMARY KEY ((manufacturer), year, model)
.
So, my question is what if I declare every attribute as primary key? Is there any problem with this, since I'll be able to filter multiple columns as well.
This is just a small model. What if I had a model such as:-
class UserProfile(Model):
id = columns.UUID(primary_key=True, default=uuid.uuid4)
model = columns.Text()
msisdn = columns.Text(index=True)
gender = columns.Text(index=True)
imei1 = columns.Set(columns.Text)
circle = columns.Text(index=True)
epoch = columns.DateTime(index=True)
cellid = columns.Text(index=True)
lacid = columns.Text(index=True)
mcc = columns.Text(index=True)
mnc = columns.Text(index=True)
installed_apps = columns.Set(columns.Text)
otp = columns.Text(index=True)
regtype = columns.Text(index=True)
ctype = columns.Text(index=True)
operator = columns.Text(index=True)
dob = columns.DateTime(index=True)
jsonver = columns.Text(index=True)
and if I declare every attribute as PK, is there any problem with this?
imei,phone,datetime,model,dob, and few other fields
. Now I want to filter on multiple coulmns such asphone,imei,model and dob
.1)
Should I declare all these 4 fields as PK?2)
Lets say if all of these are declared as PK, then in future if user updates his mobile number, how will I update it, since its not allowed to update a PK. – Chatelaine