>>! In T39902#2209625, @Anomie wrote:
>>>! In T39902#2208376, @GWicke wrote:
>> This end point already supports restricting links to a specific namespace using the `plnamespace` parameter.  Along the same lines, we could add a `plbrokenlinks` flag parameter, which would restrict the returned list of titles to broken / red links only. 
> 
> We might have to disable it (or reduce the functionality) in miser mode though, like we do with various other parameters, to avoid bugs like T97797.

The current query for this module is reasonably simple, basically
```
-- Generic
SELECT pl_from, pl_namespace, pl_title FROM pagelinks WHERE pl_from IN (...) ORDER BY pl_from ASC, pl_namespace ASC, pl_title ASC LIMIT 501;

-- With plnamespace
SELECT pl_from, pl_namespace, pl_title FROM pagelinks WHERE pl_from IN (...) AND pl_namespace IN (...) ORDER BY pl_from ASC, pl_namespace ASC, pl_title ASC LIMIT 501;
```

Adding a `plbrokenlinks` parameter would require joining with `page`, though:
```
SELECT pl_from, pl_namespace, pl_title FROM pagelinks LEFT JOIN page ON (pl_namespace = page_namespace AND pl_title = page_title) WHERE pl_from IN (...) AND page_id IS NULL ORDER BY pl_from ASC, pl_namespace ASC, pl_title ASC LIMIT 501;
```
Just a join there is probably not too bad (it's an `eq_ref` which isn't a bad join type, although it's still a join on a 261-byte key so it's not the greatest), but using the join as a filter where the vast majority of the time the filter is going to fail would certainly be a T97797 issue waiting to be reported.

So what you'd end up with on WMF wikis is that using your `plbrokenlinks` parameter would do a query more like
```
SELECT pl_from, pl_namespace, pl_title, page_id FROM pagelinks LEFT JOIN page ON (pl_namespace = page_namespace AND pl_title = page_title) WHERE pl_from IN (...) ORDER BY pl_from ASC, pl_namespace ASC, pl_title ASC LIMIT 501;
```
then on the PHP side it would filter out the rows with `$row->page_id !== null`, typically leaving zero to actually be returned and a continuation for it to do the same check on the next batch of links.