From: Toon van Doorn <tvdoorn@reto.nl>
To: pgsql-php@postgresql.org
Subject: Query takes much to long, is there a work around?
Date: Tue, 4 Oct 2005 13:55:16 +0200
Message-ID: <20051004115514.A9ECED941F@svr1.postgresql.org> (raw)
Hello all,
I made a mailing system where i log al the hits.
The query is dynamic, now there is this mailing with 16 links to log.
Here is the query to get out the data.
#########################
SELECT *,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='1012' AND linklog.adrescode=adreslog.alogid) as Homepage,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='1234' AND linklog.adrescode=adreslog.alogid) as Mickey,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='2345' AND linklog.adrescode=adreslog.alogid) as Winnie,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3010' AND linklog.adrescode=adreslog.alogid) as Kd,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3020' AND linklog.adrescode=adreslog.alogid) as Lleft,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3030' AND linklog.adrescode=adreslog.alogid) as Ergo,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3040' AND linklog.adrescode=adreslog.alogid) as Optic,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3050' AND linklog.adrescode=adreslog.alogid) as Mic,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3060' AND linklog.adrescode=adreslog.alogid) as Toets,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3070' AND linklog.adrescode=adreslog.alogid) as Kabel,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='3456' AND linklog.adrescode=adreslog.alogid) as Sponge,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='4567' AND linklog.adrescode=adreslog.alogid) as Cookie,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='5678' AND linklog.adrescode=adreslog.alogid) as Dora,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='6789' AND linklog.adrescode=adreslog.alogid) as Cool,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='7891' AND linklog.adrescode=adreslog.alogid) as Col,
(SELECT count(linkcode) FROM linklog WHERE linklog.mailcode='24120256' AND
linkcode='8912' AND linklog.adrescode=adreslog.alogid) as Headset
FROM adreslog WHERE mailcode='24120256'
3599 rows fetched (71,81 sec)
#######################
This way i get the information of the adres and how often they clicked on
wich link.
The explain on this query gives
51 rows fetched (0,19 sec)
Is there a faster way of selecting the hits on a link per adres?
Every hit is a record in the linklog table
CREATE TABLE "public"."linklog" (
"llogid" BIGSERIAL,
"mailcode" VARCHAR(15),
"linkcode" VARCHAR(15),
"adrescode" BIGINT,
"date" TIMESTAMP(6) WITHOUT TIME ZONE
) WITH OIDS;
This is the table with adresses
CREATE TABLE "public"."adreslog" (
"alogid" SERIAL,
"mailcode" VARCHAR(15),
"naam1" VARCHAR(255),
"naam2" VARCHAR(255),
"naam3" VARCHAR(255),
"adres" VARCHAR(70),
"firstread" TIMESTAMP(6) WITHOUT TIME ZONE,
"lastread" TIMESTAMP(6) WITHOUT TIME ZONE,
"totalread" INTEGER DEFAULT 0
) WITH OIDS;
Kind regards,
Toon van Doorn
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: tvdoorn@reto.nl
Subject: Re: Query takes much to long, is there a work around?
In-Reply-To: <20051004115514.A9ECED941F@svr1.postgresql.org>
References: <20051004115514.A9ECED941F@svr1.postgresql.org>
* 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