API: Rewrite queries for list=allusers
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 29 Sep 2014 16:17:25 +0000 (12:17 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 29 Sep 2014 16:34:18 +0000 (12:34 -0400)
commite6b9fa4abdb56fda263be6bd37a80f939e4ac893
tree9cdb48dcd950266dc045e26039b293948c43d454
parenta9d0cfc4d5a855c5196a0b6af620222516b05bd6
API: Rewrite queries for list=allusers

The existing query only works with a single value for augroup, or mostly
if it's combined with auprop=groups or auprop=rights (since most users
don't have every possible group).

When used with multiple values for augroup, it will raise an error if it
happens to encounter enough users who have more than one of the
specified groups. And further, it will lead to repeated groups for these
users if combined with auprop=groups or auprop=rights.

An attempt to use EXISTS instead of a JOIN to query user_groups failed
because it made the planner scan the user table where a smaller scan of
user_groups plus a filesort was faster. So instead, let's just fix it
directly by acknowledging that supplying multiple groups for
augroup is going to give us duplicate rows.

At the same time, let's try using a subquery (with GROUP_CONCAT) to
fetch the actual groups the user belongs to, both to avoid processing so
many duplicate rows and to simplify the row-processing code. And let's
kill the forced index, it's probably not needed anymore.

Bug: 70496
Change-Id: Ic87dbc3b2d933775ca71a72932e0658e2f082bb6
includes/api/ApiQueryAllUsers.php