Add SQL views for changeset rewirer
Created by: eseliger
Closes #16271. This was a little tricker than I anticipated because I forgot I also had conditions depending on external variables in the CTEs, but in the end I think it's kinda okay for now. I also found some potential to simplify some things, so overall this is an improvement IMO. Still not 100% happy with this bear of a query, but at least a small step towards this being manageable.