From: Paul Ramsey Date: Wed, 28 Oct 2009 18:20:44 +0000 (+0000) Subject: Fix error in picksplit routine, perhaps will fix balance problem. X-Git-Tag: 1.5.0b1~335 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ed764f900f8eb6a07f509b972a6bf2143b787e5;p=postgis Fix error in picksplit routine, perhaps will fix balance problem. git-svn-id: http://svn.osgeo.org/postgis/trunk@4691 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/geography_gist.c b/postgis/geography_gist.c index 498984516..c4d511f8b 100644 --- a/postgis/geography_gist.c +++ b/postgis/geography_gist.c @@ -959,6 +959,18 @@ static int geography_gist_picksplit_badratio(int x, int y) return FALSE; } +static bool geography_gist_picksplit_badratios(int *pos, int dims) +{ + int i; + for ( i = 0; i < dims; i++ ) + { + if( geography_gist_picksplit_badratio(pos[2*i],pos[2*i+1]) == FALSE ) + return FALSE; + } + return TRUE; +} + + /* ** Where the picksplit algorithm cannot find any basis for splitting one way ** or another, we simply split the overflowing node in half. @@ -1101,16 +1113,6 @@ static void geography_gist_picksplit_constructsplit(GIST_SPLITVEC *v, OffsetNumb v->spl_ldatum_exists = v->spl_rdatum_exists = false; } -static bool geography_gist_picksplit_badratios(int *pos, int dims) -{ - int i; - for ( i = 0; i < dims; i++ ) - { - if( geography_gist_picksplit_badratio(pos[2*i],pos[2*i+1]) == FALSE ) - return FALSE; - } - return TRUE; -} #define BELOW(d) (2*(d)) #define ABOVE(d) ((2*(d))+1) @@ -1182,6 +1184,7 @@ Datum geography_gist_picksplit(PG_FUNCTION_ARGS) /* Initialize memory structures. */ nbytes = (max_offset + 2) * sizeof(OffsetNumber); ndims_pageunion = GIDX_NDIMS(box_pageunion); + POSTGIS_DEBUGF(4, "[GIST] ndims_pageunion == %d", ndims_pageunion); pos = palloc(2*ndims_pageunion * sizeof(int)); list = palloc(2*ndims_pageunion * sizeof(OffsetNumber*)); box_union = palloc(2*ndims_pageunion * sizeof(GIDX*)); @@ -1227,7 +1230,7 @@ Datum geography_gist_picksplit(PG_FUNCTION_ARGS) ** sides of the page union box can occasionally all end up in one place, leading ** to this condition. */ - if ( geography_gist_picksplit_badratios(pos,ndims_pageunion) == TRUE ) + if ( geography_gist_picksplit_badratios(pos,ndims_pageunion) == TRUE ) { /* ** Instead we split on center points and see if we do better. @@ -1300,20 +1303,23 @@ Datum geography_gist_picksplit(PG_FUNCTION_ARGS) { int posd = Max(pos[ABOVE(d)],pos[BELOW(d)]); if( posd > posmax ) + { direction = d; + posmax = posd; + } } if( direction == -1 || posmax == -1 ) { /* ERROR OUT HERE */ } - POSTGIS_DEBUGF(4, "[GIST] 'picksplit' splitting on axis %d",direction); + POSTGIS_DEBUGF(3, "[GIST] 'picksplit' splitting on axis %d", direction); geography_gist_picksplit_constructsplit(v, list[BELOW(direction)], - pos[BELOW(direction)], - &(box_union[BELOW(direction)]), - list[ABOVE(direction)], - pos[ABOVE(direction)], - &(box_union[ABOVE(direction)]) ); + pos[BELOW(direction)], + &(box_union[BELOW(direction)]), + list[ABOVE(direction)], + pos[ABOVE(direction)], + &(box_union[ABOVE(direction)]) ); PG_RETURN_POINTER(v); diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c index 600fe3fac..ad73e5176 100644 --- a/postgis/geography_measurement.c +++ b/postgis/geography_measurement.c @@ -328,7 +328,6 @@ Datum geography_bestsrid(PG_FUNCTION_ARGS) int type1, type2; int empty1 = LW_FALSE; int empty2 = LW_FALSE; - int twoargs = LW_FALSE; Datum d1 = PG_GETARG_DATUM(0); Datum d2 = PG_GETARG_DATUM(1);