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

Benjamin Lerer commented on CASSANDRA-11339:
--------------------------------------------

What we want to do here is disallow all the DISTINCT queries that have 
restrictions on other columns than the partition keys (even if the query use an 
index). Not only for filtering queries (the description as well as Sylvain's 
comment were a bit misleading).  
A query like: {{SELECT DISTINCT pk FROM myTable WHERE pk IN (1, 2, 3, 4) AND 
clustering1 = 1}} is not a filtering query but should be rejected. The current 
patch will reject it but the error message is misleading "SELECT DISTINCT 
queries are currently only supported with queries that do not require 
filtering".

The main problem behind DISTINCT is summarized in this 
[comment|https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java#L522].

I think that you do not need to provide a patch for 2.1 as it is not a critical 
one but you should provide one for 2.2.



> WHERE clause in SELECT DISTINCT can be ignored
> ----------------------------------------------
>
>                 Key: CASSANDRA-11339
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-11339
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL
>            Reporter: Philip Thompson
>            Assignee: Alex Petrov
>             Fix For: 2.1.x
>
>         Attachments: 
> 0001-Add-validation-for-distinct-queries-disallowing-quer.patch
>
>
> I've tested this out on 2.1-head. I'm not sure if it's the same behavior on 
> newer versions.
> For a given table t, with {{PRIMARY KEY (id, v)}} the following two queries 
> return the same result:
> {{SELECT DISTINCT id FROM t WHERE v > X ALLOW FILTERING}}
> {{SELECT DISTINCT id FROM t}}
> The WHERE clause in the former is silently ignored, and all id are returned, 
> regardless of the value of v in any row. 
> It seems like this has been a known issue for a while:
> http://stackoverflow.com/questions/26548788/select-distinct-cql-ignores-where-clause
> However, if we don't support filtering on anything but the partition key, we 
> should reject the query, rather than silently dropping the where clause



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to