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

Ekaterina Dimitrova commented on CASSANDRA-18584:
-------------------------------------------------

Unfortunately, the initial work on SAI indexing acceleration of the NOT 
operator did not take into account below two problems which are work on their 
own:
- TTL and NOT CONTAINS in collections because they may not be null after 
expiring if they have other items.
Example:
{code:java}
cqlsh:test> create table sets(pk int primary key, s set<int>);
cqlsh:test> create custom index on sets(s) using 'StorageAttachedIndex';

cqlsh:test> insert into sets(pk, s) values (1, {1, 2, 3, 4});
cqlsh:test> update sets using ttl 30 set s = s+{5} where pk = 1;

// run nodetool flush here

cqlsh:test> select * from sets;

 pk | s
----+-----------------
  1 | {1, 2, 3, 4, 5}

// wait 30 seconds

cqlsh:test> select * from sets;

 pk | s
----+--------------
  1 | {1, 2, 3, 4}                      // <---- see? the row does not contain 5

(1 rows)
cqlsh:test> select * from sets where s not contains 5;   

 pk | s
----+---
                                            // <---- but we don't return it, 
ouch
(0 rows)
{code}

- For NEQ and maps, current implementation will return everything that does not 
match the exact entry.

Example:

{code:java}
execute("INSERT INTO %s(k, v, m) values (1, 0, {1:1, 2:2})");
execute("INSERT INTO %s(k, v, m) values (2, 0, {1:1, 3:3})");
execute("INSERT INTO %s(k, v, m) values (3, 0, {4:4, 5:5})");
execute("INSERT INTO %s(k, v, m) values (4, 0, {1:10, 2:20})");
execute("INSERT INTO %s(k, v, m) values (5, 0, {1:10, 3:30})");
execute("INSERT INTO %s(k, v, m) values (6, 0, {4:40, 5:50})");
// not equals entries
test("SELECT k FROM %s WHERE m[1] != 1",
        !hasIndex("me"),
        hasIndex("me"),
        row(3), row(4), row(5), row(6));
{code}

The SELECT statement should return only row(4) and row(5).

To get it to work, we'll need the NEQ operator to have the key and to do two 
checks on the map entry, one to check the key and another to check the value 
(the Composite Type complicates things). Some workaround has already been done 
in some Cassandra fork to enable >, <, <=, >=, but it constitutes its own work, 
which is too much to be added as part of this ticket and I would also not have 
the time to do that. The suggestion is to open a follow-up ticket where someone 
can work on !=, >, <, <=, >=.

As the non-SAI work is mostly done and follows the three-valued logic and other 
expected results correctly, I suggest we commit that work here. Then, we can 
open follow-up tickets for the SAI acceleration and post the ongoing WIP for 
someone to finish the work and fix the mentioned problems when time permits. 
Unfortunately, I won't be able to work on this anytime soon. 

[~adelapena], [~blerer], [~pkolaczk] - please confirm you are ok with the 
suggested plan, and I will push the latest tiny review suggestions to the 
NON-SAI part of the work and get it ready to commit. More info on what type of 
queries will be enabled is available in the linked PR.

> CEP-29: NOT operator
> --------------------
>
>                 Key: CASSANDRA-18584
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-18584
>             Project: Cassandra
>          Issue Type: New Feature
>          Components: CQL/Interpreter, CQL/Semantics, CQL/Syntax, Feature/SAI
>            Reporter: Piotr Kolaczkowski
>            Assignee: Ekaterina Dimitrova
>            Priority: Normal
>          Time Spent: 3h 20m
>  Remaining Estimate: 0h
>
> Implement new CQL operators:
> - NOT CONTAINS,
> - NOT CONTAINS KEY,
> - NOT IN
> - NOT LIKE
> https://cwiki.apache.org/confluence/display/CASSANDRA/CEP-29%3A+CQL+NOT+operator



--
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