pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: secret <secret@kearneydev.com>
To: PG-SQL <pgsql-sql@postgresql.org>
To: John Ridout <johnridout@ctasystems.co.uk>
Subject: Good Optimization
Date: Wed, 07 Jul 1999 10:56:26 -0400
Message-ID: <37836A99.6989795E@kearneydev.com> (raw)


    There is a simple way to optimize SQL queries involving joins to
PostgreSQL that I think should be handled by Postgre?  If one is joining
a tables a,b on attribute "x" and if one has something like x=3 then it
helps A LOT to say: a.x=3 and b.x=3 in addition to saying a.x=b.x ...
The example below shoulds the radical speed gain of doing this, and I
think it isn't something real obvious to most people...

    Of course it could just be a common thing to do in SQL, anyway, just
thought I'd let you all know what I discovered.



Here is an example:

ftc=> explain select * from po,tickets where po_id=material_po and
po_id=8888 ;
NOTICE:  QUERY PLAN:

Nested Loop  (cost=401.34 size=6146 width=158)
  ->  Index Scan using ipo_po_id_units on po  (cost=2.05 size=2
width=94)
  ->  Index Scan using itickets_mpou on tickets  (cost=199.64 size=70650
width=6
4)

EXPLAIN
ftc=>

ftc=> explain select * from po,tickets where po_id=material_po and
po_id=8888 an
d material_po=8888;
NOTICE:  QUERY PLAN:

Nested Loop  (cost=21.42 size=268 width=158)
  ->  Index Scan using ipo_po_id_units on po  (cost=2.05 size=2
width=94)
  ->  Index Scan using itickets_material_po on tickets  (cost=9.68
size=3073 wid
th=64)

EXPLAIN
ftc=>




view thread (27+ messages)  latest in thread

Message-ID: <37836A99.6989795E@kearneydev.com>
Permalink:  ../37836A99.6989795E@kearneydev.com/
Also on:    postgresql.org/message-id/37836A99.6989795E@kearneydev.com

 · 

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-sql@postgresql.org
  Cc: secret@kearneydev.com, johnridout@ctasystems.co.uk
  Subject: Re: Good Optimization
  In-Reply-To: <37836A99.6989795E@kearneydev.com>
  References: <37836A99.6989795E@kearneydev.com>

* 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