From c3c29b8467d47467e28e85f818435a05bd997833 Mon Sep 17 00:00:00 2001 From: "p.ostrovskiy" Date: Wed, 24 Sep 2025 15:52:15 +0300 Subject: [PATCH] Fix performance issue in decimal bounds processing for integer decimals When scale = 0 (integer decimals), `while (--scale)` iterates through all int32_t values (~4.3B iterations) causing ~3s delay per value and corrupting statistics via incorrect `unscaled_value += scaler`. --- src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp b/src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp index a295071f260..d02279bf54b 100644 --- a/src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp +++ b/src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp @@ -69,9 +69,8 @@ namespace /// To handle this issue we subtract 1 from the integral part for lower_bound and add 1 to integral /// part of upper_bound. This produces: 17.22 -> [16.0, 18.0]. So this is more rough boundary, /// but at least it doesn't lead to incorrect results. - { + if (int32_t scale = DB::getDecimalScale(*non_nullable_type)){ int64_t scaler = lower_bound ? -10 : 10; - int32_t scale = DB::getDecimalScale(*non_nullable_type); while (--scale) scaler *= 10;