fixed bugs for zero-length tables, foreign keys with null values