Re: Hash a ScalarArrayOpExpr whose array is fixed for one execution

From: best xmg <bestxmg(at)gmail(dot)com>
To: geidav(dot)pg(at)gmail(dot)com
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Hash a ScalarArrayOpExpr whose array is fixed for one execution
Date: 2026-10-26 10:29:22
Message-ID: CABkqMMsykvJjBmWn8Z1fowEgvkF3K0arD+GrrF3pyuhRqi1CYg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi David,

Thanks for the review. Attached is v4.

> Thanks for the explanations. They were useful. All of them should be
> turned into comments in the code.

Done.

> A comment saying why we cannot unify the Const and non-Const case in
> execExprInterp.c would be useful. One could think that it might be a
> good idea to now always go the non-Const route for code simplicity /
> consistency.

Done, above saop_hash_eval_array(). The non-Const route copies the
array, and a Const array needs no copy, because it is part of the plan.

> Doesn't saop_array_may_vary_walker() misses T_CaseWhen? T_CaseExpr's
> args is a list of CaseWhen nodes. When recursing it doesn't match
> against T_CaseWhen and returns true while CaseWhen doesn't vary. I think
> that would only occur in this form:
>
> x = ANY(CASE WHEN $2 THEN $1 ELSE '{...}' END

This form is hashed. The walker never gets a CaseWhen node, so
T_CaseWhen is not needed. I went through expression_tree_walker() and
ran a test to confirm this.

> - Use castNode() instead of C casts

Done.

> - Use a wrapper around saop_array_may_vary_walker(), e.g.
> saop_array_may_vary()

Done.

> Beyond that, I would make the commit message less technical. This level
> of detail should be code comments. The commit message should high-level
> outline the change and its limitations. You could put there e.g. where
> the optimization doesn't apply today and where it still doesn't apply
> wit the commit's changes (soft errors, standalone expressions).

Done. The commit message of 0002 now gives a high-level outline, and
says where the optimization still does not apply.

Any further feedback or guidance would be much appreciated.

Regards,
Linden

Attachment Content-Type Size
v4-0002-Hash-a-ScalarArrayOpExpr-whose-array-is-fixed-for.patch application/octet-stream 35.5 KB
v4-0001-Refactor-hashed-ScalarArrayOpExpr-evaluation.patch application/octet-stream 11.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-10-26 10:30:49 Re: Why clearing the VM doesn't require registering vm buffer in wal record
Previous Message Ishjaap Singh 2026-10-26 10:28:46 Re: [PATCH v1] Fix tab completion for REINDEX SYSTEM