Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[opt](nereids) catch all exceptions in StatsCalculator#49415
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
22 changes: 17 additions & 5 deletions
22 fe/fe-core/src/main/java/org/apache/doris/nereids/stats/ExpressionEstimation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -95,12 +95,15 @@ | ||
| import org.apache.doris.nereids.trees.expressions.literal.Literal; | ||
| import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
| import org.apache.doris.nereids.types.DataType; | ||
| import org.apache.doris.qe.ConnectContext; | ||
| import org.apache.doris.statistics.ColumnStatistic; | ||
| import org.apache.doris.statistics.ColumnStatisticBuilder; | ||
| import org.apache.doris.statistics.Statistics; | ||
| import com.google.common.base.Preconditions; | ||
| import org.apache.commons.collections.CollectionUtils; | ||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
| import java.time.Instant; | ||
| import java.time.LocalDate; | ||
| @@ -112,7 +115,7 @@ | ||
| * Used to estimate for expressions that not producing boolean value. | ||
| */ | ||
| public class ExpressionEstimation extends ExpressionVisitor<ColumnStatistic, Statistics> { | ||
| public static final Logger LOG = LogManager.getLogger(ExpressionEstimation.class); | ||
| public static final long DAYS_FROM_0_TO_1970 = 719528; | ||
| public static final long DAYS_FROM_0_TO_9999 = 3652424; | ||
| private static final ExpressionEstimation INSTANCE = new ExpressionEstimation(); | ||
| @@ -121,11 +124,20 @@ public class ExpressionEstimation extends ExpressionVisitor<ColumnStatistic, Sta | ||
| * returned columnStat is newly created or a copy of stats | ||
| */ | ||
| public static ColumnStatistic estimate(Expression expression, Statistics stats) { | ||
| ColumnStatistic columnStatistic = expression.accept(INSTANCE, stats); | ||
| if (columnStatistic == null) { | ||
| return ColumnStatistic.UNKNOWN; | ||
| try { | ||
| ColumnStatistic columnStatistic = expression.accept(INSTANCE, stats); | ||
| if (columnStatistic == null) { | ||
| return ColumnStatistic.createUnknownByDataType(expression.getDataType()); | ||
| } | ||
| return columnStatistic; | ||
| } catch (Exception e) { | ||
| // in regression test, feDebug is true so that the exception is thrown in order to detect problems. | ||
| if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().feDebug) { | ||
englefly marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| throw e; | ||
| } | ||
| LOG.warn("ExpressionEstimation failed : " + expression, e); | ||
| return ColumnStatistic.createUnknownByDataType(expression.getDataType()); | ||
| } | ||
| return columnStatistic; | ||
| } | ||
| @Override | ||
24 changes: 22 additions & 2 deletions
24 fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -301,13 +301,33 @@ public static void estimate(GroupExpression groupExpression, CascadesContext con | ||
| private void estimate() { | ||
| Plan plan = groupExpression.getPlan(); | ||
| Statistics newStats = plan.accept(this, null); | ||
| Statistics newStats; | ||
| try { | ||
| newStats = plan.accept(this, null); | ||
| } catch (Exception e) { | ||
| // throw exception in debug mode | ||
englefly marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().feDebug) { | ||
| throw e; | ||
| } | ||
| LOG.warn("stats calculation failed, plan " + plan.toString(), e); | ||
| // use unknown stats or the first child's stats | ||
| if (plan.children().isEmpty() || !(plan.child(0) instanceof GroupPlan)) { | ||
| Map<Expression, ColumnStatistic> columnStatisticMap = new HashMap<>(); | ||
| for (Slot slot : plan.getOutput()) { | ||
| columnStatisticMap.put(slot, ColumnStatistic.createUnknownByDataType(slot.getDataType())); | ||
| } | ||
| newStats = new Statistics(1, 1, columnStatisticMap); | ||
| } else { | ||
| newStats = ((GroupPlan) plan.child(0)).getStats(); | ||
| } | ||
| } | ||
| newStats.normalizeColumnStatistics(); | ||
| // We ensure that the rowCount remains unchanged in order to make the cost of each plan comparable. | ||
| final Statistics tmpStats = newStats; | ||
| if (groupExpression.getOwnerGroup().getStatistics() == null) { | ||
| boolean isReliable = groupExpression.getPlan().getExpressions().stream() | ||
| .noneMatch(e -> newStats.isInputSlotsUnknown(e.getInputSlots())); | ||
| .noneMatch(e -> tmpStats.isInputSlotsUnknown(e.getInputSlots())); | ||
| groupExpression.getOwnerGroup().setStatsReliable(isReliable); | ||
| groupExpression.getOwnerGroup().setStatistics(newStats); | ||
| } else { | ||
2 changes: 1 addition & 1 deletion
2 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/GroupPlan.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7 fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2271,6 +2271,12 @@ public void setDetailShapePlanNodes(String detailShapePlanNodes) { | ||
| "use other health replica when the use_fix_replica meet error" }) | ||
| public boolean fallbackOtherReplicaWhenFixedCorrupt = false; | ||
| public static final String FE_DEBUG = "fe_debug"; | ||
| @VariableMgr.VarAttr(name = FE_DEBUG, needForward = true, fuzzy = true, | ||
| description = {"when set true, FE will throw exceptions instead swallow them. This is used for test", | ||
| "when set true, FE will throw exceptions instead swallow them. This is used for test"}) | ||
englefly marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public boolean feDebug = false; | ||
| @VariableMgr.VarAttr(name = SHOW_ALL_FE_CONNECTION, | ||
| description = {"when it's true show processlist statement list all fe's connection", | ||
| "当变量为true时,show processlist命令展示所有fe的连接"}) | ||
| @@ -2505,6 +2511,7 @@ public boolean isEnableESParallelScroll() { | ||
| @SuppressWarnings("checkstyle:Indentation") | ||
| public void initFuzzyModeVariables() { | ||
| Random random = new SecureRandom(); | ||
| this.feDebug = true; | ||
| this.parallelPipelineTaskNum = random.nextInt(8); | ||
| this.parallelPrepareThreshold = random.nextInt(32) + 1; | ||
| this.enableCommonExprPushdown = random.nextBoolean(); | ||
26 changes: 26 additions & 0 deletions
26 fe/fe-core/src/main/java/org/apache/doris/statistics/ColumnStatistic.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9 fe/fe-core/src/test/java/org/apache/doris/nereids/stats/ExpressionEstimationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.