Skip to content

SQL: push UNION result filters into each part #2302

@ideoma

Description

@ideoma

Is your feature request related to a problem?

Union used to push filters into the sub queries but it was abandoned in 6.4.2 because the tables can have different column names.

Describe the solution you'd like.

When query

SELECT * FROM 
bus INNER JOIN (
  (SELECT datetime,"from" as busId FROM branch2 WHERE logical) 
  UNION
  (SELECT datetime,"to" as busId FROM branch2 WHERE logical)
) 
 u ON bus.busId = u.busId AND bus.datetime = u.datetime 
WHERE bus.datetime = '2026-10-05T09:55'

it should push datetime = '2026-10-05T09:55' filter into UNION parts like this

SELECT * FROM 
bus INNER JOIN (
  (SELECT datetime,"from" as busId FROM branch2 WHERE logical AND datetime = '2026-10-05T09:55') 
  UNION
  (SELECT datetime,"to" as busId FROM branch2 WHERE logical AND datetime = '2026-10-05T09:55')
) 
 u ON bus.busId = u.busId AND bus.datetime = u.datetime 
WHERE bus.datetime = '2026-10-05T09:55'

Describe alternatives you've considered.

No response

Additional context.

Reported in #2182

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featureFeature requestsSQLIssues or changes relating to SQL execution

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions