diff --git a/sc/source/core/data/queryiter.cxx b/sc/source/core/data/queryiter.cxx index 75a2fe28b7a6..0cd1a19ec744 100644 --- a/sc/source/core/data/queryiter.cxx +++ b/sc/source/core/data/queryiter.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -1106,7 +1107,12 @@ void ScQueryCellIteratorAccessSpecific< ScQueryCellIteratorAccess::SortedCache > { ++sortedCachePos; nRow = sortedCache->rowForIndex(sortedCachePos); - maCurPos = rCol.maCells.position(nRow); + // Avoid mdds position() call if row is in the same block. + if(maCurPos.first != rCol.maCells.end() && o3tl::make_unsigned(nRow) >= maCurPos.first->position + && o3tl::make_unsigned(nRow) < maCurPos.first->position + maCurPos.first->size) + maCurPos.second = nRow - maCurPos.first->position; + else + maCurPos = rCol.maCells.position(nRow); } else {