mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-03 13:37:04 +00:00
cql3: add needs_filtering to primary key restrictions
Primary key restrictions sometimes require filtering. These functions return true if ALLOW FILTERING needs to be enabled in order to satisfy these restrictions.
This commit is contained in:
@@ -95,7 +95,32 @@ public:
|
||||
uint32_t size() const override {
|
||||
return uint32_t(get_column_defs().size());
|
||||
}
|
||||
|
||||
bool has_unrestricted_components(const schema& schema) const;
|
||||
|
||||
virtual bool needs_filtering(const schema& schema) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool primary_key_restrictions<partition_key>::has_unrestricted_components(const schema& schema) const {
|
||||
return size() < schema.partition_key_size();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool primary_key_restrictions<clustering_key>::has_unrestricted_components(const schema& schema) const {
|
||||
return size() < schema.clustering_key_size();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool primary_key_restrictions<partition_key>::needs_filtering(const schema& schema) const {
|
||||
return !empty() && !is_on_token() && (has_unrestricted_components(schema) || is_contains() || is_slice());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool primary_key_restrictions<clustering_key>::needs_filtering(const schema& schema) const {
|
||||
// Currently only overloaded single_column_primary_key_restrictions will require ALLOW FILTERING
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,6 +349,8 @@ public:
|
||||
_restrictions->restrictions() | boost::adaptors::map_values,
|
||||
[&] (auto&& r) { return r->is_satisfied_by(schema, key, ckey, cells, options, now); });
|
||||
}
|
||||
|
||||
virtual bool needs_filtering(const schema& schema) const override;
|
||||
};
|
||||
|
||||
template<>
|
||||
@@ -406,6 +408,29 @@ single_column_primary_key_restrictions<clustering_key_prefix>::bounds_ranges(con
|
||||
return bounds;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool single_column_primary_key_restrictions<partition_key>::needs_filtering(const schema& schema) const {
|
||||
return primary_key_restrictions<partition_key>::needs_filtering(schema);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool single_column_primary_key_restrictions<clustering_key>::needs_filtering(const schema& schema) const {
|
||||
// Restrictions currently need filtering in three cases:
|
||||
// 1. any of them is a CONTAINS restriction
|
||||
// 2. restrictions do not form a contiguous prefix (i.e. there are gaps in it)
|
||||
// 3. a SLICE restriction isn't on a last place
|
||||
column_id position = 0;
|
||||
for (const auto& restriction : _restrictions->restrictions() | boost::adaptors::map_values) {
|
||||
if (restriction->is_contains() || position != restriction->get_column_def().id) {
|
||||
return true;
|
||||
}
|
||||
if (!restriction->is_slice()) {
|
||||
position = restriction->get_column_def().id + 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user