• Tom Lane's avatar
    Disable physical tlist if any Var would need multiple sortgroupref labels. · aeb9ae64
    Tom Lane authored
    As part of upper planner pathification (commit 3fc6e2d7) I redid
    createplan.c's approach to the physical-tlist optimization, in which scan
    nodes are allowed to return exactly the underlying table's columns so as
    to save doing a projection step at runtime.  The logic was intentionally
    more aggressive than before about applying the optimization, which is
    generally a good thing, but Andres Freund found a case in which it got
    too aggressive.  Namely, if any column is referenced more than once in
    the parent plan node's sorting or grouping column list, we can't optimize
    because then that column would need to have more than one ressortgroupref
    label, and we only have space for one.
    
    Add logic to detect this situation in use_physical_tlist(), and also add
    some error checking in apply_pathtarget_labeling_to_tlist(), which this
    example proves was being overly cavalier about whether what it was doing
    made any sense.
    
    The added test case exposes the problem only because we do not eliminate
    duplicate grouping keys.  That might be something to fix someday, but it
    doesn't seem like appropriate post-beta work.
    
    Report: <20160526021235.w4nq7k3gnheg7vit@alap3.anarazel.de>
    aeb9ae64
createplan.c 180 KB