Partial index and query plan - Mailing list pgsql-sql

From Aleksandr Vinokurov
Subject Partial index and query plan
Date
Msg-id b048c51b0708220557g18cc9a6p7bf2ab195539c3bd@mail.gmail.com
Whole thread Raw
Responses Re: Partial index and query plan  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Partial index and query plan  ("Scott Marlowe" <scott.marlowe@gmail.com>)
List pgsql-sql
Hello all,

Imagine having this table:

create table user_history (  rec_id               SERIAL not null,  date                 TIMESTAMP            not null,
action               INT2                 not null,  uid                  INT4                 not null,  name
      CHAR(10)             null default NULL,  constraint PK_USER_HISTORY primary key (rec_id),  constraint
AK_DATE_USER_HISunique (date)
 
);

and this partial index:

create unique index indx_date_action12_uid_user_his
on user_history (date, uid)
where action <> 0;

and this query:

select date
from "user_history"
where date > '2007-08-18 14:33'
and date <= '2007-08-18 16:30'
and uid = 1388
and action <> 0
limit 1;


The question is why "explain analyze" shows a 'Filter: ("action" <> 0)' in plan:

Limit  (cost=0.00..3.05 rows=1 width=8) (actual time=4.798..4.798
rows=0 loops=1)  ->  Index Scan using indx_date_action12_uid_user_his on
user_history  (cost=0.00..6.10 rows=2 width=8) (actual
time=4.791..4.791 rows=0 loops=1)        Index Cond: ((date > '2007-08-18 14:33:40.60664'::timestamp
without time zone) AND (date <= '2007-08-18 16:30:00'::timestamp
without time zone) AND (uid = 138658))        Filter: ("action" <> 0)

when this is a "where" case of the index?


pgsql-sql by date:

Previous
From: roopa perumalraja
Date:
Subject: Re: Solution to retrieve first and last row for each minute
Next
From: "Christian Kindler"
Date:
Subject: Re: Solution to retrieve first and last row for each minute