Sorry for spamming, but I found a more elegant way to check ifquery_paths is NIL without modified list_copy_head.
Here is a third iteration of this patch.
-- Miroslav