Sorry for the late feedback.

The one above is called `distincts_sources`, it loops over all distinct expr, get the sources, then flatten and uniq. It has already 'unwrapped' all the metadata, cleaned-up duplicates, etc. It's useful to build the list of distinct fields, regardless of how they got introduced in the query.

The other one is a local variable poorly called `distinct_sources` (notice no 's' at distinct) which retrieves the sources for one specific distinct expression. So the main difference is that one is concerned with all the distincts expr and their sources and one is concerned with only one and its metadata!

Yeah... it's nowhere near perfect, but merging them isn't as easy as it looks (especially as we are comparing to `order_by_sources` which does something similar to `distincts_sources`, so to make comparison easy, it's easier if both have a similar output format... except that `orders_by_sources` isn't concerned with metadata at all, so we'd have to rework that too). Gotta pick the better of two evils!