The check for parallel_safe should be even cheaper than cost comparison so I think it's better to do that first. The attached patch does this and also updates the comment to mention the requirement about being parallel-safe.
Thanks Richard
v1-0001-Adjustment-to-get_cheapest_path_for_pathkeys.patch
Description: Binary data