This logic was repeated, and I need to use it in the next diff.
Depends on D13137
Tests.
Rename
Rebase
I would move this to line 45 to make this private
Make the method private
Remove the method from DatabaseQueryExecutor