From 7bce15324748014412db5c93e7775198e528c993 Mon Sep 17 00:00:00 2001 From: Mikhail Koviazin Date: Mon, 30 Mar 2026 12:44:24 +0200 Subject: [PATCH] Fix row policies silently ignored on Iceberg tables with PREWHERE enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Iceberg read optimization (`allow_experimental_iceberg_read_optimization`) identifies constant columns from Iceberg metadata and removes them from the read request. When all requested columns become constant, it sets `need_only_count = true`, which tells the Parquet reader to skip all initialization — including `preparePrewhere` — and just return the raw row count from file metadata. This completely bypasses `row_level_filter` (row policies) and `prewhere_info`, returning unfiltered row counts. The InterpreterSelectQuery relies on the storage to apply these filters when `supportsPrewhere` is true and does not add a fallback FilterStep to the query plan, so the filter is silently lost. The fix prevents `need_only_count` from being set when an active `row_level_filter` or `prewhere_info` exists in the format filter info. Fixes #1595 --- src/Storages/ObjectStorage/StorageObjectStorageSource.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp b/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp index b07deb3a472b..41cbde9db05f 100644 --- a/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp +++ b/src/Storages/ObjectStorage/StorageObjectStorageSource.cpp @@ -789,7 +789,8 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade if (requested_columns_copy.size() + constant_columns.size() != original_columns) throw Exception(ErrorCodes::LOGICAL_ERROR, "Can't remove constant columns for file {} correct, fallback to read. Founded constant columns: [{}]", object_info->getPath(), constant_columns); - if (requested_columns_copy.empty()) + if (requested_columns_copy.empty() + && (!format_filter_info || (!format_filter_info->row_level_filter && !format_filter_info->prewhere_info))) need_only_count = true; } }