Skip to content

Commit 036f1bc

Browse files
committed
CNDB-14343: Fix ANN queries on primary key columns
1 parent e0a509f commit 036f1bc

File tree

4 files changed

+342
-11
lines changed

4 files changed

+342
-11
lines changed

src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,19 +666,19 @@ public UnfilteredRowIterator readAndValidatePartition(PrimaryKey pk, List<Primar
666666
{
667667
queryContext.addPartitionsRead(1);
668668
queryContext.checkpoint();
669-
var staticRow = partition.staticRow();
670669
UnfilteredRowIterator clusters = applyIndexFilter(partition, filterTree, queryContext);
671670

672-
if (clusters == null || !clusters.hasNext())
673-
{
674-
processedKeys.add(pk);
671+
if (clusters == null)
675672
return null;
676-
}
677673

674+
if (!clusters.hasNext())
675+
throw new UnsupportedOperationException("Static columns are not supported");
676+
677+
var row = clusters.next();
678+
var staticRow = partition.staticRow();
678679
var now = FBUtilities.nowInSeconds();
679680
boolean isRowValid = false;
680-
var row = clusters.next();
681-
assert !clusters.hasNext() : "Expected only one row per partition";
681+
682682
if (!row.isRangeTombstoneMarker())
683683
{
684684
for (PrimaryKeyWithSortKey sourceKey : sourceKeys)

src/java/org/apache/cassandra/index/sai/plan/TopKProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private float getScoreForRow(DecoratedKey key, Row row)
303303
{
304304
ColumnMetadata column = indexContext.getDefinition();
305305

306-
if (column.isPrimaryKeyColumn() && key == null)
306+
if (column.isPartitionKey() && key == null)
307307
return 0;
308308

309309
if (column.isStatic() && !row.isStatic())

src/java/org/apache/cassandra/index/sai/utils/PrimaryKeyWithSortKey.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.cassandra.dht.Token;
2929
import org.apache.cassandra.index.sai.IndexContext;
3030
import org.apache.cassandra.io.sstable.SSTableId;
31+
import org.apache.cassandra.schema.ColumnMetadata;
3132
import org.apache.cassandra.utils.bytecomparable.ByteComparable;
3233
import org.apache.cassandra.utils.bytecomparable.ByteSource;
3334

@@ -51,7 +52,7 @@ protected PrimaryKeyWithSortKey(IndexContext context, Memtable sourceTable, Prim
5152
this.primaryKey = primaryKey;
5253
}
5354

54-
protected PrimaryKeyWithSortKey(IndexContext context, SSTableId sourceTable, PrimaryKey primaryKey)
55+
protected PrimaryKeyWithSortKey(IndexContext context, SSTableId<?> sourceTable, PrimaryKey primaryKey)
5556
{
5657
this.context = context;
5758
this.sourceTable = sourceTable;
@@ -65,10 +66,14 @@ public PrimaryKey primaryKey()
6566

6667
public boolean isIndexDataValid(Row row, int nowInSecs)
6768
{
68-
assert context.getDefinition().isRegular() : "Only regular columns are supported, got " + context.getDefinition();
69-
var cell = row.getCell(context.getDefinition());
69+
ColumnMetadata column = context.getDefinition();
70+
if (!column.isRegular())
71+
return true;
72+
73+
var cell = row.getCell(column);
7074
if (!cell.isLive(nowInSecs))
7175
return false;
76+
7277
assert cell instanceof CellWithSourceTable : "Expected CellWithSource, got " + cell.getClass();
7378
return sourceTable.equals(((CellWithSourceTable<?>) cell).sourceTable())
7479
&& isIndexDataEqualToLiveData(cell.buffer());

0 commit comments

Comments
 (0)