zhouqingqing / qpmodel

A Relational Optimizer and Executor
MIT License
64 stars 18 forks source link

REMOVE_FROM WORK: fix setop #248

Closed pkommoju closed 3 years ago

pkommoju commented 3 years ago

LogicAppend needs extra information to allow remove_from optimization to work correctly on UNION queries inside a FromQuery. Resolve all selects in UNION. When removefrom is true, we don't generate a setop plan and therefore all except the first select remain without ordinals resolved. This leads to their output being null at execution time and the result is null pointer exception. The way to handle the situation is to let each LogicAppend node to know the SetOp tree it is part of. This is done by passing the SetOp tree whose left and right selects correspond to the left and right nodes of this logicAppend node in the constructor. Visit each branch of the SetOp tree and locate the select which corrresponds to left and right node and record those select lists as leftExprs and rightExprs_.

Override ResolveColumnOrdinal in LogicAppend and using the saved selections, resolve the minimum of selections or reqOutput from each child.

Set the top level LogicAppend's outputs to those of the first child.

Two other related minor issues fixed: 1) columnOutputNames of selects remaining in upper case was causing column not found/can't bind column error. 2) Union oprator string names were in lower case but the query was in upper case, this caused parse failure.