Re: Query takes much to long, is there a work around? - Mailing list pgsql-php

From Frank Bax
Subject Re: Query takes much to long, is there a work around?
Date
Msg-id 5.2.1.1.0.20051004080930.0584cba0@pop6.sympatico.ca
Whole thread Raw
In response to Query takes much to long, is there a work around?  ("Toon van Doorn" <tvdoorn@reto.nl>)
Responses Re: Query takes much to long, is there a work around?
List pgsql-php
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.


pgsql-php by date:

Previous
From: "Toon van Doorn"
Date:
Subject: Query takes much to long, is there a work around?
Next
From: "Toon van Doorn"
Date:
Subject: Re: Query takes much to long, is there a work around?