Opened 6 years ago

Closed 6 years ago

#4088 closed defect (fixed)

Erroneous definition of relative position operators in PostGIS

Reported by: ezimanyi Owned by: pramsey
Priority: medium Milestone: PostGIS 2.4.5
Component: postgis Version: 2.4.x
Keywords: Cc:

Description

I think there is a problem in the definition of the &<, &>, &<|, and |&> operators in PostGIS since at the SQL level they are defined as being commutative by pairs (e.g., &< are &> commutative) and this should not be the case. As a comparison, the corresponding range operators are not commutative.

select oid, * from pg_operator 
where (oprname = '&<' or oprname = '&>' or oprname = '&<|' or oprname = '|&>') 
and (oprcode::text like 'geometry%' or oprcode::text like 'range%')

3895;"&<";11;10;"b";f;f;3831;3831;16;0;0;"range_overleft";"rangesel";"scalarltjoinsel"
3896;"&>";11;10;"b";f;f;3831;3831;16;0;0;"range_overright";"rangesel";"scalargtjoinsel"
2221902;"&>";2200;16386;"b";f;f;2221809;2221809;16;2221903;0;"geometry_overright";"positionsel";"positionjoinsel"
2221903;"&<";2200;16386;"b";f;f;2221809;2221809;16;2221902;0;"geometry_overleft";"positionsel";"positionjoinsel"
2221908;"|&>";2200;16386;"b";f;f;2221809;2221809;16;2221909;0;"geometry_overabove";"positionsel";"positionjoinsel"
2221909;"&<|";2200;16386;"b";f;f;2221809;2221809;16;2221908;0;"geometry_overbelow";"positionsel";"positionjoinsel"

As can be seen in their C definition in PostGIS

static bool box2df_overleft(const BOX2DF *a, const BOX2DF *b)
{
	if ( ! a || ! b ) return FALSE; /* TODO: might be smarter for EMPTY */

	/* a.xmax <= b.xmax */
	return a->xmax <= b->xmax;
}

static bool box2df_overright(const BOX2DF *a, const BOX2DF *b)
{
	if ( ! a || ! b ) return FALSE; /* TODO: might be smarter for EMPTY */

	/* a.xmin >= b.xmin */
	return a->xmin >= b->xmin;
}

if a &< b (that is a->xmax <= b->xmax) it is not necessarily the case that b &> a (that is b->xmin >= x->xmin).

Change History (1)

comment:1 by pramsey, 6 years ago

Resolution: fixed
Status: newclosed

In 16611:

Remove erroneous commutator definitions for over(left/right/above/below)
operators. Closes #4088

Note: See TracTickets for help on using tickets.