view: Add matches_view_filter() function

This patch adds the matches_view_filter() function which specifies
whether a given base row matches the view filter. Unlike
may_be_affected_by(), this function has no false positives.

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2016-12-29 11:09:28 +00:00
parent 7be0f319d4
commit 734ad80390
2 changed files with 28 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
*/
#include <boost/range/algorithm/transform.hpp>
#include <boost/range/adaptors.hpp>
#include "clustering_bounds_comparator.hh"
#include "cql3/statements/select_statement.hh"
@@ -124,6 +125,15 @@ bool view::may_be_affected_by(const ::schema& base, const dht::decorated_key& ke
return affected;
}
bool view::matches_view_filter(const ::schema& base, const partition_key& key, const clustering_row& update, gc_clock::time_point now) const {
return clustering_prefix_matches(base, key, update.key()) &&
boost::algorithm::all_of(
select_statement().get_restrictions()->get_non_pk_restriction() | boost::adaptors::map_values,
[&] (auto&& r) {
return r->is_satisfied_by(base, key, update.key(), update.cells(), cql3::query_options({ }), now);
});
}
} // namespace view
} // namespace db

View File

@@ -22,6 +22,7 @@
#pragma once
#include "dht/i_partitioner.hh"
#include "gc_clock.hh"
#include "query-request.hh"
#include "schema.hh"
#include "stdx.hh"
@@ -81,6 +82,23 @@ public:
*/
bool may_be_affected_by(const ::schema& base, const dht::decorated_key& key, const rows_entry& update) const;
/**
* Whether a given base row matches the view filter (and thus if the view should have a corresponding entry).
*
* Note that this differs from may_be_affected_by in that the provide row must be the current
* state of the base row, not just some updates to it. This function also has no false positive: a base
* row either does or doesn't match the view filter.
*
* Also note that this function doesn't check the partition key, as it assumes the upper layers
* have already filtered out the views that are not affected.
*
* @param base the base table schema.
* @param key the partition key that is updated.
* @param update the current state of a particular base row.
* @param now the current time in seconds (to decide what is live and what isn't).
* @return whether the base row matches the view filter.
*/
bool matches_view_filter(const ::schema& base, const partition_key& key, const clustering_row& update, gc_clock::time_point now) const;
private:
cql3::statements::select_statement& select_statement() const;
const query::partition_slice& partition_slice() const;