Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimate row count when BETWEEN value is an expression #18501

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ protected PlanNodeStatsEstimate visitIsNullPredicate(IsNullPredicate node, Void
@Override
protected PlanNodeStatsEstimate visitBetweenPredicate(BetweenPredicate node, Void context)
{
if (!(node.getValue() instanceof SymbolReference)) {
SymbolStatsEstimate valueStats = getExpressionStats(node.getValue());
if (valueStats.isUnknown()) {
return PlanNodeStatsEstimate.unknown();
}
if (!getExpressionStats(node.getMin()).isSingleValue()) {
Expand All @@ -324,7 +325,6 @@ protected PlanNodeStatsEstimate visitBetweenPredicate(BetweenPredicate node, Voi
return PlanNodeStatsEstimate.unknown();
}

SymbolStatsEstimate valueStats = input.getSymbolStatistics(Symbol.from(node.getValue()));
Expression lowerBound = new ComparisonExpression(GREATER_THAN_OR_EQUAL, node.getValue(), node.getMin());
Expression upperBound = new ComparisonExpression(LESS_THAN_OR_EQUAL, node.getValue(), node.getMax());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ public void testBetweenOperatorFilter()
.highValue(100.0)
.nullsFraction(0.0));

// Expression as value. CAST from DOUBLE to DECIMAL(7,2)
// Produces row count estimate without updating symbol stats
assertExpression("CAST(x AS DECIMAL(7,2)) BETWEEN CAST(DECIMAL '-2.50' AS DECIMAL(7, 2)) AND CAST(DECIMAL '2.50' AS DECIMAL(7, 2))")
.outputRowsCount(219.726563)
.symbolStats("x", symbolStats ->
symbolStats.distinctValuesCount(xStats.getDistinctValuesCount())
.lowValue(xStats.getLowValue())
.highValue(xStats.getHighValue())
.nullsFraction(xStats.getNullsFraction()));

assertExpression("'a' IN ('a', 'b')").equalTo(standardInputStatistics);
assertExpression("'a' IN ('a', 'b', NULL)").equalTo(standardInputStatistics);
assertExpression("'a' IN ('b', 'c')").outputRowsCount(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local exchange (GATHER, SINGLE, [])
scan customer_demographics
local exchange (GATHER, SINGLE, [])
remote exchange (REPLICATE, BROADCAST, [])
scan web_page
scan reason
local exchange (GATHER, SINGLE, [])
remote exchange (REPLICATE, BROADCAST, [])
scan reason
scan web_page