fixed error with with-indexes
added a quick test to make sure with-indexes behaviour is consistent with the db fn