From 53f47d4e6764e321e6ccb452b86bd230db74507c Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Sun, 5 Apr 2020 21:25:30 +0200 Subject: [PATCH] cql3: fix generating base keys from empty index paging state An empty partition/clustering key pair is a valid state of the query paging state. Unfortunately, recent attempts at debugging a flaky test resulted in introducing an assertion which breaks when trying to generate a key from such a pair. In order to keep the assertion (since it still makes sense in its scope), but at the same time translate empty keys properly, empty keys are now explicitly processed at the beginning of the function. This behaviour was 100% reproducible in a secondary index dtest below. Fixes #6134 Refs #5856 Tests: unit(dev), dtest(TestSecondaryIndexes.test_truncate_base) (cherry picked from commit 45751ee24fc0dec9ec84da285af742d8d83462ce) --- cql3/statements/select_statement.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index 91434359b6..a1a6b6ff08 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -434,6 +434,12 @@ GCC6_CONCEPT( static KeyType generate_base_key_from_index_pk(const partition_key& index_pk, const std::optional& index_ck, const schema& base_schema, const schema& view_schema) { const auto& base_columns = std::is_same_v ? base_schema.partition_key_columns() : base_schema.clustering_key_columns(); + + // An empty key in the index paging state translates to an empty base key + if (index_pk.is_empty() && !index_ck) { + return KeyType::make_empty(); + } + std::vector exploded_base_key; exploded_base_key.reserve(base_columns.size()); @@ -507,8 +513,7 @@ indexed_table_select_statement::do_execute_base_query( if (old_paging_state && concurrency == 1) { auto base_pk = generate_base_key_from_index_pk(old_paging_state->get_partition_key(), old_paging_state->get_clustering_key(), *_schema, *_view_schema); - if (_schema->clustering_key_size() > 0) { - assert(old_paging_state->get_clustering_key().has_value()); + if (old_paging_state->get_clustering_key() && _schema->clustering_key_size() > 0) { auto base_ck = generate_base_key_from_index_pk(old_paging_state->get_partition_key(), old_paging_state->get_clustering_key(), *_schema, *_view_schema); command->slice.set_range(*_schema, base_pk,