Re: Expressional Indexes - Mailing list pgsql-sql

From Randolf Richardson, DevNet SysOp 29
Subject Re: Expressional Indexes
Date
Msg-id Xns943A725C1BA38rr8xca@200.46.204.72
Whole thread Raw
In response to Re: Expressional Indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
[sNip]
>> bearing in mind that this index can be used with queries that contain
>> WHERE conditions like "create_date >= some-date-constant".  The planner
>> must be able to convince itself that the right-hand side of the WHERE
>> condition is >= the cutoff in the index's predicate condition.  Since
>> the planner is not very bright, both items had better be simple DATE
>> constants, or it won't be able to figure it out ...
> 
> Note that if you're just doing this to speed up regular queries where
> you have create_date in some small range, then you'll likely not see
> much of an increase. Mainly you'll just save space.
       Saving space is not my objective for this particular problem, but of 
course it's definitely good news as I strive to optimize from every angle 
whenever possible.
       What I'm aiming for is to get an increase, no matter how small, 
because the volume is expected to be extremely heavy duty (unfortunately I 
can't discuss too many details of the project due to agreements I've made 
with others), so even if the end result seems insignificant from the 
perspective of a single query, the advantages become obvious when the 
queries are performed repeatedly simultaneously for wide variety of massive 
numbers of clients.

> What can be interesting is to create a partial index like this but over
> a second unrelated column. Something like:
> 
> CREATE INDEX my_dec_03_index on my_table (userid)
>  WHERE (create_date >= date '2003-11-02');
> 
> Then you can do queries like
> 
> SELECT * FROM my_table WHERE userid = ? AND create_date >= date
> '2003-11-02' 
> 
> And it'll be able to efficiently pull out just those records, even if
> there are thousands more records that are older than 2003-11-02.
       What a fascinating trick.  I could also use dummy data instead of 
"userid" (which has obvious functionality as implied by its name), or even 
data that the applications can even specify first because they'll be able 
to determine things on the client-side that will make index selection more 
appropriate.
       I haven't checked into this yet, but is there a way to specify which 
index PostgreSQL use as a parameter in a SELECT?

> This avoids having to create a two-column index with a low-selectivity
> column like "month".
       Thanks, both of you.  I've got some re-thinking to do for this project 
I'm working on (since it's a low priority project at the moment, I've got 
plenty of time to re-work the plan over and over again).

-- 
Randolf Richardson - rr@8x.ca
Inter-Corporate Computer & Network Services, Inc.
Vancouver, British Columbia, Canada
http://www.8x.ca/

This message originated from within a secure, reliable,
high-performance network ... a Novell NetWare network.



pgsql-sql by date:

Previous
From:
Date:
Subject: Re: How to quote date value?
Next
From: "nobody"
Date:
Subject: How to quote date value?