{"record":{"id":"22eaf44b646383de","repo":"apache/cassandra","slug":"cannot-restrict-clustering-columns-when-selecting","errorCode":null,"errorMessage":"Cannot restrict clustering columns when selecting only static columns","messagePattern":"Cannot restrict clustering columns when selecting only static columns","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":295,"sourceCode":"            filterRestrictions.add(partitionKeyRestrictions);\n\n        if (selectsOnlyStaticColumns && hasClusteringColumnsRestrictions())\n        {\n            // If the only updated/deleted columns are static, then we don't need clustering columns.\n            // And in fact, unless it is an INSERT, we reject if clustering colums are provided as that\n            // suggest something unintended. For instance, given:\n            //   CREATE TABLE t (k int, v int, s int static, PRIMARY KEY (k, v))\n            // it can make sense to do:\n            //   INSERT INTO t(k, v, s) VALUES (0, 1, 2)\n            // but both\n            //   UPDATE t SET s = 3 WHERE k = 0 AND v = 1\n            //   DELETE v FROM t WHERE k = 0 AND v = 1\n            // sounds like you don't really understand what your are doing.\n            if (type.isDelete() || type.isUpdate())\n                throw invalidRequest(\"Invalid restrictions on clustering columns since the %s statement modifies only static columns\",\n                                     type);\n            if (type.isSelect())\n                throw invalidRequest(\"Cannot restrict clustering columns when selecting only static columns\");\n        }\n\n        processClusteringColumnsRestrictions(hasQueriableIndex,\n                                             selectsOnlyStaticColumns,\n                                             forView,\n                                             allowFiltering);\n\n        // Covers indexes on the first clustering column (among others).\n        if (isKeyRange && hasQueriableClusteringColumnIndex)\n            usesSecondaryIndexing = true;\n\n        if (usesSecondaryIndexing || clusteringColumnsRestrictions.needFiltering())\n            filterRestrictions.add(clusteringColumnsRestrictions);\n\n        // Even if usesSecondaryIndexing is false at this point, we'll still have to use one if\n        // there is restrictions not covered by the PK.\n        if (!nonPrimaryKeyRestrictions.isEmpty())\n        {","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L277-L313","documentation":"Thrown when a SELECT that reads only static columns includes restrictions on clustering columns. Since static columns have a single value per partition, clustering restrictions would not change the result set, so they are rejected as meaningless.","triggerScenarios":"`SELECT k, s FROM t WHERE k=0 AND c=1` where s is static and c is clustering; queries built generically that append clustering predicates to static-only projections.","commonSituations":"Application templates generating WHERE clauses from all known columns; developers expecting static reads to be filterable per clustering row; ORM-generated queries including every key column.","solutions":["Drop the clustering column restrictions and query by partition key only: `SELECT k, s FROM t WHERE k=0`.","If per-row data is also needed, project regular columns too so clustering restrictions become valid.","Check the query builder to omit clustering predicates when only static columns are selected.","Select DISTINCT with partition-key restrictions if you want one row per partition."],"exampleFix":"// before\nSELECT k, s FROM t WHERE k = 0 AND c = 1; -- s is static\n// after\nSELECT k, s FROM t WHERE k = 0;","handlingStrategy":"validation","validationCode":"if (selectsOnlyStaticColumns(stmt) && hasClusteringRestrictions(whereClause)) throw new IllegalArgumentException(\"static-only SELECT cannot restrict clustering columns\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit clustering predicates when projecting only static columns.","Configure query builders to derive WHERE from the projection.","Add integration tests for static-column read paths."],"tags":["cql","invalid-request","static-columns","select"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}