| From: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
|---|---|
| To: | shihao zhong <zhong950419(at)gmail(dot)com> |
| Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 303677365(at)qq(dot)com |
| Subject: | Re: BUG #19873: planner silently drops the second ORDER BY sort key when both keys reference the same expression und |
| Date: | 2026-11-29 21:19:35 |
| Message-ID: | CAN4CZFNe5QuHtTDs2f1meFqkqP4UK7svY+iCHCjQO0Ku7M4DCQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hello
v3-0001 causes two regressions compared to master:
1. DISTINCT ON (x, y) with the pattern key in the middle now returns duplicates
CREATE TABLE pairs (x text COLLATE ci, y int);
INSERT INTO pairs VALUES ('a',1),('A',2),('a',2),('A',1);
SELECT DISTINCT ON (x, y) x, y FROM pairs ORDER BY x, x USING ~<~, y;
-- master: a|1, A|2 v3: A|1, A|2, a|1, a|2
SET enable_presorted_aggregate = on;
SELECT string_agg(DISTINCT x, y::text ORDER BY x, x USING ~<~,
y::text) FROM pairs;
-- master: a2A v3: A2A1a2a
2. Incremental sort with the pattern key first reverses the first row
CREATE TABLE n AS SELECT (CASE WHEN i <= 100 THEN 'A' ELSE 'a' END)
COLLATE ci AS x,
(i <= 100)::int AS suffix FROM
generate_series(1,200) i;
ANALYZE n;
CREATE VIEW byte_first AS SELECT * FROM
(SELECT * FROM n ORDER BY x USING ~<~, suffix OFFSET 0) s ORDER BY x
USING ~<~, x, suffix;
SELECT * FROM byte_first LIMIT 1;
-- master: A|1 (no sort needed)
-- v3: a|0 (Incremental Sort, Presorted Key: n.x); A|1 with
enable_incremental_sort=off
And there's also some unsolved cases
3. FETCH ... WITH TIES still ties A and a
CREATE COLLATION ci (provider = icu, locale = 'und-u-ks-level2',
deterministic = false);
CREATE TABLE t (x text COLLATE ci);
INSERT INTO t VALUES ('a'),('A'),('a'),('A'),('b'),('B'),('b'),('B');
SELECT ARRAY(SELECT x FROM t ORDER BY x, x USING ~<~ FETCH FIRST ROW
WITH TIES); -- {A,A,a,a}
SELECT ARRAY(SELECT x FROM t ORDER BY x, x COLLATE "C" FETCH FIRST ROW
WITH TIES); -- {A,A}
4. 0002 skips citext ordered by the core text ~<~
CREATE SCHEMA ext; CREATE EXTENSION citext SCHEMA ext; -- not in search_path
CREATE TABLE c (x ext.citext COLLATE ci);
INSERT INTO c VALUES ('b'),('a'),('B'),('A'),('a'),('A');
SET enable_hashagg = off;
SELECT x, count(*) FROM c GROUP BY x ORDER BY x USING ~<~; -- A 2, B
1, a 2, b 1
The same query on x::text returns a 4, b 2 with the patch.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-11-30 01:12:09 | Re: BUG #19789: "expression not found in statistics object" for a boolean domain column in an MCV statistics object |
| Previous Message | Ishjaap Singh | 2026-11-29 19:36:53 | Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function |