From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Adrian von Bidder <avbidder(at)fortytwo(dot)ch> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Optimizer: ranges and partial indices? Or use partitioning? |
Date: | 2010-03-01 16:04:46 |
Message-ID: | 17666.1267459486@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Adrian von Bidder <avbidder(at)fortytwo(dot)ch> writes:
> Given a (big [1]) table
> values ( ts timestamp, source integer, value float );
> [under what conditions] will the opitmizer be smart enough to make use of a
> partial index on "(source, ts) where ts > '2009-01-01'"? (Queries will have
> a date restriction but not necessarily the exact "> 2009-01-01".)
The planner is reasonably smart about deductions involving combinations
of btree-indexable operators. It will be able to prove the index is
usable if the query includes restrictions like
ts > '2009-01-02'
ts >= '2009-01-02'
ts = '2009-01-02'
where the comparison is to a constant that is >= the one in the index
predicate in the first case, or > the predicate in the others.
Whether it will think that using the index is a win is a different
question --- if the restriction is not reasonably selective it will
likely not want to use an index anyway.
> (A full index on source, ts is also built, but most queries are on values
> within the last year.)
If you have a full index on the same columns, I think that a partial
index like that is likely to be a complete waste. It's just replicating
a subtree of the full index, and saving you probably not more than one
level of btree descent, at the cost of double the index update work and a
lot more pressure on cache memory.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2010-03-01 16:21:20 | Re: Cannot remove prepared statement. |
Previous Message | Tom Lane | 2010-03-01 15:39:21 | Re: continuous copy/update one table to another |