Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group