[ 
https://issues.apache.org/jira/browse/CASSANDRA-5457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13629992#comment-13629992
 ] 

Sylvain Lebresne commented on CASSANDRA-5457:
---------------------------------------------

I'm afraid this has to do with the fact that clustering order doesn't do what 
you think. Namely, it should just be seen as an "hint" to the storage engine 
that basically says "I will do most of my queries with field1 in descending 
order so optimize for that". So in particular, it doesn't give you any 
particular guarantee on the sort order of queries, you still have to use ORDER 
BY in the query for that (and as it happens, you won't be allowed to order on 
'field1' unless you specify 'id' because we have no way to do that efficiently).

I'll not that if you did a query like:
{noformat}
SELECT * FROM reverse_sort_test WHERE id=0;
{noformat}
and that was returning multiple results, then those result would be ordered by 
descending field1, while it would be in ascending order if you don't add the 
clustering order during the definition. *But*, that's just CQL3 using the fact 
you haven't specify any ORDER BY for your query to return the result in the 
order that is the easier.
                
> Ordering is ignored when using 'CLUSTERING ORDER BY' 
> -----------------------------------------------------
>
>                 Key: CASSANDRA-5457
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-5457
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.4
>            Reporter: Patrick McFadin
>            Assignee: Sylvain Lebresne
>
> Creating the following table:
> create table reverse_sort_test (
>       id int,
>       field1 int,
>       field2 int
>       PRIMARY KEY (id, field1, field2)
> ) WITH CLUSTERING ORDER BY (field1 DESC);
> I would expect field1 to be reverse ordered. 
> Inserting this data:
> insert into reverse_sort_test (id,field1,field2) values (1,1,1);
> insert into reverse_sort_test (id,field1,field2) values (3,3,3);
> insert into reverse_sort_test (id,field1,field2) values (2,2,2);
> insert into reverse_sort_test (id,field1,field2) values (4,4,4);
> insert into reverse_sort_test (id,field1,field2) values (6,6,6);
> insert into reverse_sort_test (id,field1,field2) values (5,5,5);
> And running a select:
> select * from reverse_sort_test;
>  id | field1 | field2
> ----+--------+--------
>   5 |      5 |      5
>   1 |      1 |      1
>   2 |      2 |      2
>   4 |      4 |      4
>   6 |      6 |      6
>   3 |      3 |      3
> The order looks random.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to