ekkinox opened a new pull request, #27906: URL: https://github.com/apache/datafusion/pull/27906
## Which issue does this PR close? - Closes #27905. ## Rationale for this change `map_struct_fields` searches the source fields linearly for every target field, so struct compatibility checks are quadratic in struct width. The check runs once per file and per adapted expression whenever a file's struct schema differs from the table's, and again in `cast_struct_column`. On tables with wide struct columns (OpenTelemetry attributes stored as one struct field per key, thousands of fields) this was about 70% of a query process's CPU samples and pushed queries past a 60 s timeout. ## What changes are included in this PR? - `map_struct_fields` builds a name-to-index map of the source fields once and uses it for the overlap check and for every target lookup. The first source field still wins when names repeat. - A `nested_struct` criterion benchmark for `validate_struct_compatibility`, where the source holds every other target field. Benchmark, `cargo bench -p datafusion-common --bench nested_struct` against the previous code: | Target fields | Before | After | Change | |--------------:|-------:|------:|-------:| | 100 | 12.7 µs | 4.94 µs | −58% | | 1,000 | 1.21 ms | 45.1 µs | −96% | | 10,000 | 105 ms | 474 µs | −99.5% | Measured on x86_64 Linux with 16 cores, criterion with 1 s warm-up and 3 s measurement. ## What is the testing strategy for this PR? The existing `nested_struct` tests cover compatibility rules, missing and extra fields, and error messages. Two tests are new: one pins the mapping for duplicate, reordered and missing names, the other maps a 2,000-field struct in reverse order. ## Are there any user-facing changes? No. Results and error messages are unchanged. This change was prepared with an AI coding assistant and reviewed by me. -- 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]
