pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-performance@postgresql.org
Subject: Re: mysterious difference in speed when combining two queries with OR
Date: Wed, 23 Apr 2008 09:58:10 +0200
Message-ID: <20080423075810.GB8401@a-kretschmer.de> (raw)
In-Reply-To: <20080423072303.GF11886@amin>
References: <20080423072303.GF11886@amin>

am  Wed, dem 23.04.2008, um  9:23:07 +0200 mailte Hans Ekbrand folgendes:
> I cannot understand why the following two queries differ so much in execution time (almost ten times)

wild guess: different execution plans.


Can you show us the plans? (EXPLAIN ANALYSE SELECT ...)

> 
> Query A (two queries)
> 
> select distinct moment.mid from moment,timecard where parent = 45 and (pid=17 and timecard.mid = moment.mid) order by moment.mid;
> select distinct moment.mid from moment,timecard where parent = 45 and (pbar = 0) order by moment.mid;
> 
> Query B (combining the two with OR)
> 
> select distinct moment.mid from moment,timecard where parent = 45 and ((pid=17 and timecard.mid = moment.mid) or (pbar = 0)) order by moment.mid;
>
> [ snip ]
> 
> I should say that this is on postgresql 7.4.16 (debian stable).

Uhh. Why not a recent version? We have 8.3.0...


> 
> Can query B be rewritten so that it would execute faster?

Quick and dirty: use both selects (query A) combined with UNION.

I guess, with a recent version the planner can use a bitmap index scan
to perform Query B faster.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



view thread (8+ messages)  latest in thread

Message-ID: <20080423075810.GB8401@a-kretschmer.de>
Permalink:  ../20080423075810.GB8401@a-kretschmer.de/
Also on:    postgresql.org/message-id/20080423075810.GB8401@a-kretschmer.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: andreas.kretschmer@schollglas.com
  Subject: Re: mysterious difference in speed when combining two queries with OR
  In-Reply-To: <20080423075810.GB8401@a-kretschmer.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox