pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Plug holes in SP-GiST quad tree getQuadrant() 7+ messages / 1 participants [nested] [flat]
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/eab68b1be6aa05e42330d5d7a00006e7dac8f997 Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/84572589029e53a5391f7047cf97969cd5b2b77d Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/fc834ccab5b48538ee1ffecc19b180a0f6a573a6 Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3d8c50317e01a8126eea09d1faf3786076890c64 Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/235e15ec7b5a1200394ca37c6b58b500b7ac1284 Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/37ecbb4384348f6ee9c2c1e3576e41d8a7d7c68b Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Plug holes in SP-GiST quad tree getQuadrant() @ 2026-10-14 11:26 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-14 11:26 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Plug holes in SP-GiST quad tree getQuadrant() getQuadrant() places a point on each axis with the fuzzy comparisons FPlt(), FPgt() and FPeq(), which do not cover every case. FPeq() compares the rounded difference against EPSILON, while FPlt() and FPgt() round the sum of one operand and EPSILON. When the centroid plus EPSILON rounds up, a point equal to that rounded sum is more than EPSILON above the centroid, so FPeq() is false. FPgt() compares it with the same rounded sum, so it is false too, and FPlt() is false because the point is above the centroid. The same gap exists below the centroid, when the centroid minus EPSILON rounds down. No quadrant matches, and index builds, inserts and searches fail with "getQuadrant: impossible case". To fix, fall back to deciding each axis separately: Use fuzzy tests first and then tiebreak with exact comparisons. That gives every finite value a quadrant (NaN coordinates are still an error). Points that matched a fuzzy test before are routed as before, so existing indexes remain valid. Bug: #19597 Reported-by: Michael Malis <malis@pgrust.com> Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com> Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com> Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/0e95444395db94610eb09aec92b6ce89202b8805 Modified Files -------------- src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++-- src/test/regress/expected/spgist.out | 16 +++++++++++ src/test/regress/sql/spgist.sql | 13 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-10-14 11:26 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org> 2026-10-14 11:26 pgsql: Plug holes in SP-GiST quad tree getQuadrant() John Naylor <john.naylor@postgresql.org>
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