pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jim 'Decibel!' Nasby <jnasby@cashnetusa.com>
Cc: Richard Huxton <dev@archonet.com>
Cc: postgresql performance list <pgsql-performance@postgresql.org>
Subject: Re: Oddity with view (now with test case)
Date: Mon, 10 Nov 2008 14:31:39 -0500
Message-ID: <12776.1226345499@sss.pgh.pa.us> (raw)
In-Reply-To: <1E5A4D7D-3B95-440B-A377-B6B9F8768F7A@cashnetusa.com>
References: <3CF0CFC1-FDBA-4A61-ACAA-6AF556C4C6F4@cashnetusa.com>
	<3128.1226322412@sss.pgh.pa.us>
	<7B598355-07C0-450A-9914-B5979F48A5B3@cashnetusa.com>
	<49187BA7.8020403@archonet.com>
	<1E5A4D7D-3B95-440B-A377-B6B9F8768F7A@cashnetusa.com>

"Jim 'Decibel!' Nasby" <jnasby@cashnetusa.com> writes:
> Here's the commands to generate the test case:

> create table a(a int, b text default 'test text');
> create table c(c_id serial primary key, c_text text);
> insert into c(c_text) values('a'),('b'),('c');
> create table b(a int, c_id int references c(c_id));
> create view v as select a, b, null as c_id, null as c_text from a  
> union all select a, null, b.c_id, c_text from b join c on (b.c_id=  
> c.c_id);
> \timing
> insert into a(a) select generate_series(1,9999999);
> select count(*) from a;
> select count(*) from v;
> explain analyze select count(*) from a;
> explain analyze select count(*) from v;

I think what you're looking at is projection overhead and per-plan-node
overhead (the EXPLAIN ANALYZE in itself contributes quite a lot of the
latter).  One thing you could do is be more careful about making the
union input types match up so that no subquery scan nodes are required:

create view v2 as select a, b, null::int as c_id, null::text as c_text from a                                                                      
union all select a, null::text, b.c_id, c_text from b join c on (b.c_id=c.c_id); 

On my machine this runs about twice as fast as the original view.

			regards, tom lane



view thread (8+ messages)  latest in thread

Message-ID: <12776.1226345499@sss.pgh.pa.us>
Permalink:  ../12776.1226345499@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/12776.1226345499@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, jnasby@cashnetusa.com, dev@archonet.com
  Subject: Re: Oddity with view (now with test case)
  In-Reply-To: <12776.1226345499@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