chore: refactor query distribution, extract duplicate aggregation into functions#758 - Longhorn Developers