pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Igor Neyman <ineyman@perceptron.com>
Cc: Dieter Rehbein <dieter.rehbein@skiline.cc>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Re: Join between 2 tables always executes a sequential scan on the larger table
Date: Tue, 02 Apr 2013 11:45:46 -0400
Message-ID: <2515.1364917546@sss.pgh.pa.us> (raw)
In-Reply-To: <A76B25F2823E954C9E45E32FA49D70EC08FCA68F@mail.corp.perceptron.com>
References: <D2BFB0D2-5EB3-4921-8B0B-C44402C9C03B@skiline.cc>
	<A76B25F2823E954C9E45E32FA49D70EC08FCA68F@mail.corp.perceptron.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Igor Neyman <ineyman@perceptron.com> writes:
> The output of explain analyze (Postgres 9.2.3):

> Hash Left Join  (cost=111357.64..126222.29 rows=41396 width=42) (actual time=1982.543..2737.331 rows=41333 loops=1)
>   Hash Cond: ((uc.user_id)::text = (u.id)::text)
>   ->  Seq Scan on user_2_competition uc  (cost=0.00..4705.21 rows=41396 width=33) (actual time=0.019..89.691 rows=41333 loops=1)
>         Filter: ((competition_id)::text = '3cc1cb9b3ac132ad013ad01316040001'::text)
>         Rows Removed by Filter: 80684
>   ->  Hash  (cost=90074.73..90074.73 rows=999673 width=42) (actual time=1977.604..1977.604 rows=999673 loops=1)
>         Buckets: 2048  Batches: 128  Memory Usage: 589kB
>         ->  Seq Scan on "user" u  (cost=0.00..90074.73 rows=999673 width=42) (actual time=0.004..1178.827 rows=999673 loops=1)
> Total runtime: 2740.723 ms


> I expected to see an index-scan on user_2_competition with a hash join to user, not a sequential scan on user.  I've tried this with Postgres 9.1 and 9.2.3).

According to the numbers, you're fetching about a third of the
user_2_competition table, which is well past the point where an
indexscan is of any use.  It's picking the seqscan because it thinks
that's faster, and I'm sure it's right.

The aspect of this plan that actually seems a bit dubious is that it's
hashing the larger input table rather than the smaller one.  There's
a thread going on about that in -hackers right now; we think it's
probably putting too much emphasis on the distribution of the join key
as opposed to the size of the table.

One thing that would help is increasing work_mem --- it looks like you
are using the default 1MB.  Cranking that up to a few MB would reduce
the number of hash batches needed.

			regards, tom lane


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (6+ messages)  latest in thread

Message-ID: <2515.1364917546@sss.pgh.pa.us>
Permalink:  ../2515.1364917546@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2515.1364917546@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, ineyman@perceptron.com, dieter.rehbein@skiline.cc
  Subject: Re: Re: Join between 2 tables always executes a sequential scan on the larger table
  In-Reply-To: <2515.1364917546@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