pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mario Splivalo <mario.splivalo@megafon.hr>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query much slower when run from postgres function
Date: Mon, 09 Mar 2009 19:36:10 -0400
Message-ID: <17869.1236641770@sss.pgh.pa.us> (raw)
In-Reply-To: <49B5948C.3050800@megafon.hr>
References: <49B51B60.6030600@megafon.hr>
	<27649.1236616294@sss.pgh.pa.us>
	<49B56A3D.8000100@megafon.hr>
	<14317.1236628318@sss.pgh.pa.us>
	<49B5948C.3050800@megafon.hr>

Mario Splivalo <mario.splivalo@megafon.hr> writes:
> So, it is the same. When I do EXPLAIN ANALYZE EXECUTE I get completely
> different execution plan:
> ...
>                      ->  Bitmap Heap Scan on messages
> (cost=287.98..21192.42 rows=12848 width=4) (actual time=0.049..0.169
> rows=62 loops=1)
>                            Recheck Cond: (service_id = $1)
>                            ->  Bitmap Index Scan on
> messages_uq__service_id__tan  (cost=0.00..284.77 rows=12848 width=0)
> (actual time=0.038..0.038 rows=62 loops=1)
>                                  Index Cond: (service_id = $1)

Well, there's the problem: without knowing what the specific service_id
is, the planner is estimating 12848 matching rows, which is evidently
off by a couple of orders of magnitude.  And that's pushing it to adopt
a hash join instead of a nestloop.  Are you sure the stats on this
table are up to date?  Maybe you need to increase the stats target?

			regards, tom lane



view thread (26+ messages)  latest in thread

Message-ID: <17869.1236641770@sss.pgh.pa.us>
Permalink:  ../17869.1236641770@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17869.1236641770@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mario.splivalo@megafon.hr
  Subject: Re: Query much slower when run from postgres function
  In-Reply-To: <17869.1236641770@sss.pgh.pa.us>

* 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