Defer applying query binding until the query is being compiled rather than as it's being built. This allows us to order bindings correctly in particular for unions queries and sub queries that involve joins. Fixes #5833.