Skip site navigation (1) Skip section navigation (2)

Why Index is not working on date columns.

From: Kishore B <kishorebh(at)gmail(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Why Index is not working on date columns.
Date: 2005-10-25 08:47:57
Message-ID: 42567e060510250147j582ce648p3ceef8e4376975be@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-performance
Hi All,
 Thank you very much for your help in configuring the database.
 Can you guys please take a look at the following query and let me know why
the index is not considered in the plan?
 Here is the extract of the condition string of the query that is taking the
transaction_date in index condition:
 *where (account.id <http://account.id> = search_engine.account_fk) and (
account.status = 't' and account.id <http://account.id> =
'40288a820726362f0107263c55d00003') and ( search_engine.id =
conversion.search_engine_fk and conversion.event_type ='daily_spend' and
conversion.tactic = 'PPC' and conversion.transaction_date between
'2005-01-01 00:00:00' and '2005-10-31 23:59:59') group by
account.id<http://account.id>
;
*
Plan:
*" -> Index Scan using conversion_all on "conversion"
(cost=0.00..6.02rows=1 width=98)"
" Index Cond: (((tactic)::text = 'PPC'::text) AND ((event_type)::text =
'daily_spend'::text) AND (transaction_date >= '2005-01-01
00:00:00'::timestamp without time zone) AND (transaction_date <= '2005-10-31
23:59:59'::timestamp without time zon (..)"
*
 Here is the extract of the condition string of the query that is not taking
the transaction_date in index condition:
**
where ( account.status = 't' and account.id <http://account.id> =
search_engine.account_fk and account.id <http://account.id> =
'40288a820726362f0107263c55d00003' ) and ( search_engine.id =
conversion.search_engine_fk and conversion.tactic = 'PPC' and
conversion.transaction_date >= '2005-01-01 00:00:00' and
conversion.transaction_date <= '2005-10-31 23:59:59' ) group by
account.id<http://account.id>
;
 *Plan:*
*" -> Index Scan using conv_evnt_tact_trans_date_sefk on "conversion" (cost=
0.00..6.02 rows=1 width=132)"
" Index Cond: ((("outer".id)::text = ("conversion".search_engine_fk)::text)
AND (("conversion".tactic)::text = 'PPC'::text))"
" Filter: ((transaction_date >= '2005-01-01 00:00:00'::timestamp without
time zone) AND (transaction_date <= '2005-10-31 23:59:59'::timestamp without
time zone))"
*
**
I have the following indexes defined on the columns.
*conv_evnt_tact_trans_date_sefk : (search_engine_fk, tactic, event_type,
transaction_date);*
*conv_all : (tactic, event_type, transaction_date);*
**
I am really confused when I saw this plan. In both queries, I am using the
same columns in the where condition, but the optimizer is taking different
indexes in these two cases.
Second, even though, I have the transaction_date column specified in the
second instance, why is it not taking the constraint as index condition?
 Thanks in advance.
 Thank you,
Kishore.

Responses

pgsql-performance by date

Next:From: Markus WollnyDate: 2005-10-25 09:47:57
Subject: Strange planner decision on quite simple select
Previous:From: Christian Paul B. CosinasDate: 2005-10-25 07:28:51
Subject: FW: Used Memory

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group