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

Sunil Ramchandra Pawar commented on CASSANDRA-20154:
----------------------------------------------------

I looked into this and here’s what I found:

In SimpleRestriction.java:
{code:java}
// For BETWEEN we support like in SQL reversed bounds
                    if (operator.kind() == Operator.Kind.TERNARY)
                        buffers.sort(column.type);{code}
BETWEEN is classified as TERNARY, which leads to sorting of the buffer. 
Skipping this step specifically for BETWEEN seems to help.

In ClusteringColumnRestrictions.java:
{code:java}
private boolean handleInFilter(SingleRestriction restriction, int index)
    {
        return restriction.needsFilteringOrIndexing() || index != 
restriction.firstColumn().position();
    }{code}
there’s a check where the index must match the clustering column position. 
Since clustering columns are 0-indexed, a BETWEEN on the first clustering 
column ends up failing the assertion.

Just wanted to share what I observed — curious to hear if others have any 
opinions or insights on this.

> BETWEEN where token(Y) > token(Z) returns wrong answer
> ------------------------------------------------------
>
>                 Key: CASSANDRA-20154
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-20154
>             Project: Apache Cassandra
>          Issue Type: Bug
>          Components: CQL/Semantics
>            Reporter: Ariel Weisberg
>            Priority: Urgent
>              Labels: lhf, low-hanging-fruit, lowhanging-fruit
>             Fix For: 5.x
>
>
> Noticed it’s not compliant with the SQL specification for BETWEEN and so 
> doesn’t match what other databases do (tested on Postgres and MySQL).
> Here is the [SQL 92 
> spec|https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt] (later 
> versions probably don't change something so fundamental).
> In particular rule 6 doesn't match the observed behavior which is to swap Y 
> and Z and then return what is in between them which is pretty surprising as a 
> result.
> {noformat}
> 6) "X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z".
> {noformat}
> {noformat}
>          8.3  <between predicate>
>          Function
>          Specify a range comparison.
>          Format
>          <between predicate> ::=
>               <row value constructor> [ NOT ] BETWEEN
>                 <row value constructor> AND <row value constructor>
>          Syntax Rules
>          1) The three <row value constructor>s shall be of the same degree.
>          2) Let respective values be values with the same ordinal position
>             in the two <row value constructor>s.
>          3) The data types of the respective values of the three <row value
>             constructor>s shall be comparable.
>          4) Let X, Y, and Z be the first, second, and third <row value con-
>             structor>s, respectively.
>          5) "X NOT BETWEEN Y AND Z" is equivalent to "NOT ( X BETWEEN Y AND
>             Z )".
>          6) "X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z".
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to