Skip to content

Iceberg min/max pruning disabled for microsecond timestamp columns after #2239 #2747

Open

Description

@alsugiliazova

✅ I checked the Altinity Stable Builds lifecycle table, and the Altinity Stable Build version I'm using is still supported.

Type of problem

Bug report - something's broken

Describe the situation

Since #2239 ("Fix iceberg partition pruning by nanoseconds") was merged into antalya-26.6, min/max pruning no longer works on ordinary Iceberg timestamp columns (ClickHouse DateTime64(6)). A filter such as WHERE ts <= timestamp('2024-03-20 14:00:00') reads every data file instead of skipping the ones whose bounds exclude the predicate.

Query results are still correct. The impact is performance: every file is read, so pruning on timestamp columns is effectively disabled.

This issue:

  • Fails test_minmax_pruning (all 12 parameter combinations) and test_writes_statistics_by_minmax_pruning (all 6) with assert 0 == 3: 0 files pruned where 3 are expected
  • Reproduces on every build type that runs integration tests (amd_tsan, amd_msan, amd_asan_ubsan, arm_binary), on every run, so it is deterministic and not a sanitizer artifact
  • Was not caught on the PR because Fix iceberg partition pruning by nanoseconds #2239 excluded the ARM and all sanitizer jobs, which skipped every integration job

How to reproduce the behavior

Environment

  • Version: 26.6.8.20003.altinityantalya (also every antalya-26.6 build since 2026-10-26)
  • Build type: any

Steps

cd tests/integration
./runner 'test_storage_iceberg_with_spark/test_minmax_pruning.py::test_minmax_pruning'
./runner 'test_storage_iceberg_no_spark/test_writes_statistics_by_minmax_pruning.py::test_writes_statistics_by_minmax_pruning'

Manually: create an Iceberg table with a timestamp column and several data files with non-overlapping ts ranges, then run

SELECT * FROM t WHERE ts <= timestamp('2024-03-20 14:00:00.000000') ORDER BY ALL;
SYSTEM FLUSH LOGS;
SELECT ProfileEvents['IcebergMinMaxIndexPrunedFiles'] FROM system.query_log
WHERE query_id = '<id>' AND type = 'QueryFinish';

Expected behavior

Files whose ts lower/upper bounds exclude the predicate are pruned: IcebergMinMaxIndexPrunedFiles = 3 in the test.


Actual behavior

No files are pruned: IcebergMinMaxIndexPrunedFiles = 0.

test_storage_iceberg_with_spark/test_minmax_pruning.py:116: in test_minmax_pruning
E   assert 0 == 3
E    +  where 0 = check_validity_and_get_prunned_files("SELECT * FROM test_minmax_pruning_s3_... WHERE ts <= timestamp('2024-03-20 14:00:00.000000') ORDER BY ALL")

test_storage_iceberg_no_spark/test_writes_statistics_by_minmax_pruning.py:89: in test_writes_statistics_by_minmax_pruning
E   assert 0 == 3

Root cause analysis

#2239 added deserializeDateTime64FromBinaryRepr in src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergFieldParseHelpers.cpp, and deserializeFieldFromBinaryRepr now routes every DateTime64 bound through it. For scale 6 it returns std::nullopt unless the raw value exceeds 1e18:

if (scale == 6)
{
    if (!magnitudeExceeds(unscaled, nanoseconds_lower_threshold))   // 1e18
        return std::nullopt;

    unscaled = nanosecondsToMicrosecondsForBound(unscaled, lower_bound);
}

A real microsecond timestamp in 2024 is about 1.7e15, so a correctly written timestamp bound always takes the nullopt branch. ManifestFileIterator::processRow then skips the column (if (!left || !right) continue;), and no hyperrectangle is built for it.

The intent was to detect nanosecond statistics mistakenly written into a timestamp column. The fallback for "not nanoseconds" should be to use the value as microseconds, not to drop it:

if (scale == 6 && magnitudeExceeds(unscaled, nanoseconds_lower_threshold))
    unscaled = nanosecondsToMicrosecondsForBound(unscaled, lower_bound);
return DecimalField<DateTime64>(DateTime64(unscaled), scale);

Whether the (1e16, 1e18] ambiguity mentioned in the code comment still needs a fail-open there is a separate decision. It should not disable pruning for the normal 1970–2286 microsecond range.


Additional context

CI failure

Timeline on antalya-26.6 MasterCI

Related PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions