Fix bug of IndexError when querying to empty table.