You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Andrew Jefferson (JIRA)" <ji...@apache.org> on 2017/04/19 12:21:41 UTC

[jira] [Updated] (CASSANDRA-13462) Unexpected behaviour with range queries on UUIDs

     [ https://issues.apache.org/jira/browse/CASSANDRA-13462?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrew Jefferson updated CASSANDRA-13462:
-----------------------------------------
    Description: 
My expectation is that UUIDs should behave as 128 bit integers for comparison.

However it seems that the Cassandra implementation compares first the uuid version number, then the remaining values of the uuid.

e.g. in C*

 10000000-0000-3000-0000-000000000000

 is greater than 

20000000-0000-1000-0000-000000000000 

(n.b. the 13th value is the uuid version)

 - this is consistent across range queries and using ORDER BY 

  was:
My expectation is that UUIDs should behave as 128 bit integers for comparison.

However it seems that the Cassandra implementation compares first the uuid version number, then the remaining values of the uuid.

e.g. in C*
 10000000-0000-3000-0000-000000000000 is greater than 20000000-0000-1000-0000-000000000000 


I expect range queries / comparisons on UUIDs to work as though this is the case. But it does not. It seems to require the UUID to have certain properties for range queries to work properly:

```
create table dev.testinguuids ( pk int, ck uuid, val int, PRIMARY KEY ((pk), ck) )

insert into dev.testinguuids (pk,ck,val) VALUES (1, 30000000-0000-0000-0000-000000000000, 1)

select * from dev.testinguuids where pk=1 and ck>10000000-0000-0000-0000-000000000000;

 -> returns 1 row

select * from dev.testinguuids where pk=1 and ck>00000000-0000-5000-0000-000000000000;

 - > returns 0 rows
```
after a bit of investigation of UUIDs it works correctly for me if I force my query UUIDs to be in the form:

xxxxxxxx-xxxx-05xx-xxxx-xxxxxxxxxxxx

i.e. 
select * from dev.testinguuids where pk=1 and ck>xxxxxxxx-xxxx-05xx-xxxx-xxxxxxxxxxxx

works ok

n.b. I have populated my table only with valid type 1 and type 4 uuids. In testing if I create uuids that are of the form:
xxxxxxxx-xxxx-YYxx-xxxx-xxxxxxxxxxxx where YY > 05
then they behave differently as well:


```
# Insert a valid uuid
insert into dev.testinguuids (pk,ck,val) VALUES (2, 30000000-0000-0000-0000-000000000000, 1)


insert into dev.testinguuids (pk,ck,val) VALUES (2, 30000000-0000-0000-0000-000000000000, 1) 
```


> Unexpected behaviour with range queries on UUIDs
> ------------------------------------------------
>
>                 Key: CASSANDRA-13462
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-13462
>             Project: Cassandra
>          Issue Type: Bug
>            Reporter: Andrew Jefferson
>
> My expectation is that UUIDs should behave as 128 bit integers for comparison.
> However it seems that the Cassandra implementation compares first the uuid version number, then the remaining values of the uuid.
> e.g. in C*
>  10000000-0000-3000-0000-000000000000
>  is greater than 
> 20000000-0000-1000-0000-000000000000 
> (n.b. the 13th value is the uuid version)
>  - this is consistent across range queries and using ORDER BY 



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)