You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "xiangfu0 (via GitHub)" <gi...@apache.org> on 2025/03/05 00:04:11 UTC

[PR] Adding a plan listener to report each rule evaluation time in the optimizer [pinot]

xiangfu0 opened a new pull request, #15192:
URL: https://github.com/apache/pinot/pull/15192

   1. Add a new query option: `profileRuleOptimizer` to allow dump the rule optimizer timing to log
   2. For explain query, it will be an extra column with this information.


-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1982446491


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java:
##########
@@ -49,6 +50,7 @@ public class PlannerContext implements AutoCloseable {
   private final LogicalPlanner _relTraitPlanner;
 
   private final Map<String, String> _options;
+  private final Map<String, String> _plannerOutput;

Review Comment:
   depends on if we will have more listeners to put more stuffs later on.



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #15192:
URL: https://github.com/apache/pinot/pull/15192#issuecomment-2699424500

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/15192?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `14.28571%` with `60 lines` in your changes missing coverage. Please review.
   > Project coverage is 63.36%. Comparing base [(`59551e4`)](https://app.codecov.io/gh/apache/pinot/commit/59551e45224f1535c4863fd577622b37366ccc97?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`ab17fa0`)](https://app.codecov.io/gh/apache/pinot/commit/ab17fa07084fd998b90e815cb42263ce7fb88da4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 1799 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/15192?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...pinot/query/context/RuleTimingPlannerListener.java](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&filepath=pinot-query-planner%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fquery%2Fcontext%2FRuleTimingPlannerListener.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvY29udGV4dC9SdWxlVGltaW5nUGxhbm5lckxpc3RlbmVyLmphdmE=) | 0.00% | [27 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...requesthandler/MultiStageBrokerRequestHandler.java](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&filepath=pinot-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fbroker%2Frequesthandler%2FMultiStageBrokerRequestHandler.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtYnJva2VyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9waW5vdC9icm9rZXIvcmVxdWVzdGhhbmRsZXIvTXVsdGlTdGFnZUJyb2tlclJlcXVlc3RIYW5kbGVyLmphdmE=) | 0.00% | [21 Missing :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../java/org/apache/pinot/query/QueryEnvironment.java](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&filepath=pinot-query-planner%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fquery%2FQueryEnvironment.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcGxhbm5lci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvUXVlcnlFbnZpcm9ubWVudC5qYXZh) | 45.45% | [9 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/15192?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15192      +/-   ##
   ============================================
   + Coverage     61.75%   63.36%   +1.61%     
   - Complexity      207     1363    +1156     
   ============================================
     Files          2436     2760     +324     
     Lines        133233   155171   +21938     
     Branches      20636    23911    +3275     
   ============================================
   + Hits          82274    98323   +16049     
   - Misses        44911    49407    +4496     
   - Partials       6048     7441    +1393     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration1](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration2](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-11](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-21](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.36% <14.28%> (+1.73%)` | :arrow_up: |
   | [skip-bytebuffers-false](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.32% <14.28%> (+1.58%)` | :arrow_up: |
   | [skip-bytebuffers-true](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.34% <14.28%> (+35.62%)` | :arrow_up: |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.36% <14.28%> (+1.61%)` | :arrow_up: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.36% <14.28%> (+1.61%)` | :arrow_up: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.99% <20.40%> (+9.10%)` | :arrow_up: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/15192/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `33.93% <2.85%> (+6.20%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/pinot/pull/15192?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on PR #15192:
URL: https://github.com/apache/pinot/pull/15192#issuecomment-2702867770

   Removed the query option and make it happen to all the explain query.


-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1982856026


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java:
##########
@@ -49,6 +50,7 @@ public class PlannerContext implements AutoCloseable {
   private final LogicalPlanner _relTraitPlanner;
 
   private final Map<String, String> _options;
+  private final Map<String, String> _plannerOutput;

Review Comment:
   It may be useful if in the future we introduce a json output for rule timings, but we can also include this attribute in that PR



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1983127288


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/RuleTimingPlannerListener.java:
##########
@@ -0,0 +1,89 @@
+package org.apache.pinot.query.context;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptListener;
+import org.apache.calcite.plan.RelOptRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RuleTimingPlannerListener implements RelOptListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(RuleTimingPlannerListener.class);
+  public static final String RULE_TIMINGS = "RULE_TIMINGS";
+
+  private final PlannerContext _plannerContext;
+  private final Map<RelOptRule, Long> _ruleStartTimes = new HashMap<>();
+  private final Map<RelOptRule, Long> _ruleDurations = new HashMap<>();
+
+  public RuleTimingPlannerListener(PlannerContext plannerContext) {
+    _plannerContext = plannerContext;
+  }
+
+  @Override
+  public void ruleAttempted(RuleAttemptedEvent event) {
+    // Capture start time when a rule is attempted
+    if (event.isBefore()) {
+      _ruleStartTimes.put(event.getRuleCall().getRule(), System.nanoTime());
+    } else {
+      if (_ruleStartTimes.containsKey(event.getRuleCall().getRule())) {
+        long duration = System.nanoTime() - _ruleStartTimes.get(event.getRuleCall().getRule());
+        _ruleDurations.put(event.getRuleCall().getRule(),
+            _ruleDurations.getOrDefault(event.getRuleCall().getRule(), 0L) + duration);
+      }
+    }
+  }
+
+  @Override
+  public void ruleProductionSucceeded(RuleProductionEvent event) {
+  }
+
+  @Override
+  public void relEquivalenceFound(RelEquivalenceEvent event) {
+    /* Not used */
+  }
+
+  @Override
+  public void relDiscarded(RelDiscardedEvent event) {
+    /* Not used */
+  }
+
+  @Override
+  public void relChosen(RelChosenEvent event) {
+    /* Not used */
+  }
+
+  public void printRuleTimings() {
+    String ruleTimings = getRuleTimings();
+    LOGGER.info(ruleTimings);
+    _plannerContext.getPlannerOutput().put(RULE_TIMINGS, ruleTimings);
+  }
+
+  public String getRuleTimings() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("--- Rule Execution Times ---");
+    for (Map.Entry<RelOptRule, Long> entry : _ruleDurations.entrySet()) {
+      sb.append("\nRule: ").append(entry.getKey()).append(" -> Time: ").append(entry.getValue() / 1_000_000.0);
+    }
+    return sb.toString();
+  }

Review Comment:
   done, also found a bug in the `PinotRelJsonWriter` 😮‍💨  and fixed that



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1982308252


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java:
##########
@@ -49,6 +50,7 @@ public class PlannerContext implements AutoCloseable {
   private final LogicalPlanner _relTraitPlanner;
 
   private final Map<String, String> _options;
+  private final Map<String, String> _plannerOutput;

Review Comment:
   Since we are no longer reusing the `_options` fields, shall we just return a map from rule name (string) to execution time in micros (int)? We don't need to generalize it as planner output.



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "Jackie-Jiang (via GitHub)" <gi...@apache.org>.
Jackie-Jiang commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1980514148


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/RuleTimingPlannerListener.java:
##########
@@ -0,0 +1,93 @@
+package org.apache.pinot.query.context;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptListener;
+import org.apache.calcite.plan.RelOptRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RuleTimingPlannerListener implements RelOptListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(RuleTimingPlannerListener.class);
+  public static final String RULE_TIMINGS = "RULE_TIMINGS";
+
+  private final PlannerContext _plannerContext;
+  private final Map<RelOptRule, Long> _ruleStartTimes = new HashMap<>();
+  private final Map<RelOptRule, Long> _ruleDurations = new HashMap<>();
+
+  public RuleTimingPlannerListener(PlannerContext plannerContext) {
+    _plannerContext = plannerContext;
+  }
+
+  @Override
+  public void ruleAttempted(RuleAttemptedEvent event) {
+    // Capture start time when a rule is attempted
+    if (event.isBefore()) {
+      _ruleStartTimes.put(event.getRuleCall().getRule(), System.nanoTime());
+    } else {
+      if (_ruleStartTimes.containsKey(event.getRuleCall().getRule())) {
+        long duration = System.nanoTime() - _ruleStartTimes.get(event.getRuleCall().getRule());
+        _ruleDurations.put(event.getRuleCall().getRule(),
+            _ruleDurations.getOrDefault(event.getRuleCall().getRule(), 0L) + duration);
+      }
+    }
+  }
+
+  @Override
+

Review Comment:
   (minor) Remove empty lines



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -249,16 +253,26 @@ public QueryPlannerResult explainQuery(String sqlQuery, SqlNodeAndOptions sqlNod
           RelNode explainedNode = MultiStageExplainAskingServersUtils.modifyRel(relRoot.rel,
               dispatchableSubPlan.getQueryStages(), nodeTracker, serversExplainer);
 
-          String explainStr = PlannerUtils.explainPlan(explainedNode, format, level);
-
-          return new QueryPlannerResult(null, explainStr, dispatchableSubPlan.getTableNames());
+          return getQueryPlannerResult(plannerContext, dispatchableSubPlan,
+              PlannerUtils.explainPlan(explainedNode, format, level), dispatchableSubPlan.getTableNames());
         }
       }
     } catch (Exception e) {
       throw new RuntimeException("Error explain query plan for: " + sqlQuery, e);
     }
   }
 
+  @NotNull

Review Comment:
   (minor) Let's not add `NotNull` annotation, and treat everything as non-null if not annotated



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -485,7 +515,8 @@ public boolean useSpools(Map<String, String> options) {
   public interface Config {
     String getDatabase();
 
-    @Nullable // In theory nullable only in tests. We should fix LiteralOnlyBrokerRequestTest to not need this.
+    @Nullable
+      // In theory nullable only in tests. We should fix LiteralOnlyBrokerRequestTest to not need this.

Review Comment:
   (minor) Revert?



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -391,7 +411,17 @@ private RelNode optimize(RelRoot relRoot, PlannerContext plannerContext) {
     try {
       RelOptPlanner optPlanner = plannerContext.getRelOptPlanner();
       optPlanner.setRoot(relRoot.rel);
+      RuleTimingPlannerListener listener = null;
+      if (plannerContext.getOptions()
+          .containsKey(CommonConstants.Broker.Request.QueryOptionKey.PROFILE_RULE_OPTIMIZER)) {

Review Comment:
   (minor) Extract this into `QueryOptionsUtils`. `containsKey()` is not enough. We should check the value using `Boolean.parseBoolean()`



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/RuleTimingPlannerListener.java:
##########
@@ -0,0 +1,93 @@
+package org.apache.pinot.query.context;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptListener;
+import org.apache.calcite.plan.RelOptRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RuleTimingPlannerListener implements RelOptListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(RuleTimingPlannerListener.class);
+  public static final String RULE_TIMINGS = "RULE_TIMINGS";
+
+  private final PlannerContext _plannerContext;
+  private final Map<RelOptRule, Long> _ruleStartTimes = new HashMap<>();
+  private final Map<RelOptRule, Long> _ruleDurations = new HashMap<>();
+
+  public RuleTimingPlannerListener(PlannerContext plannerContext) {
+    _plannerContext = plannerContext;
+  }
+
+  @Override
+  public void ruleAttempted(RuleAttemptedEvent event) {
+    // Capture start time when a rule is attempted
+    if (event.isBefore()) {
+      _ruleStartTimes.put(event.getRuleCall().getRule(), System.nanoTime());
+    } else {
+      if (_ruleStartTimes.containsKey(event.getRuleCall().getRule())) {
+        long duration = System.nanoTime() - _ruleStartTimes.get(event.getRuleCall().getRule());
+        _ruleDurations.put(event.getRuleCall().getRule(),
+            _ruleDurations.getOrDefault(event.getRuleCall().getRule(), 0L) + duration);
+      }
+    }
+  }
+
+  @Override
+
+  public void ruleProductionSucceeded(RuleProductionEvent event) {
+  }
+
+  @Override
+
+  public void relEquivalenceFound(RelEquivalenceEvent event) {
+    /* Not used */
+  }
+
+  @Override
+
+  public void relDiscarded(RelDiscardedEvent event) {
+    /* Not used */
+  }
+
+  @Override
+
+  public void relChosen(RelChosenEvent event) {
+    /* Not used */
+  }
+
+  public void printRuleTimings() {
+    String ruleTimings = getRuleTimings();
+    LOGGER.info(ruleTimings);
+    _plannerContext.getOptions().put(RULE_TIMINGS, ruleTimings);

Review Comment:
   Don't put it into the query options. This will be propagated to the servers



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 merged PR #15192:
URL: https://github.com/apache/pinot/pull/15192


-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "gortiz (via GitHub)" <gi...@apache.org>.
gortiz commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1981726584


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/RuleTimingPlannerListener.java:
##########
@@ -0,0 +1,89 @@
+package org.apache.pinot.query.context;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.calcite.plan.RelOptListener;
+import org.apache.calcite.plan.RelOptRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class RuleTimingPlannerListener implements RelOptListener {
+  private static final Logger LOGGER = LoggerFactory.getLogger(RuleTimingPlannerListener.class);
+  public static final String RULE_TIMINGS = "RULE_TIMINGS";
+
+  private final PlannerContext _plannerContext;
+  private final Map<RelOptRule, Long> _ruleStartTimes = new HashMap<>();
+  private final Map<RelOptRule, Long> _ruleDurations = new HashMap<>();
+
+  public RuleTimingPlannerListener(PlannerContext plannerContext) {
+    _plannerContext = plannerContext;
+  }
+
+  @Override
+  public void ruleAttempted(RuleAttemptedEvent event) {
+    // Capture start time when a rule is attempted
+    if (event.isBefore()) {
+      _ruleStartTimes.put(event.getRuleCall().getRule(), System.nanoTime());
+    } else {
+      if (_ruleStartTimes.containsKey(event.getRuleCall().getRule())) {
+        long duration = System.nanoTime() - _ruleStartTimes.get(event.getRuleCall().getRule());
+        _ruleDurations.put(event.getRuleCall().getRule(),
+            _ruleDurations.getOrDefault(event.getRuleCall().getRule(), 0L) + duration);
+      }
+    }
+  }
+
+  @Override
+  public void ruleProductionSucceeded(RuleProductionEvent event) {
+  }
+
+  @Override
+  public void relEquivalenceFound(RelEquivalenceEvent event) {
+    /* Not used */
+  }
+
+  @Override
+  public void relDiscarded(RelDiscardedEvent event) {
+    /* Not used */
+  }
+
+  @Override
+  public void relChosen(RelChosenEvent event) {
+    /* Not used */
+  }
+
+  public void printRuleTimings() {
+    String ruleTimings = getRuleTimings();
+    LOGGER.info(ruleTimings);
+    _plannerContext.getPlannerOutput().put(RULE_TIMINGS, ruleTimings);
+  }
+
+  public String getRuleTimings() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("--- Rule Execution Times ---");
+    for (Map.Entry<RelOptRule, Long> entry : _ruleDurations.entrySet()) {
+      sb.append("\nRule: ").append(entry.getKey()).append(" -> Time: ").append(entry.getValue() / 1_000_000.0);
+    }
+    return sb.toString();
+  }

Review Comment:
   Could we export this info in a JSON instead? It shouldn't be more difficult to read for humans but would be very nice for machines



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] [MSQE] Add a plan listener to report rule optimizer evaluation time [pinot]

Posted by "xiangfu0 (via GitHub)" <gi...@apache.org>.
xiangfu0 commented on code in PR #15192:
URL: https://github.com/apache/pinot/pull/15192#discussion_r1982446491


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java:
##########
@@ -49,6 +50,7 @@ public class PlannerContext implements AutoCloseable {
   private final LogicalPlanner _relTraitPlanner;
 
   private final Map<String, String> _options;
+  private final Map<String, String> _plannerOutput;

Review Comment:
   depends on if we will have more listeners to put more stuffs later on.
   E.g. cost based optimizer etc



-- 
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-unsubscribe@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org