fix table scan queries