Re: mysterious difference in speed when combining two queries with OR

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Hans Ekbrand" <hans(dot)ekbrand(at)sociology(dot)gu(dot)se>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: mysterious difference in speed when combining two queries with OR
Date: 2008-04-23 13:31:39
Message-ID: 873apcu284.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Hans Ekbrand" <hans(dot)ekbrand(at)sociology(dot)gu(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Jeffrey Baker 2008-04-23 16:40:23 Re: SELECT 'DBD::Pg ping test'
Previous Message PFC 2008-04-23 12:56:56 Re: mysterious difference in speed when combining two queries with OR