Fix assignment of IDs to multiple relations when one of them is empty an...

...d add test for it (and in general for ID assignment)
I remember yesterday @feiranwang  mentioned that we probably want to use `COUNT(*)` instead of `max(id)` to handle NULL case. Has he already fixed this? Which way is better?