Re: Expressional Indexes

From: "Randolf Richardson, DevNet SysOp 29" <rr(at)8x(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Expressional Indexes
Date: 2003-11-21 19:26:31
Message-ID: Xns943A725C1BA38rr8xca@200.46.204.72
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice 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(at)8x(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message radha.manohar 2003-11-21 20:46:28 Re: parse error in set statement
Previous Message Greg Stark 2003-11-21 19:03:16 Re: Expressional Indexes

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Barwick 2003-11-21 19:37:12 Re: Compare strings which resembles each other
Previous Message terry 2003-11-21 19:16:06 Re: How to quote date value?