pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pierre C <lists@peufeu.com>
To: pgsql-performance@postgresql.org, pasman pasmaƄski <pasman.p@gmail.com>
Subject: Re: Optimizing query
Date: Fri, 26 Nov 2010 10:46:11 +0100
Message-ID: <op.vmruq9jseorkce@apollo13> (raw)
In-Reply-To: <AANLkTimMagbDUWi+UwW=7sspj08gOZxfsGc_EK1ovhfG@mail.gmail.com>
References: <AANLkTimMagbDUWi+UwW=7sspj08gOZxfsGc_EK1ovhfG@mail.gmail.com>



Note that your LEFT JOIN condition is probably quite slow...

Please post EXPLAIN ANALYZE for this simplified version :

SELECT
	R."Osoba weryfikuj?ca",
	R."LP",
	A."NKA",
	A."NTA",
	Sum("Ile")
FROM		"NumeryA" A
LEFT JOIN	"Rejestr stacji do naprawy" R ON (
	    A."NKA" = R."Numer kierunkowy"
	and A."NTA" like R."Numer stacji"
	and substr(A."NTA",1,5) = substr(R."Numer stacji",1,5)
)
WHERE
	    A."DataPliku" >= current_date-4*30
	and A."KodB??du"=74::text
	and R."Data weryfikacji" >= current_date-4*30
GROUP BY R."Osoba weryfikuj?ca",R."LP",A."NKA", A."NTA"
ORDER BY Sum("Ile") DESC
LIMIT 5000

And also post EXPLAIN ANALYZE for this :

SELECT
	A."NKA",
	A."NTA",
	Sum("Ile") AS ss -- if it's in this table
FROM		"NumeryA" A
WHERE
	    A."DataPliku" >= current_date-4*30
	and A."KodB??du"=74::text
GROUP BY A."NKA", A."NTA"



view thread (11+ messages)  latest in thread

Message-ID: <op.vmruq9jseorkce@apollo13>
Permalink:  ../op.vmruq9jseorkce@apollo13/
Also on:    postgresql.org/message-id/op.vmruq9jseorkce@apollo13

 · 

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: lists@peufeu.com, pasman.p@gmail.com
  Subject: Re: Optimizing query
  In-Reply-To: <op.vmruq9jseorkce@apollo13>

* 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