[ALOY-1081] improve query selection speed
Merge pull request #510 from skypanther/ALOY-1081

[ALOY-1081] improve query selection speed