Re: Need another way to do this, my sql much to slow... - Mailing list pgsql-sql

From Christoph Haller
Subject Re: Need another way to do this, my sql much to slow...
Date
Msg-id 3FBCDFE5.9F3AEF69@rodos.fzk.de
Whole thread Raw
In response to Need another way to do this, my sql much to slow...  ("Jerry Wintrode" <wintrojr@tripos.com>)
List pgsql-sql
>
> I am attempting to write a spam management add-on for my corporate
> server, I have the database and the apps written but one part is WAY
to
> slow to be usefull.
>
> The following view:
>
>         Column         |  Type   | Modifiers
> -----------------------+---------+-----------
>  env_sender_num        | integer |
>  msg_from_claims_count | bigint  |
>
> is built on the follow table:
>
>      Column      |            Type             | Modifiers
> -----------------+-----------------------------+-----------
>  msg_sender_num  | integer                     |
>  env_sender_num  | integer                     |
>  msg_from_domain | character varying(255)      |
>  env_from_domain | character varying(255)      |
>  recorded_date   | timestamp without time zone |
> Indexes: record_of_claims_env_sender_num_idx btree (env_sender_num),
>          record_of_claims_msg_sender_num_idx btree (msg_sender_num)
>
> With the following SQL:
>
>
> SELECT record_of_claims.env_sender_num, count(DISTINCT
> record_of_claims.msg_sender_num)
>  AS msg_from_claims_count=20
>  FROM record_of_claims=20
>  GROUP BY record_of_claims.env_sender_num;
>
> A sample dataset follows:
>
[snip]
Not sure, if this can speed up things

SELECT env_sender_num, COUNT(msg_sender_num) AS msg_from_claims_count
FROM (
SELECT DISTINCT ON (msg_sender_num) msg_sender_num,env_sender_num
FROM record_of_claims ORDER BY msg_sender_num,env_sender_num DESC
) foo GROUP BY env_sender_num;

but possibly it inspires you or someone else for a better one.

Regards, Christoph




pgsql-sql by date:

Previous
From: "Jerry Wintrode"
Date:
Subject: Need another way to do this, my sql much to slow...
Next
From: "Jerry Wintrode"
Date:
Subject: Re: Need another way to do this, my sql much to slow...