Re: mysterious difference in speed when combining two queries with OR - Mailing list pgsql-performance

From Gregory Stark
Subject Re: mysterious difference in speed when combining two queries with OR
Date
Msg-id 873apcu284.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: mysterious difference in speed when combining two queries with OR  (Hans Ekbrand <hans.ekbrand@sociology.gu.se>)
List pgsql-performance
"Hans Ekbrand" <hans.ekbrand@sociology.gu.se> writes:

> No, I just wanted to show the time differences, I haven't used join
> before. Now that you have adviced me to, I have tried your suggestion
> to rewrite B as a union and it works good! Just as fast as the A Query!

You can even do better. If you know the two sets of mid are disjoint you can
use UNION ALL. If not you could remove the two DISTINCTs as the UNION will
take care of removing duplicates.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's On-Demand Production Tuning

pgsql-performance by date:

Previous
From: PFC
Date:
Subject: Re: mysterious difference in speed when combining two queries with OR
Next
From: "Jeffrey Baker"
Date:
Subject: Re: SELECT 'DBD::Pg ping test'