{"record":{"id":"c68659988b61217d","repo":"apache/cassandra","slug":"some-clustering-keys-are-missing-s","errorCode":null,"errorMessage":"Some clustering keys are missing: %s","messagePattern":"Some clustering keys are missing: (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":674,"sourceCode":"     * Processes the clustering column restrictions.\n     *\n     * @param hasQueriableIndex <code>true</code> if some of the queried data are indexed, <code>false</code> otherwise\n     * @param selectsOnlyStaticColumns <code>true</code> if the selected or modified columns are all statics,\n     * <code>false</code> otherwise.\n     */\n    private void processClusteringColumnsRestrictions(boolean hasQueriableIndex,\n                                                      boolean selectsOnlyStaticColumns,\n                                                      boolean forView,\n                                                      boolean allowFiltering)\n    {\n        checkFalse(!type.allowClusteringColumnSlices() && clusteringColumnsRestrictions.hasSlice(),\n                   \"Slice restrictions are not supported on the clustering columns in %s statements\", type);\n\n        if (!type.allowClusteringColumnSlices()\n            && (!table.isCompactTable() || (table.isCompactTable() && !hasClusteringColumnsRestrictions())))\n        {\n            if (!selectsOnlyStaticColumns && hasUnrestrictedClusteringColumns())\n                throw invalidRequest(\"Some clustering keys are missing: %s\",\n                                     Joiner.on(\", \").join(getUnrestrictedClusteringColumns()));\n        }\n        else\n        {\n            if (clusteringColumnsRestrictions.needsFilteringOrIndexing() && !hasQueriableIndex && !allowFiltering)\n                throw invalidRequest(\"Clustering column restrictions require the use of secondary indices\" +\n                                     \" or filtering for map-element restrictions and for the following operators: %s\",\n                                     Operator.operatorsRequiringFilteringOrIndexingFor(ColumnMetadata.Kind.CLUSTERING)\n                                             .stream()\n                                             .map(Operator::toString)\n                                             .collect(Collectors.joining(\", \")));\n\n            if (hasClusteringColumnsRestrictions() && clusteringColumnsRestrictions.needFiltering())\n            {\n                if (hasQueriableIndex || forView)\n                {\n                    usesSecondaryIndexing = true;\n                }","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L656-L692","documentation":"For statement types that don't allow clustering column slices (e.g. certain key-based writes/reads), clustering keys must be fully specified. If clustering key components are left unrestricted, processClusteringColumnsRestrictions throws this error listing the missing keys.","triggerScenarios":"DELETE FROM t WHERE pk = 'a' when the table has clustering columns that aren't restricted; SELECT on a table with clustering keys supplying only the partition key in a statement type that forbids ranges.","commonSituations":"Deleting a whole partition without knowing clustering keys (use a range instead where allowed); table schema evolved to add clustering columns while queries stayed the same; compact-table semantics confusion.","solutions":["Restrict all clustering columns up to the last one you need: WHERE pk = ... AND c1 = ... AND c2 = ...","Use SELECT (which allows clustering ranges) instead of the restrictive statement type","Delete a full partition only if the table has no clustering columns, or specify full primary key per row","Model data so the primary key matches the granularity you query/delete at"],"exampleFix":"// before\nDELETE FROM orders WHERE customer_id = 'c1';  -- clustering key order_id missing\n// after\nDELETE FROM orders WHERE customer_id = 'c1' AND order_id = 'o1';","handlingStrategy":"validation","validationCode":"// Ensure all clustering key columns up to the needed prefix are restricted:\nfor (ColumnMetadata c : table.getClusteringColumns()) {\n  if (!whereColumns.contains(c.getName()) && !allowsRange) throw new IllegalArgumentException(\"Missing clustering key: \" + c.getName());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Specify the full primary key for point reads/deletes","Use SELECT with clustering ranges when whole-partition access is intended","Update queries when clustering columns are added to a table"],"tags":["cql","cassandra","clustering-key"],"backgroundTag":"missing-required-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}