| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Matheus Alcantara <matheusssilv97(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: Enable partitionwise join for partition keys wrapped by RelabelType |
| Date: | 2026-01-15 03:30:41 |
| Message-ID: | CACJufxGqEf8K_kH6JLRY6gXWVh9p6BikWSsGrwmzY6oPrSEvQQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, Dec 15, 2025 at 10:46 PM Matheus Alcantara
<matheusssilv97(at)gmail(dot)com> wrote:
>
> Hi,
>
> The function exprs_known_equal() is used by the planner to determine if
> two expressions are semantically equivalent, often by checking if they
> belong to the same Equivalence Class (EC).
>
hi.
src/include/nodes/primnodes.h CollateExpr comments:
/*----------
* CollateExpr - COLLATE
*
* The planner replaces CollateExpr with RelabelType during expression
* preprocessing, so execution never sees a CollateExpr.
*----------
*/
examine_variable handling RelabelType (transformed from CollateExpr) is wrong, i
think. Roughly speaking it will reduce "t2.c collate case_insensitive" to
"t2.c". see [1].
If examine_variable does not strip the RelabelType(CollateExpr) node, then
estimate_num_groups->add_unique_group_var may need to deal with RelabelType.
The estimate_num_groups function should account for collation settings. "GROUP
BY a" and "GROUP BY a COLLATE case_insensitive" may result in different row
estimates and should be handled distinctly. Therefore exprs_known_equal within
add_unique_group_var must ensure collation is compared before assuming equality.
In this context, while strippping RelabelType, we should ensure
exprCollation(RelabelType->arg) is the same as the RelabelType->resultcollid.
However, it does not affect partitionwise join, because commit [2] already fixed
the collation issue. so we don't have to worry about
have_partkey_equi_join->exprs_known_equal code path for the RelabelType node.
so i change exprs_known_equal to:
+ /* Remove any relabel decorations if collation match */
+ if (IsA(expr, RelabelType))
+ {
+ RelabelType *relabel = castNode(RelabelType, expr);
+ Expr *rexpr = (Expr *) relabel;
+
+ while (rexpr && IsA(rexpr, RelabelType))
+ rexpr = ((RelabelType *) rexpr)->arg;
+
+ if (exprCollation((Node *) rexpr) == relabel->resultcollid)
+ expr = rexpr;
+ }
[1] https://postgr.es/m/CACJufxGLCiyhM+P0gxesg2x--PTrMY3PszqSqOq_H4QS_oq3Jg@mail.gmail.com
[2] https://git.postgresql.org/cgit/postgresql.git/commit/?id=075acdd93388c080c0fb0aca5723144ad7a56dac
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Enable-partitionwise-join-for-partition-keys-wrapped-by-RelabelTy.patch | text/x-patch | 6.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Henson Choi | 2026-01-15 03:46:16 | Re: Row pattern recognition |
| Previous Message | Andreas Karlsson | 2026-01-15 03:20:45 | Re: Add missing JIT inline pass for llvm>=17 |