Trouble to understand plain of postgresql

From: "Cristian Custodio" <crstian(at)terra(dot)com(dot)br>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Trouble to understand plain of postgresql
Date: 2003-06-07 13:06:38
Message-ID: 001601c32cf5$a3fef2b0$fb01a8c0@ttcristian
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I'm not be able to understand this plain:

Look this:

explain analyze
select ven.filcli, ven.codcli, rec.datven
from tt_ven ven, tt_rec rec
where ven.codfil = rec.codfil
and ven.sequen = rec.sequen
and rec.datven between to_timestamp('01/03/2003 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
and to_timestamp('03/03/2003 23:59:59', 'dd/mm/yyyy hh24:mi:ss')
and rec.flgest = 'A'

Nested Loop (cost=0.00..248.89 rows=1 width=67) (actual time=604.00..604.00 rows=0 loops=1)
-> Seq Scan on tt_rec rec (cost=0.00..242.86 rows=1 width=29) ...
Filter: (((datven)::timestamp with time zone >= to_timestamp('01/03/2003 00:00:00' ...
-> Index Scan using pk_ven on tt_ven ven (cost=0.00..6.01 rows=1 width=38) (never executed)
Index Cond: ((ven.codfil = "outer".codfil) AND (ven.sequen = "outer".sequen))
Total runtime: 606.00 msec

But if I change the function to_timestamp to to_date ...

explain analyze
select ven.filcli, ven.codcli, rec.datven
from tt_ven ven, tt_rec rec
where ven.codfil = rec.codfil
and ven.sequen = rec.sequen
and rec.datven between to_date('01/03/2003 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
and to_date('03/03/2003 23:59:59', 'dd/mm/yyyy hh24:mi:ss')
and rec.flgest = 'A'

Nested Loop (cost=0.00..12.03 rows=1 width=67) (actual time=114.00..114.00 rows=0 loops=1)
-> Index Scan using i_lc_rec_datven_flgest on tt_rec rec ...
Index Cond: ((datven >= '2003-03-01 00:00:00'::timestamp ...
-> Index Scan using pk_ven on tt_ven ven (cost=0.00..6.01 rows=1 width=38) (never executed)
Index Cond: ((ven.codfil = "outer".codfil) AND (ven.sequen = "outer".sequen))
Total runtime: 115.00 msec

Here it use INDEX SCAN i_lc_rec_datven_flgest

Why this happen?

Cristian

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2003-06-07 13:58:37 Re: Optimizer failure on integer column?
Previous Message Richard Huxton 2003-06-07 12:15:08 Re: Special characters in varchar/text fields