pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPartial index and query plan
5+ messages / 3 participants
[nested] [flat]
* Partial index and query plan
@ 2007-08-22 12:57 Aleksandr Vinokurov <aleksandr.vin@gmail.com>
0 siblings, 2 replies; 5+ messages in thread
From: Aleksandr Vinokurov @ 2007-08-22 12:57 UTC (permalink / raw)
To: 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_HIS unique (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?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Partial index and query plan
@ 2007-08-22 14:10 Tom Lane <tgl@sss.pgh.pa.us>
parent: Aleksandr Vinokurov <aleksandr.vin@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2007-08-22 14:10 UTC (permalink / raw)
To: Aleksandr Vinokurov <aleksandr.vin@gmail.com>; +Cc: pgsql-sql
"Aleksandr Vinokurov" <aleksandr.vin@gmail.com> writes:
> The question is why "explain analyze" shows a 'Filter: ("action" <> 0)' in plan:
Use a newer Postgres release (8.1 or later).
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Partial index and query plan
@ 2007-08-22 14:32 Aleksandr Vinokurov <aleksandr.vin@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Aleksandr Vinokurov @ 2007-08-22 14:32 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Thank you Tom,
but does it means that this is only an explain's problem or the plan
is actually such a hard, and postmaster actually checks each record
found by the index with this "filter"?
I'm using 8.0.1 version, but upgrading can become a work with expense.
On 22/08/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Aleksandr Vinokurov" <aleksandr.vin@gmail.com> writes:
> > The question is why "explain analyze" shows a 'Filter: ("action" <> 0)' in plan:
>
> Use a newer Postgres release (8.1 or later).
>
> regards, tom lane
>
With best wishes, Aleksandr.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Partial index and query plan
@ 2007-08-22 14:43 Scott Marlowe <scott.marlowe@gmail.com>
parent: Aleksandr Vinokurov <aleksandr.vin@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Scott Marlowe @ 2007-08-22 14:43 UTC (permalink / raw)
To: Aleksandr Vinokurov <aleksandr.vin@gmail.com>; +Cc: pgsql-sql
On 8/22/07, Aleksandr Vinokurov <aleksandr.vin@gmail.com> wrote:
>
> 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_HIS unique (date)
> );
>
> 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)
I don't see the issue here. The index being used is the same partial
index you created. Maybe it's just a question of semantics?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Partial index and query plan
@ 2007-08-22 15:02 Aleksandr Vinokurov <aleksandr.vin@gmail.com>
parent: Scott Marlowe <scott.marlowe@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Aleksandr Vinokurov @ 2007-08-22 15:02 UTC (permalink / raw)
To: Scott Marlowe <scott.marlowe@gmail.com>; +Cc: pgsql-sql
Scott Marlowe wrote:
>
> I don't see the issue here. The index being used is the same partial
> index you created. Maybe it's just a question of semantics?
>
As I understand final filter is:
a) pointed at the index creation
b) is redundant as all the indexed records have action <> 0.
So checking of it is a time wasting.
And the plan should be this:
>> 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))
I suggest that this 'Filter' check will not be noticed as it always
return TRUE, and so will be checked only once, -- because of the
"limit 1". :)
But thanks, Aleksandr.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2007-08-22 15:02 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-22 12:57 Partial index and query plan Aleksandr Vinokurov <aleksandr.vin@gmail.com>
2007-08-22 14:10 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-08-22 14:32 ` Aleksandr Vinokurov <aleksandr.vin@gmail.com>
2007-08-22 14:43 ` Scott Marlowe <scott.marlowe@gmail.com>
2007-08-22 15:02 ` Aleksandr Vinokurov <aleksandr.vin@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox