This cost equivalence is an important aspect of the present invention as it enables the optimizer to select a left deep shape that is semantically incorrect as the best plan and then apply a transformation to generate a semantically correct version of this plan.