From 85bc5d137d44e0e058b7c249b45619ecc06362fd Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Thu, 26 Nov 2026 11:17:54 +0800 Subject: [PATCH] fix(cpp): correct NOT BETWEEN page-statistic pruning TimeBetween::satisfy(Statistic*) kept a NOT BETWEEN page only when it lay entirely outside [value1_, value2_], so a page that partially overlapped the excluded interval was silently skipped even though it still contained out-of-interval times. Align the statistic-level check with satisfy_start_end_time(): start_time_ < value1_ || end_time_ > value2_. Add a regression test covering partial-overlap and boundary cases. --- cpp/src/reader/filter/time_operator.cc | 4 +-- cpp/test/reader/filter/time_operator_test.cc | 26 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cpp/src/reader/filter/time_operator.cc b/cpp/src/reader/filter/time_operator.cc index fd3b4d4f0..dba0233d2 100644 --- a/cpp/src/reader/filter/time_operator.cc +++ b/cpp/src/reader/filter/time_operator.cc @@ -47,8 +47,8 @@ bool TimeBetween::satisfy(Statistic* statistic) { return not_; } if (not_) { - return statistic->end_time_ < value1_ || - statistic->start_time_ > value2_; + return statistic->start_time_ < value1_ || + statistic->end_time_ > value2_; } else { return statistic->end_time_ >= value1_ && statistic->start_time_ <= value2_; diff --git a/cpp/test/reader/filter/time_operator_test.cc b/cpp/test/reader/filter/time_operator_test.cc index c2ee5b1c6..246ebed53 100644 --- a/cpp/test/reader/filter/time_operator_test.cc +++ b/cpp/test/reader/filter/time_operator_test.cc @@ -150,6 +150,32 @@ TEST(TimeOperatorTest, TimeBetweenNotBetweenSemantics) { (std::vector{true, true, false, false, false, true})); } +// Regression (TsFile-191): NOT BETWEEN's statistic-level pruning used to +// keep a page only when it lay entirely outside [value1_, value2_], so a page +// that partially overlapped the interval was silently skipped even though it +// contained out-of-interval times. The correct test is "may contain a time +// outside the interval": start_time_ < value1_ || end_time_ > value2_. +TEST(TimeOperatorTest, TimeBetweenNotBetweenStatisticPartialOverlap) { + TimeBetween not_between(3, 5, /*not_between=*/true); + + // Pages partially overlapping [3, 5] still contain times outside it (e.g. + // 2 or 6), so NOT BETWEEN must keep them. The old pruning returned false + // here and silently dropped matching rows. + EXPECT_TRUE(satisfy_stat(not_between, 2, 4)); + EXPECT_TRUE(satisfy_stat(not_between, 4, 6)); + EXPECT_TRUE(satisfy_stat(not_between, 2, 6)); + + // Pages wholly inside [3, 5] match nothing and are correctly pruned. + EXPECT_FALSE(satisfy_stat(not_between, 3, 4)); + EXPECT_FALSE(satisfy_stat(not_between, 3, 3)); + EXPECT_FALSE(satisfy_stat(not_between, 5, 5)); + EXPECT_FALSE(satisfy_stat(not_between, 3, 5)); + + // Pages wholly outside the interval are kept. + EXPECT_TRUE(satisfy_stat(not_between, 1, 2)); + EXPECT_TRUE(satisfy_stat(not_between, 6, 9)); +} + TEST(TimeOperatorTest, TimeBetweenInvertedRange) { TimeBetween inverted(5, 3, /*not_between=*/false); Statistic any = make_stat(0, 100);