Re: Properly pathify the union planner

David Rowley <dgrowleyml@gmail.com>

From: David Rowley <dgrowleyml@gmail.com>
To: Andy Fan <zhihuifan1213@163.com>
Cc: Richard Guo <guofenglinux@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2024-02-15T05:03:43Z
Lists: pgsql-hackers
On Wed, 7 Feb 2024 at 12:05, Andy Fan <zhihuifan1213@163.com> wrote:
> +static int
> +pathkeys_useful_for_setop(PlannerInfo *root, List *pathkeys)
> +{
> +       int                     n_common_pathkeys;
> +
> +       if (root->setop_pathkeys == NIL)
> +               return 0;                               /* no special setop ordering requested */
> +
> +       if (pathkeys == NIL)
> +               return 0;                               /* unordered path */
> +
> +       (void) pathkeys_count_contained_in(root->setop_pathkeys, pathkeys,
> +                                                                          &n_common_pathkeys);
> +
> +       return n_common_pathkeys;
> +}
>
> The two if-clauses looks unnecessary, it should be handled by
> pathkeys_count_contained_in already. The same issue exists in
> pathkeys_useful_for_ordering as well. Attached patch fix it in master.

I agree.  I'd rather not have those redundant checks in
pathkeys_useful_for_setop(), and I do want those functions to be as
similar as possible.  So I think adjusting it in master is a good
idea.

I've pushed your patch.

David



Commits

  1. Don't adjust ressortgroupref in generate_setop_child_grouplist()

  2. Don't zero tuple_fraction when planning UNIONs with ORDER BYs

  3. Fix assert failure when planning setop subqueries with CTEs

  4. Allow planner to use Merge Append to efficiently implement UNION

  5. Simplify PathKey checking code

  6. Clarify the 'rows' parameter in create_append_path