This is an automated email from the ASF dual-hosted git repository.
hyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 56c4c42 [CALCITE-3885] Restore trace logging for rules queue and
Volcano planner's internal state (Roman Kondakov)
56c4c42 is described below
commit 56c4c4258132d1f56214a5b608391a3511cc9d5e
Author: rkondakov <[email protected]>
AuthorDate: Sun Mar 29 12:55:48 2020 +0300
[CALCITE-3885] Restore trace logging for rules queue and Volcano planner's
internal state (Roman Kondakov)
After fixing CALCITE-3753 the opportunity of tracing the rules queue and
VolcanoPlanner search space state is disappeared: i.e. RuleQueue.dump()
method
was removed. We should restore this opportunity because it affects planner's
debugging capabilities.
Close #1886
---
.../org/apache/calcite/plan/volcano/RuleQueue.java | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
index 4e0da38..1600307 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/RuleQueue.java
@@ -28,6 +28,8 @@ import com.google.common.collect.Multimap;
import org.slf4j.Logger;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.EnumMap;
@@ -162,6 +164,8 @@ class RuleQueue {
* {@link #phaseCompleted(VolcanoPlannerPhase)}.
*/
VolcanoRuleMatch popMatch(VolcanoPlannerPhase phase) {
+ dumpPlannerState();
+
PhaseMatchList phaseMatchList = matchListMap.get(phase);
if (phaseMatchList == null) {
throw new AssertionError("Used match list for phase " + phase
@@ -174,6 +178,8 @@ class RuleQueue {
return null;
}
+ dumpRuleQueue(phaseMatchList);
+
match = phaseMatchList.poll();
if (skipMatch(match)) {
@@ -194,6 +200,39 @@ class RuleQueue {
return match;
}
+ /**
+ * Dumps rules queue to the logger when debug level is set to {@code TRACE}.
+ */
+ private void dumpRuleQueue(PhaseMatchList phaseMatchList) {
+ if (LOGGER.isTraceEnabled()) {
+ StringBuilder b = new StringBuilder();
+ b.append("Rule queue:");
+ for (VolcanoRuleMatch rule : phaseMatchList.preQueue) {
+ b.append("\n");
+ b.append(rule);
+ }
+ for (VolcanoRuleMatch rule : phaseMatchList.queue) {
+ b.append("\n");
+ b.append(rule);
+ }
+ LOGGER.trace(b.toString());
+ }
+ }
+
+ /**
+ * Dumps planner's state to the logger when debug level is set to {@code
TRACE}.
+ */
+ private void dumpPlannerState() {
+ if (LOGGER.isTraceEnabled()) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ planner.dump(pw);
+ pw.flush();
+ LOGGER.trace(sw.toString());
+ planner.getRoot().getCluster().invalidateMetadataQuery();
+ }
+ }
+
/** Returns whether to skip a match. This happens if any of the
* {@link RelNode}s have importance zero. */
private boolean skipMatch(VolcanoRuleMatch match) {