MaxGekk commented on code in PR #59985:
URL: https://github.com/apache/spark/pull/59985#discussion_r4467503052


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/basicPhysicalOperators.scala:
##########
@@ -256,22 +263,25 @@ trait GeneratePredicateHelper extends PredicateHelper {
       k: Int,
       conjunct: Expression,
       afterNullable: Boolean,
-      generated: Array[Boolean]): Seq[Expression] = {
-    if (afterNullable) {
-      val pending = 
notNullPreds.take(precedingNotNulls(k)).zipWithIndex.filterNot {
-        case (_, idx) => generated(idx)
-      }
-      if (pending.nonEmpty && (mayRaise(conjunct) || pending.exists(p => 
mayRaise(p._1)))) {
-        pending.map { case (p, idx) =>
-          generated(idx) = true
-          p
-        }
-      } else {
-        Nil
+      generated: Array[Boolean]): Seq[Int] = {
+    val pending = 
notNullPreds.take(precedingNotNulls(k)).zipWithIndex.filterNot {
+      case (_, idx) => generated(idx)
+    }
+    val conjunctMayRaise = mayRaise(conjunct)
+    val positioned = if (afterNullable &&
+        (conjunctMayRaise || pending.exists(p => mayRaise(p._1)))) {
+      pending
+    } else if (conjunctMayRaise) {

Review Comment:
   The numbers from `FilterNotNullCheckBenchmark` on GitHub Actions (JDK 21, 
20M Parquet rows, `d DECIMAL(38, 10)`, ANSI on, pushdown and AQE off, best of 
5): master run https://github.com/MaxGekk/spark/actions/runs/41826503647, this 
branch at 376f3b2e355 
https://github.com/MaxGekk/spark/actions/runs/41826508536. The two runs landed 
on different runners (EPYC 9V45 vs 9V74), so the absolute times differ by about 
30% across the board; the ratio to the control, `y > 98 AND d > 5`, which 
generates the same code on both, is the comparable figure.
   
   | filter | master | branch | master / control | branch / control |
   |---|---|---|---|---|
   | `d IS NOT NULL AND upper(name) = 'X' AND d > 5` | 645 ms | 836 ms | 1.83 | 
1.83 |
   | `d IS NOT NULL AND y * 3 > 1000000 AND d > 5` | 310 ms | 1158 ms | 0.88 | 
2.54 |
   | `upper(name) = 'X' AND d > 5` (inferred check) | 612 ms | 789 ms | 1.73 | 
1.73 |
   | `y > 98 AND d > 5` (control) | 353 ms | 456 ms | 1 | 1 |
   
   So the written check before `upper(name)` no longer moves and costs nothing 
(same ratio), and the inferred check keeps its placement (same ratio). The 
written check before the ANSI arithmetic moves and decodes `d` on every row, 
about 2.9x on this shape: that is the price of the fix where a conjunct can 
raise, and what SPARK-60872 (testing only the null bit there) would remove. The 
benchmark class is on the two scratch branches only, not in this 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to