riverandeye opened a new issue, #2824: URL: https://github.com/apache/iceberg-go/issues/2824
### Summary Follow-up to #2779, raised in its review. Before a copy-on-write `Delete` or filtered `Overwrite` rewrites a file, it checks whether the rewrite would drop any row. When the rewrite preserves row lineage (v3), that check reads every column of the file with no row-group pruning. A file that does hold a matching row is then read again in full by the rewrite. So on v3 the check costs as much as reading the file, while on v2 it reads only the filter columns and stops at the first match. ### Current behavior [`postFilterDropsRows`](https://github.com/apache/iceberg-go/blob/43e3820a05ef2d185f231b1605051d6f1b1547c5/table/transaction_delete.go#L814-L850) scans with `projectedSchema: c.schema`, `boundRowFilter: AlwaysTrue` and no `rowGroupFilter`. It then applies the survivor filter to each batch. One data file of 29 MB holds 200,000 rows in 10 row groups. Its columns are an `int64` id and eight 32 character strings. The table below shows the bytes read from data files by a copy-on-write `Delete` of `id = X`. | | v2 | v3 | |---|---|---| | no row matches (`X` inside the bounds but missing) | 30 KB (0.00x) | 29.1 MB (1.00x) | | one row matches | 29.1 MB (1.00x) | 58.1 MB (2.00x) | ### Expected behavior The v3 check should cost about the same as the v2 check. A file with no matching row should be read only for its filter columns. A file with a matching row should be read in full once, by the rewrite. Spark works this way. For a copy-on-write `DELETE`, Spark runs a separate query that finds the files holding a matching row ([`RowLevelOperationRuntimeGroupFiltering`](https://github.com/apache/spark/blob/v4.0.0/sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/RowLevelOperationRuntimeGroupFiltering.scala#L33-L44), [matching rows plan](https://github.com/apache/spark/blob/v4.0.0/sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/RowLevelOperationRuntimeGroupFiltering.scala#L86-L88)). Iceberg then keeps only those files in the copy-on-write scan ([`SparkCopyOnWriteScan.filter`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkCopyOnWriteScan.java#L89-L124)). * The query that finds the files is a regular batch scan. Spark prunes it to the condition columns plus `_file`. The reader projects only those columns and the columns the file's deletes need, and it passes the residual filter to Parquet ([`BaseBatchReader`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/BaseBatchReader.java#L82-L87)). * That filter drives the stats, dictionary and bloom row-group filters ([`ReadConf`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/parquet/src/main/java/org/apache/iceberg/parquet/ReadConf.java#L94-L115)). * The rewrite scan itself ignores residuals and reads every row of the kept files ([`buildCopyOnWriteScan`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkScanBuilder.java#L285-L297)). So Spark also reads a rewritten file twice. The first read covers only the condition columns and the row groups that can match. Core `DeleteFiles` never checks rows. It removes only files whose metrics show that every row matches, and it fails on a file where only some rows match ([`ManifestFilterManager`](https://github.com/apache/iceberg/blob/2e12b22aea8e43af1d3bc1559decc6bbe2e92ac0/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java#L472-L479)). ### Proposed change * Project only the columns the filter references (the `dropProjection` the v2 check already builds), and prepare the survivor filter against that projection. The projection still goes through the scanner, so type promotion and initial defaults apply before the filter, as they do in the rewrite. * Prune row groups with the negated survivor filter, which selects the rows the rewrite drops. A row group it prunes has no row to drop, so skipping it cannot change the answer. * This is not the `rowGroupFilter` the rewrite uses. The rewrite prunes with the survivor filter, which skips row groups where every row is dropped. With that filter, a file whose matching rows fill whole row groups would look unmatched, and its rows would stay. * Keep `boundRowFilter` as `AlwaysTrue` and apply the survivor filter after the scan, as the rewrite does. * Answer without reading when the negated filter binds to `AlwaysTrue` or `AlwaysFalse`, as the v2 check does. The projection is empty in that case. With this change, the same benchmark reads 30 KB on v3 when no row matches, and 29.1 MB when one row matches. -- 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]
