Skip to content

Conversation

@feiniaofeiafei
Copy link
Contributor

cherry-pick #43332 to branch-3.0

…column partition pruning (apache#43332)

For example, with a partition defined as PARTITION BY RANGE (a, dt)
[(0, '2024-01-01 00:00:00'), (10, '2024-01-10 00:00:00')).
With the predicate:
WHERE a = 0 AND date_trunc(dt, 'day') <= '2024-01-10 00:00:00',

partition pruning will expand the partition ranges to:

a = 0, dt in ['2024-01-01 00:00:00', +∞)
a = 1, dt in (-∞, +∞)
a = 2, dt in (-∞, +∞)
...
a = 10, dt in (-∞, '2024-01-10 00:00:00')

Each of these eleven ranges will be evaluated against the predicate. If
all evaluations return False, the partition can be pruned.
During the evaluation of the first range
(a = 0, dt in ['2024-01-01 00:00:00', +∞)),
the range of date_trunc(dt, 'day') is calculated as
['2024-01-01', +∞) and stored in rangeMap.

However, subsequent evaluations (e.g., for a = 2, dt in (-∞, +∞)
 reuse this range ['2024-01-01', +∞),
which is incorrect. For a = 2, the correct range should be
(-∞, +∞) for date_trunc(dt, 'day').

Due to this incorrect reuse, the range for a = 2, dt in (-∞, +∞) will
incorrectly evaluate to False, causing improper pruning of the
partition.
The correct approach is to place rangeMap within the context, so that a
new rangeMap is constructed for each evaluation.
@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@feiniaofeiafei
Copy link
Contributor Author

run buildall

@morrySnow morrySnow merged commit f650a16 into apache:branch-3.0 Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants