pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mike G. <mike@thegodshalls.com>
To: pgsql-performance@postgresql.org
Subject: Which is more efficient?
Date: Fri, 17 Dec 2004 12:52:01 -0600
Message-ID: <20041217185201.GA13389@localhost.localdomain> (raw)

Hi,

I have data that I am taking from 2 tables, pulling out specific columns and inserting into one table.

Is it more efficient to do:
a)  insert into x
    select z from y;
    insert into x
    select z from a;

b)  insert into x
    select z from y
    union all
    select z from a;

I have run both through explain.
a) 650ms
b) 741.57ms

According to the planner option a, select z from y takes 545.93 ms
Under option b select z from y takes 553.34 ms

Shouldn't the time predicted for the select z from y be the same?

I would believe b would be more efficient as the inserts could be done in a batch rather than individual transactions but the planner doesn't recognize that.  When I run option a through the planner I have to highlight each insert separately since the planner stops executing after the first ; it comes across.

Mike



view thread (2+ messages)  latest in thread

Message-ID: <20041217185201.GA13389@localhost.localdomain>
Permalink:  ../20041217185201.GA13389@localhost.localdomain/
Also on:    postgresql.org/message-id/20041217185201.GA13389@localhost.localdomain

 · 

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: mike@thegodshalls.com
  Subject: Re: Which is more efficient?
  In-Reply-To: <20041217185201.GA13389@localhost.localdomain>

* 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