Creation script:
Create Table TestTable (
A1 ascii,
A2 int,
A3 int,
A4 ascii,
A5 int,
A6 bigint,
A7 bigint,
A8 ascii,
PRIMARY KEY ((A1, A2,A3, A4),A5)
) WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 }
AND compaction = { 'class' : 'LeveledCompactionStrategy' };
Partition keys are (A1, A2, A3, A4).
I'd like to query data by (A1, A2, A3) to get more records.
Actually, I want to select one hundred records. If using (A1, A2, A3, A4) as where clause conditions, I can only get ten records.
So I'm intended to use less where clause conditions. I know I can't only use (A1, A2, A3) as where clause conditions.
Is there a way to achieve this query? Range condition? or other way?
I just make a test using one cql statement. I won't change the data model.
You already know what you need to do: there's no way to get records from a partial primary key. That's a base requirements because partition keys are used to locate data in the cluster: they tell Cassandra in which partition the requested data is, and a missing component on the partition key tuple means that Cassandra could not find the requested partition. Once Cassandra knows where the data is, it will fetch all the records ordered by the clustering key.
The way to solve your problem is to create a table with only (A1, A2, A3) as partition keys and get records from that table instead. You can keep both tables if you want, but keep in mind that if your original model had (A1, A2, A3, A4) for a reason, then removing A4 from the partition keys will likely create an hotspot in your cluster, because more data will fit inside a single partition.