pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix SP-GiST index-only scans with non-returnable keys. 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0c9fc1a96be7054cae5d79a724407426da3cdd8e Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/23fde8c7c98ecb33d6327c2fc53939f2e9766ff3 Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ac42b245f22f91cd1ee9c1cb2b178806030361d1 Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/9492bfd0072a6cf3d7db72ff72d35db73e913bad Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/028d7bda5b46d3e67a1ebea626e6da3e578176a3 Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix SP-GiST index-only scans with non-returnable keys. @ 2026-11-19 21:10 Peter Geoghegan <pg@bowt.ie> 0 siblings, 0 replies; 6+ messages in thread From: Peter Geoghegan @ 2026-11-19 21:10 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix SP-GiST index-only scans with non-returnable keys. SP-GiST index-only scans always set returnData for the key column's consistent functions, even when its opclass cannot return its keys. An index-only scan that used such an opclass would therefore return whatever leaf_consistent gave it as the key column of the tuple that it reconstructs. This could lead to the scan returning the wrong values for INCLUDE columns. It could also cause "can't happen" errors and hard crashes. Fix by setting returnData only when the opclass can return its keys. Otherwise the scan just uses NULL as the key column of the heap tuple that holds reconstructed values. This is safe because the index AM API allows that for a column that amcanreturn reports as not returnable, and the planner never lets an index-only scan reference such a column. The problem has been reachable since commit ff963b393 added poly_ops, which is still the only in-core opclass that cannot return its keys. Commit 09c1c6ab4 made it much easier to hit when it added support for INCLUDE columns to SP-GiST. Reported-by: Rui Zhao <zhaorui126@gmail.com> Author: Bilal Kahraman <kahramannbilal@gmail.com> Discussion: https://postgr.es/m/CAPkprsxXAapaJJHYVL=xLnntKDH6SZKxoxkNeDy3ZcHLqowfsw@mail.gmail.com Discussion: https://postgr.es/m/CAHWVJhHccsjcBFdgFemRu_x8n_o0_kn_MMx5g+uAnYtYxKxO5w@mail.gmail.com Discussion: https://postgr.es/m/CAPkprsycOwGY4tfU_14aX-3LyLS+D4++4a4umGS0QYgjW+hzMg@mail.gmail.com Backpatch-through: 15 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e48b96a4fcd17deea664d0b35f39e73ad37f1a01 Modified Files -------------- src/backend/access/spgist/spgscan.c | 9 +++++---- src/test/regress/expected/create_index_spgist.out | 20 ++++++++++++++++++++ src/test/regress/sql/create_index_spgist.sql | 11 +++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-11-19 21:10 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie> 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie> 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie> 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie> 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie> 2026-11-19 21:10 pgsql: Fix SP-GiST index-only scans with non-returnable keys. Peter Geoghegan <pg@bowt.ie>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox