fix countOnly for group sql

fixes: #1844
This commit is contained in:
Yu Ming Zhu 2019-11-28 12:13:39 +00:00 committed by Tomas Kopecek
parent 4b70721fe0
commit b92143370e

View file

@ -8658,7 +8658,9 @@ SELECT %(col_str)s
%(limit_str)s
"""
if self.opts.get('countOnly'):
if self.opts.get('offset') or self.opts.get('limit'):
if self.opts.get('offset') \
or self.opts.get('limit') \
or (self.enable_group and self.opts.get('group')):
# If we're counting with an offset and/or limit, we need
# to wrap the offset/limited query and then count the results,
# rather than trying to offset/limit the single row returned
@ -8684,7 +8686,9 @@ SELECT %(col_str)s
query = query % locals()
if self.opts.get('countOnly') and \
(self.opts.get('offset') or self.opts.get('limit')):
(self.opts.get('offset') or
self.opts.get('limit') or
(self.enable_group and self.opts.get('group'))):
query = 'SELECT count(*)\nFROM (' + query + ') numrows'
if self.opts.get('rowlock'):
query += '\n FOR UPDATE'