ekkinox opened a new issue, #27905: URL: https://github.com/apache/datafusion/issues/27905
### Is your feature request related to a problem or challenge? Struct compatibility checks are quadratic in struct width. `map_struct_fields` in `datafusion/common/src/nested_struct.rs` searches the source fields linearly for every target field. It backs `validate_struct_compatibility` and `cast_struct_column`, so it runs whenever a file's struct schema differs from the table schema: during physical expression adaptation, once per file and per expression, and again when batches are cast. This hurts tables with wide struct columns. We store OpenTelemetry attributes as a struct with one field per attribute key, often thousands of fields. On a query over 109 files with six struct-field projections and one struct-field filter, a CPU profile of the query process showed about 70% of samples in byte-slice equality called from `map_struct_fields` and its callers. The query ran into a 60 s timeout. A standalone benchmark of `validate_struct_compatibility`, where the source holds every other field of the target: | Target fields | Time per call | |--------------:|--------------:| | 100 | 12.7 µs | | 1,000 | 1.21 ms | | 10,000 | 105 ms | ### Describe the solution you'd like Build a name-to-index map of the source fields once per call and use it for the overlap check and for each target field lookup. Keep the existing semantics: the first source field wins when names repeat. ### Describe alternatives you've considered - Caching adapted expressions across files with identical schemas (#21554) would cut how often the check runs, but each check stays quadratic. - Validating only the struct fields a query reads would change which schema mismatches raise errors. ### Additional context #24316 indexed `DFSchema` lookups by name; this is the same problem in `nested_struct`. -- 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]
