Re: Query only slow on first run

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dave Dutcher" <dave(at)tridecap(dot)com>
Cc: "'tmp'" <skrald(at)amossen(dot)dk>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Query only slow on first run
Date: 2007-11-28 17:12:52
Message-ID: 2224.1196269972@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Dave Dutcher" <dave(at)tridecap(dot)com> writes:
> ... According to the explain analyze
> there are only 646 rows in posts which match your criteria, so it does seem
> like scanning posts first might be the right thing to do.

No, that's not right. What the output actually shows is that only 646
posts rows were needed to produce the first 200 aggregate rows, which was
enough to satisfy the LIMIT. The planner is evidently doing things this
way in order to exploit the presence of the LIMIT --- if it had to
compute all the aggregate results it would likely have picked a
different plan.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Simon Riggs 2007-11-28 17:22:56 Re: TB-sized databases
Previous Message Usama Munir Dar 2007-11-28 16:20:46 Re: Training Recommendations