@@ -156,13 +156,13 @@ public static StatementRestrictions empty(StatementType type, TableMetadata tabl
156
156
return new StatementRestrictions (type , table , IndexHints .NONE , false );
157
157
}
158
158
159
- private StatementRestrictions (StatementType type , TableMetadata table , IndexHints indexHints , boolean allowFiltering )
159
+ private StatementRestrictions (StatementType type , TableMetadata table , IndexHints indexHints , boolean allowFilteringOfPrimaryKeys )
160
160
{
161
161
this .type = type ;
162
162
this .table = table ;
163
163
this .indexHints = indexHints ;
164
164
this .partitionKeyRestrictions = new PartitionKeyRestrictions (table .partitionKeyAsClusteringComparator ());
165
- this .clusteringColumnsRestrictions = new ClusteringColumnRestrictions (table , allowFiltering );
165
+ this .clusteringColumnsRestrictions = new ClusteringColumnRestrictions (table , allowFilteringOfPrimaryKeys );
166
166
this .nonPrimaryKeyRestrictions = RestrictionSet .empty ();
167
167
this .notNullColumns = new HashSet <>();
168
168
}
@@ -370,7 +370,7 @@ else if (operator.requiresIndexing())
370
370
}
371
371
else
372
372
{
373
- if (!allowFiltering && requiresAllowFilteringIfNotSpecified (table ))
373
+ if (!allowFiltering && requiresAllowFilteringIfNotSpecified (table , false ))
374
374
throw invalidRequest (allowFilteringMessage (state ));
375
375
}
376
376
@@ -381,14 +381,14 @@ else if (operator.requiresIndexing())
381
381
validateSecondaryIndexSelections ();
382
382
}
383
383
384
- public static boolean requiresAllowFilteringIfNotSpecified (TableMetadata metadata )
384
+ public static boolean requiresAllowFilteringIfNotSpecified (TableMetadata metadata , boolean isPrimaryKey )
385
385
{
386
386
if (!metadata .isVirtual ())
387
387
return true ;
388
388
389
389
VirtualTable tableNullable = VirtualKeyspaceRegistry .instance .getTableNullable (metadata .id );
390
390
assert tableNullable != null ;
391
- return !tableNullable .allowFilteringImplicitly ();
391
+ return isPrimaryKey ? ! tableNullable . allowFilteringPrimaryKeysImplicitly () : !tableNullable .allowFilteringImplicitly ();
392
392
}
393
393
394
394
private void addRestriction (Restriction restriction , IndexRegistry indexRegistry , IndexHints indexHints )
@@ -593,7 +593,7 @@ private void processPartitionKeyRestrictions(ClientState state, boolean hasQueri
593
593
// components must have a EQ. Only the last partition key component can be in IN relation.
594
594
if (partitionKeyRestrictions .needFiltering ())
595
595
{
596
- if (!allowFiltering && !forView && !hasQueriableIndex && requiresAllowFilteringIfNotSpecified (table ))
596
+ if (!allowFiltering && !forView && !hasQueriableIndex && requiresAllowFilteringIfNotSpecified (table , true ))
597
597
throw new InvalidRequestException (allowFilteringMessage (state ));
598
598
599
599
isKeyRange = true ;
0 commit comments