Skip to content

Consolidate interval analysies from Interval and PruningPredicate #7887

Open

Description

@alamb

Is your feature request related to a problem or challenge?

We now have two ways to do range / interval analysis in DataFusion.

Having two representations is challenging because we have to implement the same logic in two places. For example,

  • supporting columns known to be NULL that @appletreeisyellow is working on will only affect PruningPredicates
  • Supporting LIKE or substr would require different code in different places
  • Support for IN lists added to PruningPredicate was not added to Interval arithmetic

The rewrite used by the PruningPrediate logic is tricky to understand and only handles very specific predicate forms (see #9184 for an essay on the topic and #9230 for an example of getting it wrong). Thus it is hard to extend the number of functions / types of predicates that are supported.

The existing range analysis are:

Interval based analysis

The ExprIntervalGraph library is used for cardinality estimation and range analysis for the symmetric hash join, and it:

  1. Can handle arbitrary expressions (such as a < b, not just constants a < 5)
  2. Has a story for how it would support user defined functions (each function would implement a range analysis)

Pruning Predicate Pruning Predicate is used to prune row groups based on min/max values which:

  1. Is vectorized (is efficient to evaluate over 1000s of containers)
  2. Handles the common cases of col <op> constant (such as a = 5, or a < 100), and conjunctions of them
  3. It is not clear (to me at least) how the rewrite that is used can handle arbitrary expressions (e.g. a < b)

Describe the solution you'd like

I would like to rewrite PruningPredicate to use ExprIntervalGraph, measuring and possibly improving the performance of ExprIntervalGraph

The benefits would be:

  1. We would have a single code path to extend and maintain
  2. We would have a clear path for handling arbitrary predicates to prune row groups

Describe alternatives you've considered

Doing so would likely require extending the interval analysis to support more operators (like IN lists) to reach feature parity with the current PruningPredicate rewrite

Additional context

There was a lot of discussion of this topic on the PR that originally introduced Intervals: #5322 (comment) between @ozankabak @metegenez and myself

Activity

  1. alamb commented on Oct 20, 2023

    @alamb
    ContributorAuthor

    @ozankabak and @tustvold I swear we have talked about this topic before but I could not find an existing ticket or discussion. Do you have any other pointers to past discussions?

  2. berkaysynnada commented on Oct 21, 2023

    @berkaysynnada
    Contributor

    I am not sure this is what you searched for but there was an issue #5535.

    Actually, I have tried to apply cp_solver strategy to prune row groups. But we observed a performance degradation since this method sacrifices vectorized computing power, meaning that the process needs to be run for each set of statistics. As the number of sets increases, the efficiency decreases.

    I will again think about how to insert Interval library there without sacrificing performance.

  3. alamb commented on Oct 21, 2023

    @alamb
    ContributorAuthor

    I am not sure this is what you searched for but there was an issue #5535.

    Thank you -- this is exactly what I was looking for.

    I will again think about how to insert Interval library there without sacrificing performance.

    I may be able to help with this too. One way is use Datum (from arrow) (rather than ScalarValue)in theInterval` representation -- that way each can store a single value or multiple.

  4. alamb commented on Feb 14, 2024

    @alamb
    ContributorAuthor

    I just updated this ticket's description with a more coherent story and examples that @appletreeisyellow and I have hit recently while working on in #9171

    We were talking today and I think @appletreeisyellow may try to prototype what this solution could look like, if she has time, to move the conversation forward.

  5. appletreeisyellow commented on Feb 14, 2024

    @appletreeisyellow
    Contributor

    Thank you @alamb for the updating the description

  6. adriangb commented on Mar 26, 2025

    @adriangb
    Contributor

    Hi @appletreeisyellow or @#15425 I was wondering if you were able to make any progress with this? I was thinking about #15425 today but since it requires considerable changes to PruningPredicate and conflict with this work I wanted to check first.

  7. appletreeisyellow commented on Mar 26, 2025

    @appletreeisyellow
    Contributor

    Hi @adriangb! I've done this part of the work:

    I don't have any plans to work on PruningPredicate in the near future, so you are good! Unless @alamb has anything to add?

  8. adriangb commented on Mar 26, 2025

    @adriangb
    Contributor

    I was more so asking about work to use ExprIntervalGraph inside of PruningPredicate

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions