Via Quarry we have access to various Wikimedia and Toolforge databases. It provides more powerful queries than MediaWiki API.
We may have a WDQS service to query it. The format may be similar to T230759: Create a service to query Common-hosted tabular data. By query only the result set instead of doing SQL query on-the-fly, We avoid the problem of expensive queries that will run for an arbitrary long time in WDQS.