Skip to content

Struct compatibility checks are quadratic in struct width #27905

Description

@ekkinox

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

Additional context

#24316 indexed DFSchema lookups by name; this is the same problem in nested_struct.

Activity

  1. reopened this on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions