From c2f586ac7d3613f2053c32a911d0e52fb8975151 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 23 Apr 2015 18:20:00 +0000 Subject: [PATCH] #3018, GROUP BY geography sometimes returns duplicate rows git-svn-id: http://svn.osgeo.org/postgis/trunk@13437 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + postgis/geography_btree.c | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 7da25d146..457eca201 100644 --- a/NEWS +++ b/NEWS @@ -96,6 +96,7 @@ PostGIS 2.2.0 - #3061, Allow duplicate points in JSON, GML, GML ST_GeomFrom* functions - #3086, ST_DumpValues() crashes backend on cleanup with invalid band indexes + - #3018, GROUP BY geography sometimes returns duplicate rows * Code refactoring * diff --git a/postgis/geography_btree.c b/postgis/geography_btree.c index dd3da7969..23b59e064 100644 --- a/postgis/geography_btree.c +++ b/postgis/geography_btree.c @@ -210,7 +210,7 @@ Datum geography_eq(PG_FUNCTION_ARGS) /* Must be able to build box for each argument (ie, not empty geometry) */ if ( ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(0), gbox1) || - ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), gbox2) ) + ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), gbox2) ) { PG_RETURN_BOOL(FALSE); } @@ -249,13 +249,33 @@ Datum geography_cmp(PG_FUNCTION_ARGS) geography_gidx_center(gbox1, &p1); geography_gidx_center(gbox2, &p2); - if ( p1.x > p2.x && p1.y > p2.y && p1.z > p2.z ) + if ( ! FP_EQUALS(p1.x, p2.x) ) + { + if (p1.x < p2.x) + { + PG_RETURN_INT32(-1); + } PG_RETURN_INT32(1); + } - if ( FP_EQUALS(p1.x, p2.x) && FP_EQUALS(p1.y, p2.y) && FP_EQUALS(p1.z, p2.z) ) - PG_RETURN_INT32(0); + if ( ! FP_EQUALS(p1.y, p2.y) ) + { + if (p1.y < p2.y) + { + PG_RETURN_INT32(-1); + } + PG_RETURN_INT32(1); + } - PG_RETURN_INT32(-1); + if ( ! FP_EQUALS(p1.z, p2.z) ) + { + if (p1.z < p2.z) + { + PG_RETURN_INT32(-1); + } + PG_RETURN_INT32(1); + } + PG_RETURN_INT32(0); } -- 2.40.0