'Given a "before" copy of the alias_refcounts dictionary (as
\'initial_refcounts\') and a collection of aliases that may have been
changed or created, works out which aliases have been created since
then and which ones haven\'t been used and promotes all of those
aliases, plus any children of theirs in the alias tree, to outer joins.'

def promote_unused_aliases(self, initial_refcounts, used_aliases):

    considered = {}
    for alias in self.tables:
        if (alias not in used_aliases):
            continue
        if ((alias not in initial_refcounts) or (self.alias_refcount[alias] == initial_refcounts[alias])):
            parent = self.alias_map[alias][LHS_ALIAS]
            must_promote = considered.get(parent, False)
            promoted = self.promote_alias(alias, must_promote)
            considered[alias] = (must_promote or promoted)
