Page MenuHomePhabricator

Forcing an index on a select query when doing a table join gives a query error
Closed, DuplicatePublicPRODUCTION ERROR

Description

Forcing an index on a select query when doing a table join gives a query error, we get

SELECT page_title,page_namespace FROM mw_page JOIN mw_categorylinks ON ((page_id=cl_from)) FORCE INDEX (page_random) WHERE page_is_redirect = '0' AND (page_random >= 0.757003172866) AND cl_to = 'Test' ORDER BY page_random LIMIT 1

from within function "RandomPage::selectRandomPageFromDB". Database returned error "1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FORCE INDEX (page_random) WHERE page_is_redirect = '0' AND (page_random >= 0.757' at line 1 (localhost)".

When we want

SELECT page_title,page_namespace FROM mw_page FORCE INDEX (page_random) JOIN mw_categorylinks ON ((page_id=cl_from)) WHERE page_is_redirect = '0' AND (page_random >= 0.757003172866) AND cl_to = 'Test' ORDER BY page_random LIMIT 1

Noticed when refactoring RandomPage and RandomInCategory to reduce code duplication


Version: unspecified
Severity: minor

Details

Reference
bz27081