ApiQueryLogEvents: Add IGNORE INDEX to avoid MariaDB optimizer bug
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 4 Mar 2019 15:44:05 +0000 (10:44 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 4 Mar 2019 15:51:32 +0000 (10:51 -0500)
commite6021abc9c1654c09d3b2ae9b4b4d723fd43c983
treedc743c4f8e13f47cf3a0992e83fd38e316e60f13
parente0a20177a0068d68315c142a30d56c77c2b3de2f
ApiQueryLogEvents: Add IGNORE INDEX to avoid MariaDB optimizer bug

The optimizer in MariaDB 10.1.37 and 10.1.38 seems to wildly
underestimate the cost of using the `times` index and overestimate the
cost of using the `user_time` or `actor_time` indexes, leading to it
choosing a plan that may have to fetch and filesort 10000000s of rows
versus the 10s or 1000s fetched with no filesort if it used the correct
index.

We can get it to use the correct index by having it ignore `times`, and
this also won't interfere with it choosing `log_user_type_time`,
`log_actor_type_time`, or other more specific indexes in cases where
those would be more appropriate.

As usual, this should be reviewed as MySQL/MariaDB versions used are
updated and removed if the optimizer is fixed.

Bug: T71222
Change-Id: I16dba2158865917e763722a5848cb5d483bf1a0b
includes/api/ApiQueryLogEvents.php