Re: how to make this database / query faster

From: "Martin Gainty" <mgainty(at)hotmail(dot)com>
To: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to make this database / query faster
Date: 2008-03-16 16:47:18
Message-ID: BLU136-DAV1A2A43F6C30D5EFC7429DAE040@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Richard-

My understanding is that Partial index is implemented for low cardinality scenarios ('Y'/'N') ('T'/'F') (null/not null) ?
http://en.wikipedia.org/wiki/Partial_index

Would it matter the selectivity is balanced?
thus 1 null record and 1 trillion null records would not apply

?
Martin-
----- Original Message -----
From: Richard Broersma
To: brian
Cc: pgsql-general(at)postgresql(dot)org
Sent: Sunday, March 16, 2008 10:25 AM
Subject: Re: [GENERAL] how to make this database / query faster

On Sat, Mar 15, 2008 at 5:04 PM, brian <brian(at)zijn-digital(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma 2008-03-16 17:16:13 Re: how to make this database / query faster
Previous Message Tom Lane 2008-03-16 16:43:29 Re: on insert when ... do instead update