Skip to content

Commit

Permalink
cql3: Fix value_for when restriction is impossible
Browse files Browse the repository at this point in the history
Previously, single_column_restrictions::value_for() assumed that a
column's restriction specifies exactly one value for the column.  But
since 37ebe52, 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 scylladb#7772

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>
  • Loading branch information
Dejan Mircevski committed Dec 16, 2020
1 parent 4bb1107 commit 46b4b59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cql3/restrictions/single_column_restrictions.hh
Expand Up @@ -108,6 +108,9 @@ public:
return bytes_opt{};
} else {
const auto values = std::get<expr::value_list>(possible_lhs_values(&cdef, it->second->expression, options));
if (values.empty()) {
return bytes_opt{};
}
assert(values.size() == 1);
return values.front();
}
Expand Down
8 changes: 8 additions & 0 deletions test/boost/secondary_index_test.cc
Expand Up @@ -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<cql_transport::messages::result_message> 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<cql_transport::messages::result_message> msg) {
assert_that(msg).is_rows().with_rows({{utf8_type->decompose(sstring("Denmark"))}});
});
});
}
Expand Down

0 comments on commit 46b4b59

Please sign in to comment.