pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Joel Reymont <joelr1@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: stored proc and inserting hundreds of thousands of rows
Date: Sat, 30 Apr 2011 13:24:12 -0500
Message-ID: <4DBC0D7C020000250003D09E@gw.wicourts.gov> (raw)
In-Reply-To: <4881277622113933088@unknownmsgid>
References: <D5DE36B9-17CF-4A55-9119-CDC0BDC4E48D@gmail.com>
	<4DBC004C020000250003D099@gw.wicourts.gov>
	<4881277622113933088@unknownmsgid>

[rearranging to correct for top-posting]
 
Joel Reymont <joelr1@gmail.com> wrote:
> Kevin Grittner <Kevin.Grittner@wicourts.gov> wrote:
>> Joel Reymont <joelr1@gmail.com> wrote:
>>
>>> We have 2 million documents now and linking an ad to all of them
>>> takes 5 minutes on my top-of-the-line SSD MacBook Pro.
>>
>> How long does it take to run just the SELECT part of the INSERT
>> by itself?
 
> Are you suggesting eliminating the physical linking and
> calculating matching documents on the fly?
 
I'm not suggesting anything other than it being a good idea to
determine where the time is being spent before trying to make it
faster.  You showed this as the apparent source of the five minute
delay:
 
  INSERT INTO doc_ads (doc_id, ad_id, distance)
  SELECT doc, (t).ad_id, (t).distance
  FROM (SELECT ads_within_distance(topics, threshold) AS t
       FROM docs
       WHERE id = doc) AS x;
 
What we don't know is how much of that time is due to writing to the
doc_ads table, and how much is due to reading the other tables.  We
can find that out by running this:
 
  SELECT doc, (t).ad_id, (t).distance
  FROM (SELECT ads_within_distance(topics, threshold) AS t
       FROM docs
       WHERE id = doc) AS x;
 
If this is where most of the time is, the next thing is to run it
with EXPLAIN ANALYZE, and post the output.  It's a whole different
set of things to try to tune if that part is fast and the INSERT
itself is slow.
 
Of course, be aware of caching effects when you time this.
 
-Kevin



view thread (14+ messages)  latest in thread

Message-ID: <4DBC0D7C020000250003D09E@gw.wicourts.gov>
Permalink:  ../4DBC0D7C020000250003D09E@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4DBC0D7C020000250003D09E@gw.wicourts.gov

 · 

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: Kevin.Grittner@wicourts.gov, joelr1@gmail.com
  Subject: Re: stored proc and inserting hundreds of thousands of rows
  In-Reply-To: <4DBC0D7C020000250003D09E@gw.wicourts.gov>
  References: <D5DE36B9-17CF-4A55-9119-CDC0BDC4E48D@gmail.com> <4DBC004C020000250003D099@gw.wicourts.gov> <4881277622113933088@unknownmsgid> <4DBC0D7C020000250003D09E@gw.wicourts.gov>

* 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