Improve performance of reading iceberg table with many equality delete files#17115
Conversation
alexjo2144
left a comment
There was a problem hiding this comment.
The core change here, reducing the number of StructLikeSets created seems like a good idea to me. Just a couple code simplification questions.
Just for reference here's a thread on this from the original PR: #13219 (comment)
cc: @findepi
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteFilter.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteFilter.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteSets.java
Outdated
Show resolved
Hide resolved
cd0d4d8 to
4f8e9ca
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
|
Great job on a quick fix of the issue, @Heltman @alexjo2144 ! It may significantly improve Trino's performance on Iceberg delete file filtering. IMHO, the patch made by @alexjo2144 makes less code changes and seems easier to understand, but some problems may not completely resolved:
|
|
Looks like using a Set is safe there in the Iceberg Spark implementation because they do an additional projection step to ensure that the readers return the Schema stored in the Set there, even if it doesn't match the file schema. We don't have that additional projection here yet, so it will cause problems in Trino. It needs some clean-up but here's a test case illustrating the problem: https://gist.github.com/alexjo2144/8a80ff5146ab3c82fa0c5fc5b4f33e66 So we can either need to add the additional projection, or use an ordered Collection like a List |
|
@alexjo2144 Schema mismatch is indeed a problem, but fortunately, the additional projection step implemented by spark is also easy to implement in trino. We only need to refer to the implementation of spark and organize the fields in order when reading the delete files. Trino's ParquetReader has additional projection(same as spark). Please check the new commit, I fix this problem and add your test case. |
c571e0a to
fb9c955
Compare
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
Can you pls provide a test case in your PR which can be used to showcase this situation? I was trying with the code from |
@findinpath just check below. |
It is difficult to simulate this performance problem, because it needs to have more deletefiles, and it has been updated many times according to same columns. We only need to imagine that if there are two deletefiles, each with 10,000 lines, 9,000 of which are the same. Originally, we need to filter a line of data from 20,000 lines, but now we only need to match 11,000 lines. |
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
fb9c955 to
66fe0b4
Compare
|
@findinpath , add testMultipleEqualityDeletes, delete file has compact: |
66fe0b4 to
852299d
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteFilter.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
findinpath
left a comment
There was a problem hiding this comment.
Overall there are some cosmetics improvements needed and testing coverage for nested deletes is missing.
Great work ! 👍
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteSets.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteFilter.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteSets.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
552b092 to
58a765d
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
d9193b1 to
947faab
Compare
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
c1a4fa9 to
7a23964
Compare
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergV2.java
Outdated
Show resolved
Hide resolved
7a23964 to
541cbb4
Compare
|
Pending the last couple comments from Marius, this looks good to me. |
541cbb4 to
3e0278f
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
ff47acc to
6ed8f78
Compare
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java
Outdated
Show resolved
Hide resolved
plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/delete/EqualityDeleteFilter.java
Outdated
Show resolved
Hide resolved
6ed8f78 to
69ca01b
Compare
There was a problem hiding this comment.
the call site looks like new EqualityDeleteSet(deleteSchema, schemaFromHandles(readColumns))
are the constructor arg names right? is the call site right?
There was a problem hiding this comment.
I suggest public EqualityDeleteSet(Schema deleteSchema, Schema fileSchema). Because first one is schema from iceberg metadata, second schema from read file (parquet, orc, etc.)
There was a problem hiding this comment.
@Heltman yes, public EqualityDeleteSet(Schema deleteSchema, Schema fileSchema) should be fine. Let's go forward with this suggestion
There was a problem hiding this comment.
Finally we reached a consensus, public EqualityDeleteSet(Schema deleteSchema, Schema dataSchema) is good idea. deleteSchema come from iceberg metadata, dataSchema come from equality delete file.
69ca01b to
62276ce
Compare
62276ce to
a3d08f2
Compare
|
Merged, thanks! |

Description
Fixes #17114
Additional context and related issues
If a split with many delete file
RowPredicate.andwill create a deep stack, this pr compact all StructLikeSet to a collection to reduce stack depth.The stack depth is only a hidden danger. The real problem is that multiple
StructLikeSetof a split are not merged according to the ids, resulting in too manyStructLikeSetbeing generated, which makes the filtering efficiency very lowly.The main content is to classify delete files according to id, and only use the same
StructLikeSetto collect deletion data.Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text: