{"record":{"id":"064228cdeaf00ab0","repo":"apache/cassandra","slug":"top-k-queries-do-not-support-paging-and-the-page-s","errorCode":null,"errorMessage":"Top-K queries do not support paging and the page size is set to %d, which is less than LIMIT %d. The page size has been set to %d to match the LIMIT.","messagePattern":"Top-K queries do not support paging and the page size is set to (.+?), which is less than LIMIT (.+?)\\. The page size has been set to (.+?) to match the LIMIT\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cql3/statements/SelectStatement.java","lineNumber":418,"sourceCode":"                ConsistencyLevel supplied = options.getConsistency();\n                ConsistencyLevel downgrade = supplied.isDatacenterLocal() ? ConsistencyLevel.LOCAL_ONE : ConsistencyLevel.ONE;\n\n                options = QueryOptions.withConsistencyLevel(options, downgrade);\n\n                ClientWarn.instance.warn(String.format(TOPK_CONSISTENCY_LEVEL_WARNING, supplied, downgrade));\n            }\n\n            checkFalse(limit.isUnlimited(), TOPK_LIMIT_ERROR);\n\n            checkFalse(limit.perPartitionCount() != DataLimits.NO_LIMIT, TOPK_PARTITION_LIMIT_ERROR);\n\n            if (pageSize > 0 && pageSize < limit.count())\n            {\n                int oldPageSize = pageSize;\n                pageSize = limit.count();\n                limit = getDataLimits(userLimit, userPerPartitionLimit, pageSize, aggregationSpec);\n                options = QueryOptions.withPageSize(options, pageSize);\n                ClientWarn.instance.warn(String.format(TOPK_PAGE_SIZE_WARNING, oldPageSize, limit.count(), pageSize));\n            }\n        }\n\n        ReadQuery query = getQuery(options, state.getClientState(), selectors.getColumnFilter(), nowInSec, limit, PotentialTxnConflicts.DISALLOW);\n\n        if (options.isReadThresholdsEnabled())\n            query.trackWarnings();\n        ResultMessage.Rows rows;\n\n        if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize) || query.isTopK()))\n        {\n            rows = execute(query, options, state.getClientState(), selectors, nowInSec, userLimit, null, requestTime, unmask);\n        }\n        else\n        {\n            QueryPager pager = getPager(query, options);\n\n            rows = execute(state,","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java#L400-L436","documentation":"Top-K (ANN) queries do not support paging. If the configured page size is non-zero and smaller than the query LIMIT, the coordinator bumps the page size to the LIMIT so the whole top-K result is fetched in one page, and warns the client about the change.","triggerScenarios":"Executing an ANN SELECT with LIMIT N while the driver page fetch size is set to a value between 1 and N-1; SelectStatement.execute rewrites the page size and warns via ClientWarn.","commonSituations":"Driver default fetch size (5000) exceeding ANN LIMIT is fine, but a reduced fetch size (e.g. setPageSize(100) for memory reasons) collides with a larger LIMIT; global driver config tuned for regular queries applied to vector queries.","solutions":["Set page size >= LIMIT for ANN queries, or remove explicit page-size settings","Set fetch size to the ANN LIMIT exactly (e.g. setPageSize(limit))","Use a dedicated execution profile for vector queries with an appropriate fetch size"],"exampleFix":"// before\nstatement.setPageSize(100); // with LIMIT 500 ANN query\n// after\nstatement.setPageSize(500); // match the ANN LIMIT, paging unsupported","handlingStrategy":"validation","validationCode":"if (isAnnQuery && pageSize > 0 && pageSize < limit) {\n    pageSize = limit; // ANN queries do not support paging below LIMIT\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match fetch size to ANN LIMIT","Use a separate execution profile for ANN queries","Keep a warning handler registered to observe page-size rewrites"],"tags":["cassandra","paging","vector-search","client-warning"],"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"}