Re: Operator COMMUTATOR - how does postgresql use this information

Lists: pgsql-general
From: "Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Operator COMMUTATOR - how does postgresql use this information
Date: 2008-04-11 12:48:36
Message-ID: 53F9CF533E1AA14EA1F8C5C08ABC08D203A9A5A5@ZDND.DND.boston.cob
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Does PostgreSQL use the COMMUTATOR property of an operator to determine
if flip-flopped arguments can be collapsed.

I used to think it did until someone pointed it doesn't - For example
in the below

SELECT b.*
FROM boszip b INNER JOIN landparcels l
ON (b.the_geom && l.the_geom AND l.the_geom && b.the_geom AND
l.the_geom && b.the_geom )
WHERE l.gid = b.gid and b.gid = l.gid
limit 1


If I look at the query plan - I see the plan has reduced things down to

l.gid = b.gid AND (b.the_geom && l.the_geom AND l.the_geom &&
b.the_geom)

Why is (b.the_geom && l.the_geom AND l.the_geom && b.the_geom) not
reduced down to just

b.the_geom && l.the_geom

even though && is defined as the commutator of &&?

Thanks,
Regina

-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Operator COMMUTATOR - how does postgresql use this information
Date: 2008-04-11 16:06:15
Message-ID: 12804.1207929975@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

"Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov> writes:
> Does PostgreSQL use the COMMUTATOR property of an operator to determine
> if flip-flopped arguments can be collapsed.

No. In recent releases we don't even bother to look for simple
duplicate clauses (it's seldom worth the cycles), let alone clauses that
would be duplicates after some transformation or other.

> I used to think it did until someone pointed it doesn't - For example
> in the below

> SELECT b.*
> FROM boszip b INNER JOIN landparcels l
> ON (b.the_geom && l.the_geom AND l.the_geom && b.the_geom AND
> l.the_geom && b.the_geom )
> WHERE l.gid = b.gid and b.gid = l.gid
> limit 1

> If I look at the query plan - I see the plan has reduced things down to

> l.gid = b.gid AND (b.the_geom && l.the_geom AND l.the_geom &&
> b.the_geom)

8.3 will do that (prior releases will often fail to recognize the
redundancy) but it's an outgrowth of mergejoin equivalence-class
processing. && isn't a mergejoinable equality operator so nothing much
happens to those clauses.

regards, tom lane