Skip to content

Commit bc3a635

Browse files
psarnaavikivity
authored andcommitted
view: exclude using static columns in the view filter
The code which applied view filtering (i.e. a condition placed on a view column, e.g. "WHERE v = 42") erroneously used a wildcard selection, which also assumes that static columns are needed, if the base table contains any such columns. The filtering code currently assumes that no such columns are fetched, so the selection is amended to only ask for regular columns (primary key columns are sent anyway, because they are enabled via slice options, so no need to ask for them explicitly). Fixes scylladb#10851 Closes scylladb#10855
1 parent b0b29ed commit bc3a635

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

db/view/view.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ class view_filter_checking_visitor {
313313
view_filter_checking_visitor(const schema& base, const view_info& view)
314314
: _base(base)
315315
, _view(view)
316-
, _selection(cql3::selection::selection::wildcard(_base.shared_from_this()))
316+
, _selection(cql3::selection::selection::for_columns(_base.shared_from_this(),
317+
boost::copy_range<std::vector<const column_definition*>>(
318+
_base.regular_columns() | boost::adaptors::transformed([] (const column_definition& cdef) { return &cdef; }))
319+
)
320+
)
317321
{}
318322

319323
void accept_new_partition(const partition_key& key, uint64_t row_count) {

test/cql-pytest/test_materialized_view.py

+14
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,17 @@ def test_mv_is_not_null(cql, test_keyspace):
192192
assert list(cql.execute(f"SELECT * FROM {mv}")) == [('cat', 123)]
193193
cql.execute(f"DELETE v FROM {table} WHERE p=123")
194194
assert list(cql.execute(f"SELECT * FROM {mv}")) == []
195+
196+
# Refs #10851. The code used to create a wildcard selection for all columns,
197+
# which erroneously also includes static columns if such are present in the
198+
# base table. Currently views only operate on regular columns and the filtering
199+
# code assumes that. TODO: once we implement static column support for materialized
200+
# views, this test case will be a nice regression test to ensure that everything still
201+
# works if the static columns are *not* used in the view.
202+
def test_filter_with_unused_static_column(cql, test_keyspace):
203+
schema = 'p int, c int, v int, s int static, primary key (p,c)'
204+
with new_test_table(cql, test_keyspace, schema) as table:
205+
with new_materialized_view(cql, table, select='p,c,v', pk='p,c,v', where='p IS NOT NULL and c IS NOT NULL and v = 44') as mv:
206+
cql.execute(f"INSERT INTO {table} (p,c,v) VALUES (42,43,44)")
207+
cql.execute(f"INSERT INTO {table} (p,c,v) VALUES (1,2,3)")
208+
assert list(cql.execute(f"SELECT * FROM {mv}")) == [(42, 43, 44)]

0 commit comments

Comments
 (0)