Skip to content

fix(planner): Set the size estimate for a ConstantExpression/Literal#27188

Merged
tdcmeehan merged 1 commit intoprestodb:masterfrom
aaneja:improveSizeEstimateForConstants
Feb 24, 2026
Merged

fix(planner): Set the size estimate for a ConstantExpression/Literal#27188
tdcmeehan merged 1 commit intoprestodb:masterfrom
aaneja:improveSizeEstimateForConstants

Conversation

@aaneja
Copy link
Copy Markdown
Contributor

@aaneja aaneja commented Feb 23, 2026

Description, Motivation and Context

The planner generates constant variables which were missing a size estimate. These are needed for correctly estimating join sizes/ join costs (among other cost based comparisons)

Impact

Improves build/prode side estimation during DetermineJoinDistributionType

Test Plan

CI

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* Improves size estimates for constant variables

Summary by Sourcery

Set size estimates for constant and literal string expressions to improve planner cost estimation for joins and other operations.

Bug Fixes:

  • Populate average row size for constant and literal Slice-backed expressions so planner statistics include size estimates.

Tests:

  • Extend scalar stats calculator tests to cover average row size estimation for string literals.

@aaneja aaneja requested review from a team, feilong-liu and jaystarshot as code owners February 23, 2026 07:03
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Feb 23, 2026
@prestodb-ci prestodb-ci requested review from a team, BryanCutler and Joe-Abraham and removed request for a team February 23, 2026 07:03
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Sets average row size estimates for constant scalar expressions backed by Slice values and updates scalar stats tests accordingly, improving join size and cost estimation for constant variables.

Class diagram for updated ScalarStatsCalculator scalar estimation

classDiagram
    class ScalarStatsCalculator {
        +VariableStatsEstimate visitConstant(ConstantExpression literal, Void context)
        +VariableStatsEstimate visitLiteral(Literal node, Void context)
    }

    class VariableStatsEstimate {
        +setLowValue(double lowValue) VariableStatsEstimateBuilder
        +setHighValue(double highValue) VariableStatsEstimateBuilder
        +setAverageRowSize(double averageRowSize) VariableStatsEstimateBuilder
        +build() VariableStatsEstimate
    }

    class VariableStatsEstimateBuilder {
        +setLowValue(double lowValue) VariableStatsEstimateBuilder
        +setHighValue(double highValue) VariableStatsEstimateBuilder
        +setAverageRowSize(double averageRowSize) VariableStatsEstimateBuilder
        +build() VariableStatsEstimate
    }

    class ConstantExpression {
        +Object getValue()
    }

    class Literal {
        +Object getValue()
    }

    class Slice {
        +int length()
    }

    ScalarStatsCalculator --> VariableStatsEstimateBuilder : uses
    ScalarStatsCalculator --> ConstantExpression : parameter
    ScalarStatsCalculator --> Literal : parameter
    ConstantExpression --> Slice : value_may_be
    Literal --> Slice : value_may_be
    VariableStatsEstimateBuilder --> VariableStatsEstimate : builds
    Slice <.. ScalarStatsCalculator : averageRowSize_from_length
Loading

File-Level Changes

Change Details Files
Add average row size estimation for constant expressions and literals with Slice values in the scalar stats calculator.
  • Update ConstantExpression stats calculation to set averageRowSize based on Slice length when the literal value is a Slice.
  • Update Literal stats calculation to set averageRowSize based on Slice length when the value is a Slice.
presto-main-base/src/main/java/com/facebook/presto/cost/ScalarStatsCalculator.java
Extend scalar stats calculator tests to cover average row size estimation for string literals.
  • Capture the VariableStatsAssertion for a simple StringLiteral and assert that averageRowSize matches the literal length.
  • Keep existing assertions for distinct values, low/high values, and null fraction for the StringLiteral.
presto-main-base/src/test/java/com/facebook/presto/cost/TestScalarStatsCalculator.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The logic to set averageRowSize for Slice values is duplicated in both visitConstant and visitLiteral; consider extracting a small helper to keep this behavior consistent and easier to evolve.
  • Right now only Slice-backed literals get an averageRowSize; if there are other variable-width types represented differently (e.g., non-Slice-backed), it may be worth clarifying or centralizing how average row size should be derived across all relevant types.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic to set `averageRowSize` for `Slice` values is duplicated in both `visitConstant` and `visitLiteral`; consider extracting a small helper to keep this behavior consistent and easier to evolve.
- Right now only `Slice`-backed literals get an `averageRowSize`; if there are other variable-width types represented differently (e.g., non-Slice-backed), it may be worth clarifying or centralizing how average row size should be derived across all relevant types.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@aaneja aaneja force-pushed the improveSizeEstimateForConstants branch from 2f32172 to 829dea4 Compare February 23, 2026 10:18
@aaneja aaneja force-pushed the improveSizeEstimateForConstants branch from 829dea4 to d02433a Compare February 23, 2026 15:36
@GregoryKimball GregoryKimball removed this from libcudf Feb 24, 2026
@tdcmeehan tdcmeehan merged commit ad48335 into prestodb:master Feb 24, 2026
110 of 112 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants