pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Helio Campos Mello de Andrade <helio.campos@gmail.com>
To: Віталій Тимчишин <tivv00@gmail.com>
Cc: Jeff Davis <pgsql@j-davis.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: PostgreSQL OR performance
Date: Thu, 6 Nov 2008 10:26:20 -0200
Message-ID: <29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com> (raw)
In-Reply-To: <331e40660811060246m51df553egd4e2ba91f08d1434@mail.gmail.com>
References: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com>
	<1225902700.1432.53.camel@jdavis>
	<331e40660811060246m51df553egd4e2ba91f08d1434@mail.gmail.com>

For what i see in four OR-plan.txt tou are doing too much "sequencial scan"
. Create some indexes for those tables using the fields that you use an it
may help you.

OBS: If you already have lots of indexes in your tables it may be a good
time for you re-think your strategy because it´s ot working.
Tips:
  1 - create indexes for the tables with the fields that you will use in the
query if it is your most important query. If you have others querys that are
used please post those here and we can help you to desing a better plan.
  2 - You cold give us the configuration os the hardware and the posgresql
configuration file and we can see what is going on.

Regards

On Thu, Nov 6, 2008 at 8:46 AM, Віталій Тимчишин <tivv00@gmail.com> wrote:

>
> My main message is that I can see this in many queries and many times. But
> OK, I can present exact example.
>
> 2008/11/5 Jeff Davis <pgsql@j-davis.com>
>
>> On Wed, 2008-11-05 at 13:12 +0200, Віталій Тимчишин wrote:
>> > For a long time already I can see very poor OR performance in
>> > postgres.
>> > If one have query like "select something from table where condition1
>> > or condition2" it may take ages to execute while
>> > "select something from table where condition1" and "select something
>> > from table where condition2" are executed very fast and
>> > "select something from table where condition1 and not condition2 union
>> > all select something from table where condition2" gives required
>> > results fast
>> >
>>
>> What version are you using?
>
>
> Server version 8.3.3
>
>
>>
>>
>> Have you run "VACUUM ANALYZE"?
>
>
> I have autovacuum, but for this example I did vacuum analyze of the whole
> DB.
> The real-life query (autogenerated) looks like the next:
> select t0.id as pk1,t1.id as pk2 ,t0.run_id as f1_run_id,t1.run_id as
> f2_run_id
> from tmpv_unproc_null_production_company_dup_cons_company as t0, (select *
> from production.company where run_id in (select id from production.run where
> name='test')) as t1
> where
> t0.name = t1.name
> or
> (t0.name,t1.name) in (select s1.name, s2.name from atom_match inner join
> atoms_string s1 on atom_match.atom1_id = s1.id  inner join atoms_string s2
> on atom_match.atom2_id = s2.id where s1.atom_type_id = -1 and
> match_function_id = 2)
>
> with tmpv_unproc_null_production_company_dup_cons_company:
>
> create temporary view tmpv_unproc_null_production_company_dup_cons_company
> as select * from production.company where 1=1 and status='unprocessed' and
> run_id in (select id from production.run where name='test')
>
>>
>>
>> Next, do:
>>
>> EXPLAIN ANALYZE select something from table where condition1 or
>> condition2;
>
>
> without analyze is in OR-plan.txt
> Also plans for only condition1, only condition2 and union is attached
>
>
>
> --
> Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance
>
>


-- 
Helio Campos Mello de Andrade


view thread (16+ messages)  latest in thread

Message-ID: <29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com>
Permalink:  ../29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com/
Also on:    postgresql.org/message-id/29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: helio.campos@gmail.com, tivv00@gmail.com, pgsql@j-davis.com
  Subject: Re: PostgreSQL OR performance
  In-Reply-To: <29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com>
  References: <331e40660811050312u552cab53ifa88e493e1c4f7ac@mail.gmail.com> <1225902700.1432.53.camel@jdavis> <331e40660811060246m51df553egd4e2ba91f08d1434@mail.gmail.com> <29e3942f0811060426k5fe34b1av401a2dba62e4ae3c@mail.gmail.com>

* 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