This is an automated email from the ASF dual-hosted git repository.

gengliangwang pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new e02ab1c28355 [SPARK-59456][SQL] Fix: RuleExecutor.PlanChangeLogger 
does work even when it doesn't log
e02ab1c28355 is described below

commit e02ab1c28355a20a84305231bf38dc7c4b5cab1b
Author: bhollis-dbx <[email protected]>
AuthorDate: Thu Oct 22 09:47:12 2026 -0700

    [SPARK-59456][SQL] Fix: RuleExecutor.PlanChangeLogger does work even when 
it doesn't log
    
    ### What changes were proposed in this pull request?
    
    Added a functional `withLogLevel` helper to Logging to make it easy to skip 
work when the log level is below a target.
    
    Then used that in `RuleExecutor.PlanChangeLogger` to avoid calling 
`fastEquals` unnecessarily.
    
    ### Why are the changes needed?
    
    The existing code always called `fastEquals`, even when it couldn't log 
anything because of the log leve..
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    The change itself is trivial.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: OpenAI Codex CLI 0.147.0 (GPT-5)
    
    Closes #58755 from bhollis-dbx/optimize-rule-executor-wide-union.
    
    Authored-by: bhollis-dbx <[email protected]>
    Signed-off-by: Gengliang Wang <[email protected]>
    (cherry picked from commit f96ffb6921640b983f4744b47625ddafb2f43f06)
    Signed-off-by: Gengliang Wang <[email protected]>
---
 .../spark/sql/catalyst/rules/RuleExecutor.scala    | 33 +++++++++++-----------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
index b5a35608a54e..54b396ac2ce6 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala
@@ -55,25 +55,24 @@ class PlanChangeLogger[TreeType <: TreeNode[_]] extends 
Logging {
   private val logBatches = SQLConf.get.planChangeBatches.map(Utils.stringToSeq)
 
   def logRule(ruleName: String, oldPlan: TreeType, newPlan: TreeType): Unit = {
-    if (!newPlan.fastEquals(oldPlan)) {
-      if (logRules.isEmpty || logRules.get.contains(ruleName)) {
-        def message(): MessageWithContext = {
-          val oldPlanStringWithOutput = oldPlan.treeString(verbose = false,
-            printOutputColumns = true)
-          val newPlanStringWithOutput = newPlan.treeString(verbose = false,
-            printOutputColumns = true)
-          // scalastyle:off line.size.limit
+    if (log.isEnabledForLevel(logLevel)) {
+      if ((logRules.isEmpty || logRules.get.contains(ruleName)) &&
+          !newPlan.fastEquals(oldPlan)) {
+        val oldPlanStringWithOutput = oldPlan.treeString(verbose = false,
+          printOutputColumns = true)
+        val newPlanStringWithOutput = newPlan.treeString(verbose = false,
+          printOutputColumns = true)
+        // scalastyle:off line.size.limit
+        logBasedOnLevel(logLevel) {
           log"""
-             |=== Applying Rule ${MDC(RULE_NAME, ruleName)} ===
-             |${MDC(QUERY_PLAN, sideBySide(oldPlan.treeString, 
newPlan.treeString).mkString("\n"))}
-             |
-             |Output Information:
-             |${MDC(QUERY_PLAN, sideBySide(oldPlanStringWithOutput, 
newPlanStringWithOutput).mkString("\n"))}
-           """.stripMargin
-           // scalastyle:on line.size.limit
+            |=== Applying Rule ${MDC(RULE_NAME, ruleName)} ===
+            |${MDC(QUERY_PLAN, sideBySide(oldPlan.treeString, 
newPlan.treeString).mkString("\n"))}
+            |
+            |Output Information:
+            |${MDC(QUERY_PLAN, sideBySide(oldPlanStringWithOutput, 
newPlanStringWithOutput).mkString("\n"))}
+          """.stripMargin
         }
-
-        logBasedOnLevel(logLevel)(message())
+        // scalastyle:on line.size.limit
       }
     }
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to