jasonstack commented on code in PR #3649: URL: https://github.com/apache/cassandra/pull/3649#discussion_r1832203612
########## src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java: ########## @@ -222,45 +236,57 @@ public UnfilteredRowIterator computeNext() /** * Returns the next available key contained by one of the keyRanges and selected by the queryController. * If the next key falls out of the current key range, it skips to the next key range, and so on. - * If no more keys acceptd by the controller are available, returns null. + * If no more keys acceptd by the controller are available, returns an empty list. */ - private @Nullable PrimaryKey nextSelectedKeyInRange() + private List<PrimaryKey> nextSelectedKeyInRange() { + List<PrimaryKey> threadLocalNextKeys = nextKeys.get(); + threadLocalNextKeys.clear(); PrimaryKey key; + do { key = nextKeyInRange(); + + if (key == null) + return Collections.emptyList(); } - while (key != null && queryController.doesNotSelect(key)); - return key; + while (queryController.doesNotSelect(key) || key.equals(lastKey)); + + lastKey = key; + threadLocalNextKeys.add(key); + return threadLocalNextKeys; } /** - * Retrieves the next primary key that belongs to the given partition and is selected by the query controller. - * The underlying key iterator is advanced only if the key belongs to the same partition. - * <p> - * Returns null if: - * <ul> - * <li>there are no more keys</li> - * <li>the next key is beyond the upper bound</li> - * <li>the next key belongs to a different partition</li> - * </ul> - * </p> + * Retrieves the next batch of primary keys (i.e. up to {@link #partitionRowBatchSize} of them) that belong to + * the given partition and are selected by the query controller, advancing the underlying iterator only while + * the next key belongs to that partition. + * + * @return a list of up to {@link #partitionRowBatchSize} primary keys within the given partition and data range */ - private @Nullable PrimaryKey nextSelectedKeyInPartition(DecoratedKey partitionKey) + private List<PrimaryKey> nextSelectedKeysInPartition(DecoratedKey partitionKey) Review Comment: so, for this wide schema: ``` createTable("CREATE TABLE %s (pk int, ck int, v1 int, primary key(pk, ck))"); executeNet("CREATE INDEX index_1 ON %s(v1) USING 'sai'"); waitForTableIndexesQueryable(); execute("INSERT INTO %s (pk, ck, v1) VALUES(1, 1, 1)"); execute("INSERT INTO %s (pk, ck, v1) VALUES(1, 2, 1)"); execute("INSERT INTO %s (pk, ck, v1) VALUES(1, 3, 1)"); execute("INSERT INTO %s (pk, ck, v1) VALUES(1, 4, 1)"); execute("INSERT INTO %s (pk, ck, v1) VALUES(1, 5, 1)"); flush(); ResultSet rows = executeNet("SELECT * FROM %s WHERE v1 = 1"); ``` `queryStorageAndFilter` is called twice: * first time reading with pk=1 and ck=1 - PrimaryKey is fetched from `nextSelectedKeyInRange` * second time reading with pk=1 and ck in [2,3,4,5] - PrimaryKeys are fetched from `nextSelectedKeysInPartition` can we improve it to execute one local read? -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org