pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Why Index is not working on date columns.
4+ messages / 2 participants
[nested] [flat]

* Why Index is not working on date columns.
@ 2005-10-25 08:47 Kishore B <kishorebh@gmail.com>
  2005-10-25 13:38 ` Re: Why Index is not working on date columns. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Kishore B @ 2005-10-25 08:47 UTC (permalink / raw)
  To: 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.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why Index is not working on date columns.
  2005-10-25 08:47 Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
@ 2005-10-25 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
  2005-10-25 15:04   ` Re: Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2005-10-25 13:38 UTC (permalink / raw)
  To: Kishore B <kishorebh@gmail.com>; +Cc: pgsql-performance

Kishore B <kishorebh@gmail.com> writes:
>  Can you guys please take a look at the following query and let me know why
> the index is not considered in the plan?

"Considered" and "used" are two different things.

The two examples you give have the same estimated cost (within two
decimal places) so the planner sees no particular reason to choose one
over the other.

I surmise that you are testing on toy tables and extrapolating to what
will happen on larger tables.  This is an unjustified assumption.
Create a realistic test data set, ANALYZE it, and then see if the
planner chooses indexes you like.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why Index is not working on date columns.
  2005-10-25 08:47 Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
  2005-10-25 13:38 ` Re: Why Index is not working on date columns. Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-10-25 15:04   ` Kishore B <kishorebh@gmail.com>
  2005-10-25 18:01     ` Re: Why Index is not working on date columns. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Kishore B @ 2005-10-25 15:04 UTC (permalink / raw)
  To: pgsql-performance

Hi Tom,
 Thank you for your response.

> I surmise that you are testing on toy tables and extrapolating to what
> will happen on larger tables.
>
These tables participating here contain more than 8 million records as of
now, and on every day, 200K records, will add to them.
  Thank you,
Kishore.


 On 10/25/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Kishore B <kishorebh@gmail.com> writes:
> > Can you guys please take a look at the following query and let me know
> why
> > the index is not considered in the plan?
>
> "Considered" and "used" are two different things.
>
> The two examples you give have the same estimated cost (within two
> decimal places) so the planner sees no particular reason to choose one
> over the other.
>
> I surmise that you are testing on toy tables and extrapolating to what
> will happen on larger tables. This is an unjustified assumption.
> Create a realistic test data set, ANALYZE it, and then see if the
> planner chooses indexes you like.
>
> regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why Index is not working on date columns.
  2005-10-25 08:47 Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
  2005-10-25 13:38 ` Re: Why Index is not working on date columns. Tom Lane <tgl@sss.pgh.pa.us>
  2005-10-25 15:04   ` Re: Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
@ 2005-10-25 18:01     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2005-10-25 18:01 UTC (permalink / raw)
  To: Kishore B <kishorebh@gmail.com>; +Cc: pgsql-performance

Kishore B <kishorebh@gmail.com> writes:
>> I surmise that you are testing on toy tables and extrapolating to what
>> will happen on larger tables.
>> 
> These tables participating here contain more than 8 million records as of
> now, and on every day, 200K records, will add to them.

In that case, have you ANALYZEd the tables lately?  The planner's cost
estimates correspond to awfully small tables ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-10-25 18:01 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-25 08:47 Why Index is not working on date columns. Kishore B <kishorebh@gmail.com>
2005-10-25 13:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-10-25 15:04   ` Kishore B <kishorebh@gmail.com>
2005-10-25 18:01     ` Tom Lane <tgl@sss.pgh.pa.us>

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