adelapena commented on code in PR #2673:
URL: https://github.com/apache/cassandra/pull/2673#discussion_r1327951896


##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -1133,13 +1149,13 @@ public SelectStatement prepare(ClientState state, 
boolean forView) throws Invali
             List<Selectable> selectables = 
RawSelector.toSelectables(selectClause, table);
             boolean containsOnlyStaticColumns = selectOnlyStaticColumns(table, 
selectables);
 
-            StatementRestrictions restrictions = prepareRestrictions(state, 
table, bindVariables, containsOnlyStaticColumns, forView);
+            List<Ordering> orderings = getOrderings(table);
+            StatementRestrictions restrictions = prepareRestrictions(state, 
table, bindVariables, orderings, containsOnlyStaticColumns, forView);
 
             // If we order post-query, the sorted column needs to be in the 
ResultSet for sorting,
             // even if we don't ultimately ship them to the client 
(CASSANDRA-4911).
-            Map<ColumnMetadata, Boolean> orderingColumns = 
getOrderingColumns(table);
-            Set<ColumnMetadata> resultSetOrderingColumns = 
restrictions.keyIsInRelation() ? orderingColumns.keySet()
-                                                                               
           : Collections.emptySet();
+            Map<ColumnMetadata, Ordering> orderingColumns = 
getOrderingColumns(orderings);
+            Set<ColumnMetadata> resultSetOrderingColumns = 
getResultSetOrdering(restrictions, orderingColumns);

Review Comment:
   It seems that somehow the vector column of an ANN query is always included 
in the results set, even if it's not included in the selection. This 
single-node dtest shows the issue:
   ```java
   try (Cluster cluster = init(Cluster.build(1).start()))
   {
    cluster.schemaChange(withKeyspace("CREATE TABLE %s.t (k int PRIMARY KEY, v 
vector<float, 1>, c int)"));
    cluster.schemaChange(withKeyspace("CREATE CUSTOM INDEX ON %s.t(v) USING 
'StorageAttachedIndex'"));
   
    cluster.coordinator(1).execute(withKeyspace("INSERT INTO %s.t (k, v, c) 
VALUES (0, [1], 2)"), ConsistencyLevel.QUORUM);
   
    String query = withKeyspace("SELECT c FROM %s.t ORDER BY v ANN OF [1] LIMIT 
10");
    assertRows(cluster.coordinator(1).execute(query, ConsistencyLevel.QUORUM), 
row(2)); // includes the vector column!!
   }
   ```
   We can also reproduce it with a unit test, but it requires to define a page 
size, as I think drivers usually do:
   ```java
   @Test
   public void testSelection() throws Throwable
   {
       createTable("CREATE TABLE %s (k int PRIMARY KEY, v vector<float, 1>, c 
int)");
       createIndex("CREATE CUSTOM INDEX ON %s(v) USING 'StorageAttachedIndex'");
       execute("INSERT INTO %s (k, v, c) VALUES (0, [1], 2)");
   
       String query = "SELECT c FROM %s ORDER BY v ANN OF [1] LIMIT 10";
       assertRows(execute(query), row(2));
       
       requireNetwork();
       assertRowsNet(executeNet(query), row(2));
       assertRowsNet(executeNetWithPaging(query, 1000), row(2)); // wrongly 
includes the vector column
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to