rewrite query5 api impl for slightly more efficiency (i hope)
Merge branch '2.0-maint' into 2.1-maint