morrySnow commented on code in PR #39576:
URL: https://github.com/apache/doris/pull/39576#discussion_r1722756189


##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -2408,8 +2424,8 @@ public int getAnalyzeTimeoutS() {
         return analyzeTimeoutS;
     }
 
-    public void setEnableTwoPhaseReadOpt(boolean enable) {
-        enableTwoPhaseReadOpt = enable;
+    public void disableTwoPhaseReadOpt() {

Review Comment:
   we should use `enable` as function or variable name, disable is hard to 
understand



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/LimitAggToTopNAgg.java:
##########
@@ -46,35 +46,33 @@ public class LimitAggToTopNAgg implements 
RewriteRuleFactory {
     public List<Rule> buildRules() {
         return ImmutableList.of(
                 // limit -> agg to topn->agg
-                logicalLimit(logicalAggregate())
-                        .when(limit -> ConnectContext.get() != null
-                                && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= limit.getLimit() + limit.getOffset())
+                logicalLimit(logicalAggregate()).when(
+                        limit -> ConnectContext.get() != null && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
limit.getLimit()
+                                        + limit.getOffset())

Review Comment:
   ```suggestion
                   logicalLimit(logicalAggregate())
                           .when(limit -> ConnectContext.get() != null
                                   && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
                                   && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold
                                   >= limit.getLimit() + limit.getOffset())
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/LimitAggToTopNAgg.java:
##########
@@ -46,35 +46,33 @@ public class LimitAggToTopNAgg implements 
RewriteRuleFactory {
     public List<Rule> buildRules() {
         return ImmutableList.of(
                 // limit -> agg to topn->agg
-                logicalLimit(logicalAggregate())
-                        .when(limit -> ConnectContext.get() != null
-                                && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= limit.getLimit() + limit.getOffset())
+                logicalLimit(logicalAggregate()).when(
+                        limit -> ConnectContext.get() != null && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
limit.getLimit()
+                                        + limit.getOffset())
                         .then(limit -> {
                             LogicalAggregate<? extends Plan> agg = 
limit.child();
                             List<OrderKey> orderKeys = 
generateOrderKeyByGroupKey(agg);
                             return new LogicalTopN<>(orderKeys, 
limit.getLimit(), limit.getOffset(), agg);
                         }).toRule(RuleType.LIMIT_AGG_TO_TOPN_AGG),
-                //limit->project->agg to topn->project->agg
+                // limit->project->agg to topn->project->agg
                 logicalLimit(logicalProject(logicalAggregate()))
                         .when(limit -> ConnectContext.get() != null
                                 && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= limit.getLimit() + limit.getOffset())
-                        .when(limit -> outputAllGroupKeys(limit, 
limit.child().child()))
-                        .then(limit -> {
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
limit.getLimit()
+                                        + limit.getOffset())
+                        .when(limit -> outputAllGroupKeys(limit, 
limit.child().child())).then(limit -> {
                             LogicalProject<? extends Plan> project = 
limit.child();
                             LogicalAggregate<? extends Plan> agg = 
(LogicalAggregate<? extends Plan>) project.child();
                             List<OrderKey> orderKeys = 
generateOrderKeyByGroupKey(agg);
                             return new LogicalTopN<>(orderKeys, 
limit.getLimit(), limit.getOffset(), project);
                         }).toRule(RuleType.LIMIT_AGG_TO_TOPN_AGG),
-                // topn -> agg: add all group key to sort key, if sort key is 
prefix of group key
-                logicalTopN(logicalAggregate())
-                        .when(topn -> ConnectContext.get() != null
-                                && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= topn.getLimit() + topn.getOffset())
+                // topn -> agg: add all group key to sort key, if sort key is 
prefix of group
+                // key
+                logicalTopN(logicalAggregate()).when(
+                        topn -> ConnectContext.get() != null && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
topn.getLimit()
+                                        + topn.getOffset())

Review Comment:
   ```suggestion
                   logicalTopN(logicalAggregate())
                           .when(topn -> ConnectContext.get() != null
                                   && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
                                   && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold
                                   >= topn.getLimit() + topn.getOffset())
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DeferMaterializeTopNResult.java:
##########
@@ -53,29 +53,25 @@ public class DeferMaterializeTopNResult implements 
RewriteRuleFactory {
     @Override
     public List<Rule> buildRules() {
         return ImmutableList.of(
-                RuleType.DEFER_MATERIALIZE_TOP_N_RESULT.build(
-                        logicalResultSink(logicalTopN(logicalOlapScan()))
-                                .when(r -> r.child().getLimit() < 
getTopNOptLimitThreshold())
-                                .whenNot(r -> 
r.child().getOrderKeys().isEmpty())
-                                .when(r -> 
r.child().getOrderKeys().stream().map(OrderKey::getExpr)
-                                        
.allMatch(Expression::isColumnFromTable))
-                                .when(r -> 
r.child().child().getTable().getEnableLightSchemaChange())
-                                .when(r -> 
r.child().child().getTable().isDupKeysOrMergeOnWrite())
-                                .then(r -> deferMaterialize(r, r.child(), 
Optional.empty(), r.child().child()))
-                ),
-                RuleType.DEFER_MATERIALIZE_TOP_N_RESULT.build(
-                        
logicalResultSink(logicalTopN(logicalFilter(logicalOlapScan())))
-                                .when(r -> r.child().getLimit() < 
getTopNOptLimitThreshold())
+                
RuleType.DEFER_MATERIALIZE_TOP_N_RESULT.build(logicalResultSink(logicalTopN(logicalOlapScan()))
+                        .when(r -> r.child().getLimit() < 
getTwoPhaseReadLimitThreshold())
+                        .whenNot(r -> r.child().getOrderKeys().isEmpty())
+                        .when(r -> 
r.child().getOrderKeys().stream().map(OrderKey::getExpr)
+                                .allMatch(Expression::isColumnFromTable))
+                        .when(r -> 
r.child().child().getTable().getEnableLightSchemaChange())
+                        .when(r -> 
r.child().child().getTable().isDupKeysOrMergeOnWrite())
+                        .then(r -> deferMaterialize(r, r.child(), 
Optional.empty(), r.child().child()))),
+                RuleType.DEFER_MATERIALIZE_TOP_N_RESULT
+                        
.build(logicalResultSink(logicalTopN(logicalFilter(logicalOlapScan())))
+                                .when(r -> r.child().getLimit() < 
getTwoPhaseReadLimitThreshold())
                                 .whenNot(r -> 
r.child().getOrderKeys().isEmpty())
                                 .when(r -> 
r.child().getOrderKeys().stream().map(OrderKey::getExpr)
                                         
.allMatch(Expression::isColumnFromTable))
                                 .when(r -> 
r.child().child().child().getTable().getEnableLightSchemaChange())
-                                .when(r -> 
r.child().child().child().getTable().isDupKeysOrMergeOnWrite())
-                                .then(r -> {
+                                .when(r -> 
r.child().child().child().getTable().isDupKeysOrMergeOnWrite()).then(r -> {
                                     LogicalFilter<LogicalOlapScan> filter = 
r.child().child();
                                     return deferMaterialize(r, r.child(), 
Optional.of(filter), filter.child());

Review Comment:
   ```suggestion
                                   .when(r -> 
r.child().child().child().getTable().isDupKeysOrMergeOnWrite())
                                   .then(r -> {
                                       LogicalFilter<LogicalOlapScan> filter = 
r.child().child();
                                       return deferMaterialize(r, r.child(), 
Optional.of(filter), filter.child());
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/LimitAggToTopNAgg.java:
##########
@@ -46,35 +46,33 @@ public class LimitAggToTopNAgg implements 
RewriteRuleFactory {
     public List<Rule> buildRules() {
         return ImmutableList.of(
                 // limit -> agg to topn->agg
-                logicalLimit(logicalAggregate())
-                        .when(limit -> ConnectContext.get() != null
-                                && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= limit.getLimit() + limit.getOffset())
+                logicalLimit(logicalAggregate()).when(
+                        limit -> ConnectContext.get() != null && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
limit.getLimit()
+                                        + limit.getOffset())
                         .then(limit -> {
                             LogicalAggregate<? extends Plan> agg = 
limit.child();
                             List<OrderKey> orderKeys = 
generateOrderKeyByGroupKey(agg);
                             return new LogicalTopN<>(orderKeys, 
limit.getLimit(), limit.getOffset(), agg);
                         }).toRule(RuleType.LIMIT_AGG_TO_TOPN_AGG),
-                //limit->project->agg to topn->project->agg
+                // limit->project->agg to topn->project->agg
                 logicalLimit(logicalProject(logicalAggregate()))
                         .when(limit -> ConnectContext.get() != null
                                 && 
ConnectContext.get().getSessionVariable().pushTopnToAgg
-                                && 
ConnectContext.get().getSessionVariable().topnOptLimitThreshold
-                                >= limit.getLimit() + limit.getOffset())
-                        .when(limit -> outputAllGroupKeys(limit, 
limit.child().child()))
-                        .then(limit -> {
+                                && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold >= 
limit.getLimit()
+                                        + limit.getOffset())
+                        .when(limit -> outputAllGroupKeys(limit, 
limit.child().child())).then(limit -> {

Review Comment:
   ```suggestion
                                   && 
ConnectContext.get().getSessionVariable().pushLimitToAggThreshold
                                   >= limit.getLimit() + limit.getOffset())
                           .when(limit -> outputAllGroupKeys(limit, 
limit.child().child()))
                           .then(limit -> {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to