improve query statistics

Close #718