Skip to content

Commit d314677

Browse files
HyukjinKwonJoshRosen
authored andcommitted
[SPARK-16461][SQL] Support partition batch pruning with <=> predicate in InMemoryTableScanExec
## What changes were proposed in this pull request? It seems `EqualNullSafe` filter was missed for batch pruneing partitions in cached tables. It seems supporting this improves the performance roughly 5 times faster. Running the codes below: ```scala test("Null-safe equal comparison") { val N = 20000000 val df = spark.range(N).repartition(20) val benchmark = new Benchmark("Null-safe equal comparison", N) df.createOrReplaceTempView("t") spark.catalog.cacheTable("t") sql("select id from t where id <=> 1").collect() benchmark.addCase("Null-safe equal comparison", 10) { _ => sql("select id from t where id <=> 1").collect() } benchmark.run() } ``` produces the results below: **Before:** ``` Running benchmark: Null-safe equal comparison Running case: Null-safe equal comparison Stopped after 10 iterations, 2098 ms Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 on Mac OS X 10.11.5 Intel(R) Core(TM) i7-4850HQ CPU 2.30GHz Null-safe equal comparison: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative ------------------------------------------------------------------------------------------------ Null-safe equal comparison 204 / 210 98.1 10.2 1.0X ``` **After:** ``` Running benchmark: Null-safe equal comparison Running case: Null-safe equal comparison Stopped after 10 iterations, 478 ms Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 on Mac OS X 10.11.5 Intel(R) Core(TM) i7-4850HQ CPU 2.30GHz Null-safe equal comparison: Best/Avg Time(ms) Rate(M/s) Per Row(ns) Relative ------------------------------------------------------------------------------------------------ Null-safe equal comparison 42 / 48 474.1 2.1 1.0X ``` ## How was this patch tested? Unit tests in `PartitionBatchPruningSuite`. Author: hyukjinkwon <[email protected]> Closes apache#14117 from HyukjinKwon/SPARK-16461.
1 parent e388bd5 commit d314677

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/columnar/InMemoryTableScanExec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ case class InMemoryTableScanExec(
6565
case EqualTo(l: Literal, a: AttributeReference) =>
6666
statsFor(a).lowerBound <= l && l <= statsFor(a).upperBound
6767

68+
case EqualNullSafe(a: AttributeReference, l: Literal) =>
69+
statsFor(a).lowerBound <= l && l <= statsFor(a).upperBound
70+
case EqualNullSafe(l: Literal, a: AttributeReference) =>
71+
statsFor(a).lowerBound <= l && l <= statsFor(a).upperBound
72+
6873
case LessThan(a: AttributeReference, l: Literal) => statsFor(a).lowerBound < l
6974
case LessThan(l: Literal, a: AttributeReference) => l < statsFor(a).upperBound
7075

sql/core/src/test/scala/org/apache/spark/sql/execution/columnar/PartitionBatchPruningSuite.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class PartitionBatchPruningSuite
8585
// Comparisons
8686
checkBatchPruning("SELECT key FROM pruningData WHERE key = 1", 1, 1)(Seq(1))
8787
checkBatchPruning("SELECT key FROM pruningData WHERE 1 = key", 1, 1)(Seq(1))
88+
checkBatchPruning("SELECT key FROM pruningData WHERE key <=> 1", 1, 1)(Seq(1))
89+
checkBatchPruning("SELECT key FROM pruningData WHERE 1 <=> key", 1, 1)(Seq(1))
8890
checkBatchPruning("SELECT key FROM pruningData WHERE key < 12", 1, 2)(1 to 11)
8991
checkBatchPruning("SELECT key FROM pruningData WHERE key <= 11", 1, 2)(1 to 11)
9092
checkBatchPruning("SELECT key FROM pruningData WHERE key > 88", 1, 2)(89 to 100)

0 commit comments

Comments
 (0)