Skip to content

makeGettersOverSkyline returns nullptr for unmaterialized intermediate subfield paths #1325

Description

@peterenescu

When subfield pushdown is enabled, makeGettersOverSkyline returns nullptr if a projection references an intermediate subfield path that has no matching prefix in the column's skyline. This is null value is stored directly in renames_ and returned during translate... calls which can lead to crashes without explicit null check handling.

Repro

pushdown subfields enabled on:

SELECT v, nested[1]                                                                                                                               
FROM t                                       
LEFT JOIN (SELECT k, m[100] as nested FROM u) u ON t.k = u.k                                                                                      

(See SubfieldTest.leftJoinWithUnmaterializedSubfield)

Step by step analysis:

  1. intersectWithSkyline iterates all prefixes of the requested subfield path against skyline.pathToExpr. If no prefix matches, it returns nullptr
  2. makeGettersOverSkyline forwards the nullptr
  3. translateSubfield wraps it in an engaged std::optional<ExprCP>(nullptr)
  4. translateExpr checks if (auto path = translateSubfield(expr)) — the optional is truthy, so path.value() returns nullptr
  5. addProjection stores renames_[name] = expr unconditionally, including when expr is nullptr.
  6. Any caller of translateColumn that dereferences the result without a null check crashes.

Known crash sites:

  • addJoinColumns
  • addUnionColumns

Proposed fix: We should probably prevent the nullptr upstream. Either makeGettersOverSkyline should materialize the intermediate container when a skyline exists but doesn't cover the requested prefix, or translateSubfield should distinguish "not a subfield" (std::nullopt) from "subfield but not materialized" (currently optional(nullptr)) and handle the latter explicitly rather than propagating nullptr into renames_.

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