Skip to content

Physical plan does not support logical expression Exists #23022

@zyuiop

Description

@zyuiop

Describe the bug

The following query (from the HotCRP open source software) fails to build a physical plan:

select (select group_concat(paperId, ' ', conflictType) from PaperConflict where contactId=1), exists (select * from PaperReview where contactId=1 and reviewType>0), exists (select * from PaperReview where requestedBy=1 and reviewType>0 and reviewType<=2 and contactId!=1), 0

The error is

DataFusion error: This feature is not implemented: Physical plan does not support logical expression Exists(Exists { subquery: <subquery>, negated: false })

The reason is that some queries have subqueries in their projection, but the decorrelate_predicate_subquery optimizer step only accepts filter plans.

To Reproduce

A smaller query is:

select exists (select paperId from PaperReview)

Expected behavior

No response

Additional context

Logical plan:

Projection: (<subquery>), EXISTS (<subquery>) AS EXISTS (SELECT * FROM PaperReview WHERE contactId = 1 AND reviewType > 0), EXISTS (<subquery>) AS EXISTS (SELECT * FROM PaperReview WHERE requestedBy = 1 AND reviewType > 0 AND reviewType <= 2 AND contactId <> 1), Int64(0) AS 0
    Subquery:
      Aggregate: groupBy=[[]], aggr=[[group_concat(CAST(PaperConflict.paperId AS Utf8), Utf8(" "), CAST(PaperConflict.conflictType AS Utf8))]]
        TableScan: PaperConflict projection=[paperId, conflictType], full_filters=[PaperConflict.contactId = Int32(1)]
    Subquery:
      TableScan: PaperReview projection=[paperId, reviewId, contactId, reviewType, requestedBy, reviewToken, reviewRound, reviewOrdinal, reviewBlind, reviewTime, reviewModified, reviewSubmitted, reviewAuthorSeen, timeDisplayed, timeApprovalRequested, reviewNeedsSubmit, reviewViewScore, rflags, timeRequested, timeRequestNotified, reviewAuthorModified, reviewNotified, reviewAuthorNotified, reviewEditVersion, reviewWordCount, s01, s02, s03, s04, s05, s06, s07, s08, s09, s10, s11, tfields, sfields], full_filters=[PaperReview.contactId = Int32(1), PaperReview.reviewType > Int8(0)]
    Subquery:
      TableScan: PaperReview projection=[paperId, reviewId, contactId, reviewType, requestedBy, reviewToken, reviewRound, reviewOrdinal, reviewBlind, reviewTime, reviewModified, reviewSubmitted, reviewAuthorSeen, timeDisplayed, timeApprovalRequested, reviewNeedsSubmit, reviewViewScore, rflags, timeRequested, timeRequestNotified, reviewAuthorModified, reviewNotified, reviewAuthorNotified, reviewEditVersion, reviewWordCount, s01, s02, s03, s04, s05, s06, s07, s08, s09, s10, s11, tfields, sfields], full_filters=[PaperReview.requestedBy = Int32(1), PaperReview.reviewType > Int8(0), PaperReview.reviewType <= Int8(2), PaperReview.contactId != Int32(1)]
    EmptyRelation: rows=1

Plan for the smaller minimal example query:

Projection: EXISTS (<subquery>) AS EXISTS (SELECT paperId FROM PaperReview)
  Subquery:
    TableScan: PaperReview projection=[paperId]
  EmptyRelation: rows=1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions