pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Bax <fbax@sympatico.ca>
To: pgsql-php@postgresql.org
Subject: Re: Query takes much to long, is there a work around?
Date: Tue, 04 Oct 2005 08:18:47 -0400
Message-ID: <5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca> (raw)
In-Reply-To: <20051004115514.A9ECED941F@svr1.postgresql.org>

At 07:55 AM 10/4/05, Toon van Doorn wrote:
>Is there a faster way of selecting the hits on a link per adres?


This type of question (slow query) is usually asked on pgsql-sql list, it 
has nothing to do with php.

You didn't mention indexes - surely you have indexes on your tables?

Check the output of "EXPLAIN ANALYSE" for one of your "select count ..." 
subqueries.

I think your query will benefit from a multi-column index on ( mailcode, 
linkcode, adrescode ), but 16 subselects and 51 rows in adreslog means over 
800 subqueries being executed - that's a lot of work to do!!

What happens if you change
SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='1012' AND linklog.adrescode=adreslog.alogid) as Homepage
to somthing like:
SELECT adrescode, mailcode, count(linkcode) FROM linklog WHERE 
mailcode='24120256' AND
linkcode='1012' as Homepage

then join to adreslog table.




view thread (3+ messages)  latest in thread

Message-ID: <5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca>
Permalink:  ../5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca/
Also on:    postgresql.org/message-id/5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca

 · 

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-php@postgresql.org
  Cc: fbax@sympatico.ca
  Subject: Re: Query takes much to long, is there a work around?
  In-Reply-To: <5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca>
  References: <20051004115514.A9ECED941F@svr1.postgresql.org> <5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca>

* 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