LuciferYang commented on code in PR #60387:
URL: https://github.com/apache/spark/pull/60387#discussion_r4573096780


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -244,6 +245,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
           targetKey,
           currentPlan,
           useMaterializedThreshold = false))
+      // A DSv2 scan can take a filter in fully and leave no `Filter` for it, 
as a built-in file
+      // scan does with its partition filters. With no selective `Filter` 
above the scan, its
+      // pushed filters count as such a `Filter` would, but only for a scan 
whose pushed operations
+      // all work on each row by itself, since the bloom filter's subquery 
reads it again. A pushed
+      // limit, for example, lets the source pick other rows on a second read.
+      case scan: DataSourceV2ScanRelation if scan.onlyRowWisePushdowns &&

Review Comment:
   A V1 path read has the same limitation: its estimate does not shrink with 
the partition filters either, since `PruneFileSourcePartitions` narrows the 
size only for a `CatalogFileIndex`, and neither read reports a row count. A 
built-in V2 file source reads only paths, since a catalog table always reads 
through V1. For a 10-partition dimension filtered by `dp = 1`, I measured the 
dimension side at about 2.4 MB for a V1 path read, 1.0 MB for V2 and 0.24 MB 
for a V1 catalog table. A size estimate after the partition filters would help 
both path reads, so I'd leave it out of this PR. In 04f8a85e9ce the comment on 
the case and the PR description state the limitation.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -244,6 +245,18 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
           targetKey,
           currentPlan,
           useMaterializedThreshold = false))
+      // A DSv2 scan can take a filter in fully and leave no `Filter` for it, 
as a built-in file
+      // scan does with its partition filters. With no selective `Filter` 
above the scan, its
+      // pushed filters count as such a `Filter` would, but only for a scan 
whose pushed operations
+      // all work on each row by itself, since the bloom filter's subquery 
reads it again. A pushed
+      // limit, for example, lets the source pick other rows on a second read.
+      case scan: DataSourceV2ScanRelation if scan.onlyRowWisePushdowns &&
+          scan.pushedFilters.forall(isSimpleExpression) &&

Review Comment:
   Done in 04f8a85e9ce. A DSv2 scan that records a non-simple pushed filter, or 
one whose second read may return other rows, is no longer a creation side, with 
or without a selective `Filter` above it. `d.ds LIKE 'a_' AND d.v > 2` now gets 
no bloom filter, as in V1.
   
   The second check uses a new `repeatableRead` on the scan relation: false 
with a pushed limit, offset, top-N or sample, also a sample in a side of a 
pushed join, and true for a pushed aggregate or join and a copy-on-write target 
read, which `onlyRowWisePushdowns` leaves false. So for a key without a DPP 
filter, a scan with a row-selecting pushdown or a non-simple pushed filter 
stops being a creation side under a selective `Filter`, and the SPARK-60702 
top-N test now expects no bloom filter from it without DPP.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -447,7 +461,8 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
       case Project(projectList, _) => !projectList.forall(e => 
cannotFail(trimAliases(e)))
       case Filter(condition, _) => 
!splitConjunctivePredicates(condition).forall(cannotFail)
       case _: CTERelationRef => true
-      case scan: DataSourceV2ScanRelation => !scan.onlyRowWisePushdowns
+      case scan: DataSourceV2ScanRelation =>
+        !scan.onlyRowWisePushdowns || !scan.pushedFilters.forall(cannotFail)

Review Comment:
   Done in 04f8a85e9ce. `buildScanWithPushedVariants` now records 
`holder.pushedFilterExpressions`, which reference the relation's output, as in 
the plain path. The new test pushes a variant extraction into the dimension 
scan and checks that `d.dp = 1` gets a bloom filter, and that `d.ds RLIKE '^a' 
AND d.v > 2` gets none for a key whose DPP filter is dropped, as in V1. 
`PartitionPruning` reads the same filters, so such a dimension can trigger DPP 
too.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InjectRuntimeFilter.scala:
##########
@@ -447,7 +461,8 @@ object InjectRuntimeFilter extends Rule[LogicalPlan] with 
PredicateHelper with J
       case Project(projectList, _) => !projectList.forall(e => 
cannotFail(trimAliases(e)))
       case Filter(condition, _) => 
!splitConjunctivePredicates(condition).forall(cannotFail)
       case _: CTERelationRef => true
-      case scan: DataSourceV2ScanRelation => !scan.onlyRowWisePushdowns
+      case scan: DataSourceV2ScanRelation =>
+        !scan.onlyRowWisePushdowns || !scan.pushedFilters.forall(cannotFail)

Review Comment:
   I'd keep the check for every DSv2 scan, as V1 does: a V1 JDBC or file 
relation keeps the same predicate in the `Filter` above it, and 
`canEvaluateAgain` rejects it there. An exemption would have to rule out every 
way the join's read of the scan can skip rows the subquery reads, such as 
runtime filtering, partitions a storage-partitioned join drops, or storage 
filters, and a new one would reopen the gap. The cost is the bloom filter on a 
key whose DPP filter is dropped and whose creation side took a filter outside 
the `cannotFail` list.



-- 
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