pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dawid Kuroczko <qnex42@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Views, joins and LIMIT
Date: Mon, 11 Oct 2004 10:14:18 -0400
Message-ID: <4865.1097504058@sss.pgh.pa.us> (raw)
In-Reply-To: <758d5e7f04101102543eab8dca@mail.gmail.com>
References: <758d5e7f04101102543eab8dca@mail.gmail.com>

Dawid Kuroczko <qnex42@gmail.com> writes:
> This I guess would be quite benefitial for VIEWs. :)

Have you tried it?

regression-# SELECT entry_id,message FROM entries NATURAL JOIN messages ORDER BY entry_id DESC LIMIT 10;
                                             QUERY PLAN

-----------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..48.88 rows=10 width=36)
   ->  Nested Loop  (cost=0.00..4887.52 rows=1000 width=36)
         ->  Index Scan Backward using entries_pkey on entries  (cost=0.00..52.00 rows=1000 width=8)
         ->  Index Scan using messages_pkey on messages  (cost=0.00..4.82 rows=1 width=36)
               Index Cond: ("outer".message_id = messages.message_id)
(5 rows)

> Other thing that would be, I guess, benefitial for views would be
> special handling of lines like this:

> SELECT entry_id,message_id FROM entries NATURAL JOIN messages;

> Here there is no reason to perform JOIN at all -- the data will not be used.
> As above, since entries.message_id IS NOT NULL REFERENCES messages
> and messages is UNIQUE (PRIMARY KEY) we are sure there will be one-to-one(*)
> mapping between two tables.  And since these keys are not used, no need to
> waste time and perform JOIN.

The bang-for-the-buck ratio on that seems much too low.

			regards, tom lane



view thread (2+ messages)

Message-ID: <4865.1097504058@sss.pgh.pa.us>
Permalink:  ../4865.1097504058@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4865.1097504058@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, qnex42@gmail.com
  Subject: Re: Views, joins and LIMIT
  In-Reply-To: <4865.1097504058@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