Re: how to make this database / query faster - Mailing list pgsql-general

From Richard Broersma
Subject Re: how to make this database / query faster
Date
Msg-id 396486430803160825n3aa8e462h2de15371e789b3a2@mail.gmail.com
Whole thread Raw
In response to Re: how to make this database / query faster  (brian <brian@zijn-digital.com>)
List pgsql-general
On Sat, Mar 15, 2008 at 5:04 PM, brian <brian@zijn-digital.com> wrote:
As there's an index on id would it be faster to transpose the WHERE
conditions?

WHERE id > your_last_id
AND session_key IS NOT NULL

I can't remember if the order of WHERE is significant.

I don't think that the order of WHERE clause conditions are significant with PostgreSQL since it has a sophisticated planner.  One way to be sure would be to examine the EXPLAIN plans for different where clause ordering to see if the query plan changes depending upon the order specified.

Another way to make this query faster would be to create a partial index on id;

CREATE UNIQUE INDEX Partial_id
        ON Users
 WHERE session_key IS NOT NULL;


This index would be much smaller if there are many session_keys that are null, so it should be loaded as searched much faster.

pgsql-general by date:

Previous
From: askel
Date:
Subject: on insert when ... do instead update
Next
From: "Martin Gainty"
Date:
Subject: Re: how to make this database / query faster