wangyum opened a new pull request #27632: [WIP][SPARK-30872][SQL] Constraints 
inferred from inferred attributes
URL: https://github.com/apache/spark/pull/27632
 
 
   ### What changes were proposed in this pull request?
   This PR fix a special case about infer additional constraints. How to 
reproduce this issue:
   ```scala
   scala> spark.range(20).selectExpr("id as a", "id as b", "id as 
c").write.saveAsTable("t1")
   
   scala> spark.sql("select count(*) from t1 where a = b and b = c and (c = 3 
or c = 13)").explain(false)
   == Physical Plan ==
   *(2) HashAggregate(keys=[], functions=[count(1)])
   +- Exchange SinglePartition, true, [id=#76]
      +- *(1) HashAggregate(keys=[], functions=[partial_count(1)])
         +- *(1) Project
            +- *(1) Filter (((((((isnotnull(c#36L) AND ((b#35L = 3) OR (b#35L = 
13))) AND isnotnull(b#35L)) AND (a#34L = c#36L)) AND isnotnull(a#34L)) AND 
(a#34L = b#35L)) AND (b#35L = c#36L)) AND ((c#36L = 3) OR (c#36L = 13)))
               +- *(1) ColumnarToRow
                  +- FileScan parquet default.t1[a#34L,b#35L,c#36L] Batched: 
true, DataFilters: [isnotnull(c#36L), ((b#35L = 3) OR (b#35L = 13)), 
isnotnull(b#35L), (a#34L = c#36L), isnotnull(a#..., Format: Parquet, Location: 
InMemoryFileIndex[file:/Users/yumwang/Downloads/spark-3.0.0-preview2-bin-hadoop2.7/spark-warehous...,
 PartitionFilters: [], PushedFilters: [IsNotNull(c), 
Or(EqualTo(b,3),EqualTo(b,13)), IsNotNull(b), IsNotNull(a), 
Or(EqualTo(c,3),EqualT..., ReadSchema: struct<a:bigint,b:bigint,c:bigint>
   ```
   
   We can infer more constraints: `(a#34L = 3) OR (a#34L = 13)`.
   
   
   ### Why are the changes needed?
   
   Improve query performance.
   
   ### Does this PR introduce any user-facing change?
   No.
   
   
   ### How was this patch tested?
   Unit test.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to