Re: Possibly slow query - Mailing list pgsql-performance

From Manfred Koizar
Subject Re: Possibly slow query
Date
Msg-id j44sv0hjeg0539tqriuppfo7o4och2dslc@email.aon.at
Whole thread Raw
In response to Re: Possibly slow query  ("Peter Darley" <pdarley@kinesis-cem.com>)
Responses Re: Possibly slow query
List pgsql-performance
On Wed, 26 Jan 2005 07:16:25 -0800, "Peter Darley"
<pdarley@kinesis-cem.com> wrote:
>SELECT User_ID
>FROM Assignments A NATURAL LEFT JOIN (SELECT * FROM Assignment_Settings
>WHERE Setting='Status') ASet
>WHERE A.User_ID IS NOT NULL
>    AND ASet.Assignment_ID IS NULL
>GROUP BY User_ID;

"ASet.Assignment_ID IS NULL" and "value IS NULL" as you had in your
original post don't necessarily result in the same set of rows.

SELECT DISTINCT a.User_ID
  FROM Assignments a
       LEFT JOIN Assignment_Settings s
              ON (a.Assignment_ID=s.Assignment_ID
              AND s.Setting='Status')
 WHERE a.User_ID IS NOT NULL
   AND s.Value IS NULL;

Note how the join condition can contain subexpressions that only depend
on columns from one table.

BTW,
|neo=# \d assignment_settings
| [...]
| setting               | character varying(250) | not null
| [...]
|Indexes:
|    [...]
|    "assignment_settings_assignment_id_setting" unique, btree (assignment_id, setting)

storing the setting names in their own table and referencing them by id
might speed up some queries (and slow down others).  Certainly worth a
try ...

Servus
 Manfred

pgsql-performance by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Postgres server getting slow!!
Next
From: "N S"
Date:
Subject: Re: Postgres server getting slow!!