The SQL query provided there is valid, yet a MariaDB error about its syntax is returned by Toolforge SQL Optimizer.
SQL Optimizer works by putting a SLEEP(1) in the query and EXPLAINing the query using the process ID. It is only but so smart, unfortunately. Here it went with:
SELECT SLEEP(1), DISTINCT page_id FROM page
which won't work. I guess if there's only a DISTINCT [field name] in the select clause, we need to put the SLEEP(1) after it, not before.