Change Title::getPreviousRevisionID (and next) to ignore PRIMARY
authorJcrespo <jcrespo@wikimedia.org>
Wed, 8 Mar 2017 09:10:19 +0000 (09:10 +0000)
committerJcrespo <jcrespo@wikimedia.org>
Fri, 10 Mar 2017 08:07:37 +0000 (08:07 +0000)
commit80b9ad3a8a356220223033103252df4ff6e31839
treea559ed4171d80a9d44fedd9e5af6bf5f49146b7c
parent22806b0a4509e97b56fb52b387e17e3c80fb7eb2
Change Title::getPreviousRevisionID (and next) to ignore PRIMARY

Both Title::getPreviousRevisionID and Title::getNextRevisionID
have bad performance under certain versions of MySQL/MariaDB
when the page has many revisions (in the order of dozens of
thousands). This is good enough in most cases.

However, on a contributions slave, where it has an explicity
defined extended secondary key with the primary key, the
performance is really, really bad, performing a full table scan.

By ignoring the PRIMARY KEY index, contributions slaves go from the
worst case to the best case, while not affecting the plan of regular
slaves. It is believed that more recent versions of MySQL chose the
right indexes automatically, because they can use the extended primary
key automatically, without adding it explicitly. If that doesn't
happen, we can consider adding it explicitly to the regular slaves,
too.

In any case, not using the PRIMARY gives always a much better or at
least the same performance (this never causes a regression, unlike
FORCE'ing a specific index).

Bug: T159319
Change-Id: Ibb6e5240b87bd8e2d680fc4d58fcb3db1a4721cc
includes/Title.php