From 46b4b599456b318d2216996d52ca6fc76ea1b9e7 Mon Sep 17 00:00:00 2001 From: Dejan Mircevski Date: Wed, 16 Dec 2020 15:00:29 -0500 Subject: [PATCH] cql3: Fix value_for when restriction is impossible Previously, single_column_restrictions::value_for() assumed that a column's restriction specifies exactly one value for the column. But since 37ebe521e3, multiple equalities on the same column are allowed, so the restriction could be a conjunction of conflicting equalities (eg, c=1 AND c=0). That violates an assert and crashes Scylla. This patch fixes value_for() by gracefully handling the impossible-restriction case. Fixes #7772 Signed-off-by: Dejan Mircevski --- cql3/restrictions/single_column_restrictions.hh | 3 +++ test/boost/secondary_index_test.cc | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cql3/restrictions/single_column_restrictions.hh b/cql3/restrictions/single_column_restrictions.hh index 3590917c9570..b9881a6ba51b 100644 --- a/cql3/restrictions/single_column_restrictions.hh +++ b/cql3/restrictions/single_column_restrictions.hh @@ -108,6 +108,9 @@ public: return bytes_opt{}; } else { const auto values = std::get(possible_lhs_values(&cdef, it->second->expression, options)); + if (values.empty()) { + return bytes_opt{}; + } assert(values.size() == 1); return values.front(); } diff --git a/test/boost/secondary_index_test.cc b/test/boost/secondary_index_test.cc index a08d27e94048..18473d2e0675 100644 --- a/test/boost/secondary_index_test.cc +++ b/test/boost/secondary_index_test.cc @@ -76,6 +76,14 @@ SEASTAR_TEST_CASE(test_secondary_index_clustering_key_query) { { utf8_type->decompose(sstring("dcurrorw@techcrunch.com")) }, { utf8_type->decompose(sstring("beassebyv@house.gov")) }, }); + }).then([&e] { + return e.execute_cql("select country from users where country='France' and country='Denmark'"); // #7772 + }).then([&e] (shared_ptr msg) { + assert_that(msg).is_rows().is_empty(); + }).then([&e] { + return e.execute_cql("select country from users where country='Denmark' and country='Denmark'"); + }).then([&e] (shared_ptr msg) { + assert_that(msg).is_rows().with_rows({{utf8_type->decompose(sstring("Denmark"))}}); }); }); }