| From: | shihao zhong <zhong950419(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | 303677365(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19873: planner silently drops the second ORDER BY sort key when both keys reference the same expression und |
| Date: | 2026-11-28 18:17:51 |
| Message-ID: | CAGRkXqS7uEP6Cc+R-emk6Jh404D30zW4JtNS9g6m2K2ski81mQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Tom,
> Hmm, why should it matter whether the opfamily is default or not?
> I grant that the pattern_ops opfamily is collation-insensitive,
> but we shouldn't assume that that's universally true.
Right. The catalogs can't tell us which opfamilies sort without the
collation while their "=" uses it. index_create() names the pattern_ops
opclasses for that reason, so v3 names their two opfamilies.
I didn't do it your first way, by not merging a key into an earlier
one. That puts one EC twice in a pathkey list and trips two
assertions. It also misses single-key cases like WHERE x = 'a' ORDER
BY x USING ~<~. So v3 gives a pattern_ops sort key its own EC from the
start.
> Do you have an idea where it needs to be fixed?
The parser copies ~<~ from ORDER BY into GROUP BY, DISTINCT and
PARTITION BY. Then the grouping sorts by ~<~ but compares with "=".
That is a different mechanism from 0001. So the fix is a separate
v3-0002 in the planner, and you can take 0001 alone. It doesn't fix
DISTINCT ON and aggregate DISTINCT, nor window peers and incremental
sort.
Thanks,
Shihao
| Attachment | Content-Type | Size |
|---|---|---|
| v3-0002-Fix-grouping-by-pattern_ops-operators-under-nondeter.patch | application/octet-stream | 8.1 KB |
| v3-0001-Fix-merging-of-sort-keys-under-nondeterministic-coll.patch | application/octet-stream | 6.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | shihao zhong | 2026-11-28 17:40:00 | Re: BUG #17545: Incorrect selectivity for IS NOT DISTINCT FROM and NULLs |