'Is sorting rows by UUID a bad way in Cassandra?
I have a simple table and I want to sort by descending it. I added a parent_id and it's value is zero always. Is this a bad way to order by?
CREATE TABLE postcards (
id uuid,
parent_id tinyint,
body text,
PRIMARY KEY (parent_id, id)
) WITH CLUSTERING ORDER BY (id DESC)
SELECT * FROM postcards;
And query result:
[
{
"parent_id": 0,
"id": "f6b53ed0-aa30-11ec-8dc2-38f3ab100fe8",
"body": "7"
},
{
"parent_id": 0,
"id": "f507fa4b-aa30-11ec-8dc1-38f3ab100fe8",
"body": "6"
},
{
"parent_id": 0,
"id": "f31a2ced-aa30-11ec-8dc0-38f3ab100fe8",
"body": "5"
},
{
"parent_id": 0,
"id": "f1ab7e36-aa30-11ec-8dbf-38f3ab100fe8",
"body": "4"
},
{
"parent_id": 0,
"id": "f0897c34-aa30-11ec-8dbe-38f3ab100fe8",
"body": "3"
},
{
"parent_id": 0,
"id": "ef61185e-aa30-11ec-8dbd-38f3ab100fe8",
"body": "2"
},
{
"parent_id": 0,
"id": "ee1f9399-aa30-11ec-8dbc-38f3ab100fe8",
"body": "1"
}
]
Solution 1:[1]
If you will ever have just the one parent_id, this makes no sense because the data will only ever be owned by one node in the cluster (+ replicas).
Whether you sort the rows in ascending or descending is neither bad nor good. The more appropriate question is "What problem are you trying to solve?" because we would be able to give you a better answer if we have context on what you are trying to achieve.
If you're able to update your question with those details, I'd be happy to update my answer. Cheers!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Erick Ramirez |
