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

Dmitry Lychagin commented on ASTERIXDB-2372:
--------------------------------------------

May be we should slightly reconsider the floor/ceil approach when it comes to 
equality comparison, since we also want to support cases when the probe type is 
not known at compile time.

For equality comparison, can we first convert it to the indexed type then 
figure out the range and inclusiveness? (we somewhat do it with floor/ceil, but 
let me explain further)
That conversion should return NULL if some information will be lost, like in 
case #2 above. The inclusiveness option would still be maintained (<=, >=), but 
it would not matter because the Btree-search runtime should be modified to 
return empty result if one of the range values is NULL (if it doesn't do that 
already).

So the rewrite for equality would conceptually be 
id = X  (let's say 'id' is closed field of type int32 or indexed with enforced 
index as int32)
into 
id >= convert(X, int32) and id <= convert(X, int32)

'convert' returns NULL in cases where there's information loss, for example
- non-integral floating point value (1.3), or  
- int64 which is out of range for int32. 
In these cases we know that no indexed value (int32) can possibly match the 
probe value therefore the result would be empty, so we don't even need to 
physically scan the index 

With this approach X does not have to be a constant, but could be any 
expression for which the type might not even be known at compile time.

We should figure out rules for other comparison operators. There the conversion 
to the indexed type will be permitted even if there's an information loss.

 

 

 

> Providing a float value predicate to an integer primary index does not work 
> as expected.
> ----------------------------------------------------------------------------------------
>
>                 Key: ASTERIXDB-2372
>                 URL: https://issues.apache.org/jira/browse/ASTERIXDB-2372
>             Project: Apache AsterixDB
>          Issue Type: Bug
>            Reporter: Taewoo Kim
>            Assignee: Taewoo Kim
>            Priority: Critical
>
> If we have an integer primary index and feed a float value predicate that is 
> not an integer such as 1.3, the search result is not correct.
>  
> The DDL and DML
> {code:java}
> drop dataverse test if exists;
> create dataverse test;
> use test;
> create type MyRecord as closed {
>   id: int64
> };
> create dataset MyData(MyRecord) primary key id;
> insert into MyData({"id":1});
> insert into MyData({"id":2});
> select * from MyData where id = 1.3;{code}
>  
> The result should be empty. But, it returns 1 and 2 as the result.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to