@@ -156,13 +156,13 @@ public static StatementRestrictions empty(StatementType type, TableMetadata tabl
156156 return new StatementRestrictions (type , table , IndexHints .NONE , false );
157157 }
158158
159- private StatementRestrictions (StatementType type , TableMetadata table , IndexHints indexHints , boolean allowFiltering )
159+ private StatementRestrictions (StatementType type , TableMetadata table , IndexHints indexHints , boolean allowFilteringOfPrimaryKeys )
160160 {
161161 this .type = type ;
162162 this .table = table ;
163163 this .indexHints = indexHints ;
164164 this .partitionKeyRestrictions = new PartitionKeyRestrictions (table .partitionKeyAsClusteringComparator ());
165- this .clusteringColumnsRestrictions = new ClusteringColumnRestrictions (table , allowFiltering );
165+ this .clusteringColumnsRestrictions = new ClusteringColumnRestrictions (table , allowFilteringOfPrimaryKeys );
166166 this .nonPrimaryKeyRestrictions = RestrictionSet .empty ();
167167 this .notNullColumns = new HashSet <>();
168168 }
@@ -370,7 +370,7 @@ else if (operator.requiresIndexing())
370370 }
371371 else
372372 {
373- if (!allowFiltering && requiresAllowFilteringIfNotSpecified (table ))
373+ if (!allowFiltering && requiresAllowFilteringIfNotSpecified (table , false ))
374374 throw invalidRequest (allowFilteringMessage (state ));
375375 }
376376
@@ -381,14 +381,14 @@ else if (operator.requiresIndexing())
381381 validateSecondaryIndexSelections ();
382382 }
383383
384- public static boolean requiresAllowFilteringIfNotSpecified (TableMetadata metadata )
384+ public static boolean requiresAllowFilteringIfNotSpecified (TableMetadata metadata , boolean isPrimaryKey )
385385 {
386386 if (!metadata .isVirtual ())
387387 return true ;
388388
389389 VirtualTable tableNullable = VirtualKeyspaceRegistry .instance .getTableNullable (metadata .id );
390390 assert tableNullable != null ;
391- return !tableNullable .allowFilteringImplicitly ();
391+ return isPrimaryKey ? ! tableNullable . allowFilteringPrimaryKeysImplicitly () : !tableNullable .allowFilteringImplicitly ();
392392 }
393393
394394 private void addRestriction (Restriction restriction , IndexRegistry indexRegistry , IndexHints indexHints )
@@ -593,7 +593,7 @@ private void processPartitionKeyRestrictions(ClientState state, boolean hasQueri
593593 // components must have a EQ. Only the last partition key component can be in IN relation.
594594 if (partitionKeyRestrictions .needFiltering ())
595595 {
596- if (!allowFiltering && !forView && !hasQueriableIndex && requiresAllowFilteringIfNotSpecified (table ))
596+ if (!allowFiltering && !forView && !hasQueriableIndex && requiresAllowFilteringIfNotSpecified (table , true ))
597597 throw new InvalidRequestException (allowFilteringMessage (state ));
598598
599599 isKeyRange = true ;
0 commit comments