BTW, I just had another thought about reducing the cost of
has_parallel_hazard checks, to wit: you already made one pass over the
entire query to verify that there's no PARALLEL UNSAFE functions anywhere.
If that pass were to also track whether there are any PARALLEL RESTRICTED
functions anywhere, then in very many common cases, subsequent tests on
portions of the query would not have to do anything, because we'd already
know there was nothing to worry about.
regards, tom lane