Improve query efficiency.

Get data query was very slow when there was a lot of data.