'Converts the query to do count(...) or count(distinct(pk)) in order to
get its size.'

def add_count_column(self):

    if (not self.distinct):
        if (not self.select):
            count = self.aggregates_module.Count('*', is_summary=True)
        else:
            assert (len(self.select) == 1), ("Cannot    add    count    col    with    multiple    cols    in    'select':    %r" % self.select)
            count = self.aggregates_module.Count(self.select[0].col)
    else:
        opts = self.get_meta()
        if (not self.select):
            count = self.aggregates_module.Count((self.join((None, opts.db_table, None)), opts.pk.column), is_summary=True, distinct=True)
        else:
            assert (len(self.select) == 1), "Cannot    add    count    col    with    multiple    cols    in    'select'."
            count = self.aggregates_module.Count(self.select[0].col, distinct=True)
        self.distinct = False
    self.aggregates = {None: count}
    self.set_aggregate_mask(None)
    self.group_by = None
