diff --git a/src/Storages/prepareReadingFromFormat.cpp b/src/Storages/prepareReadingFromFormat.cpp index d0d1c4ae3eeb..54ba1fc572da 100644 --- a/src/Storages/prepareReadingFromFormat.cpp +++ b/src/Storages/prepareReadingFromFormat.cpp @@ -260,19 +260,23 @@ Names filterTupleColumnsToRead(NamesAndTypesList & requested_columns) ReadFromFormatInfo updateFormatPrewhereInfo(const ReadFromFormatInfo & info, const FilterDAGInfoPtr & row_level_filter, const PrewhereInfoPtr & prewhere_info) { - chassert(prewhere_info); + chassert(prewhere_info || row_level_filter); - if (info.prewhere_info || info.row_level_filter) + if (info.prewhere_info) throw Exception(ErrorCodes::LOGICAL_ERROR, "updateFormatPrewhereInfo called more than once"); ReadFromFormatInfo new_info; new_info.prewhere_info = prewhere_info; + new_info.row_level_filter = row_level_filter; /// Removes columns that are only used as prewhere input. /// Adds prewhere outputs (the actual prewhere filter column is only added if /// !remove_prewhere_column; but there may also be subexpressions computed by prewhere /// expression and preserved for use further down the query pipeline). - new_info.format_header = SourceStepWithFilter::applyPrewhereActions(info.format_header, row_level_filter, prewhere_info); + /// If row_level_filter was already applied in a previous call, don't re-apply it; + /// only apply the new prewhere_info on top. + new_info.format_header = SourceStepWithFilter::applyPrewhereActions( + info.format_header, info.row_level_filter ? nullptr : row_level_filter, prewhere_info); /// We assume that any format that supports prewhere also supports subset of subcolumns, so we /// don't need to replace subcolumns with their nested columns etc. diff --git a/tests/queries/0_stateless/04053_row_policy_object_storage.reference b/tests/queries/0_stateless/04053_row_policy_object_storage.reference new file mode 100644 index 000000000000..7f4f9bef5bd9 --- /dev/null +++ b/tests/queries/0_stateless/04053_row_policy_object_storage.reference @@ -0,0 +1,7 @@ +--- Row policy filters URL Parquet table --- +1 a +2 b +--- Row policy with WHERE on URL Parquet table --- +1 a +--- Row policy count on URL Parquet table --- +2 diff --git a/tests/queries/0_stateless/04053_row_policy_object_storage.sh b/tests/queries/0_stateless/04053_row_policy_object_storage.sh new file mode 100755 index 000000000000..e66ff60e8ad6 --- /dev/null +++ b/tests/queries/0_stateless/04053_row_policy_object_storage.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Tags: no-replicated-database, no-fasttest + +# Regression test: row policy on a URL table with Parquet format caused +# "Logical error: 'prewhere_info'" because updateFormatPrewhereInfo asserted +# prewhere_info was non-null, but only row_level_filter was set. + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +user="user04053_${CLICKHOUSE_DATABASE}_$RANDOM" +db=${CLICKHOUSE_DATABASE} + +${CLICKHOUSE_CLIENT} <