pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Do cast affects index usage?
5+ messages / 3 participants
[nested] [flat]

* Do cast affects index usage?
@ 2012-10-12 20:05 Anibal David Acosta <aa@devshock.com>
  2012-10-12 20:37 ` Re: Do cast affects index usage? Scott Marlowe <scott.marlowe@gmail.com>
  2012-10-12 20:38 ` Re: Do cast affects index usage? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 5+ messages in thread

From: Anibal David Acosta @ 2012-10-12 20:05 UTC (permalink / raw)
  To: pgsql-performance

I have a table with a column of type timestamp with time zone, this column
has an index

 

If I do a select like this

 

select * from mytable where cast(my_date as timestamp without time zone) >
'2012-10-12 20:00:00'

 

this query will use the index over the my_date column?

 

Thanks

 

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

* Re: Do cast affects index usage?
  2012-10-12 20:05 Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
@ 2012-10-12 20:37 ` Scott Marlowe <scott.marlowe@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Scott Marlowe @ 2012-10-12 20:37 UTC (permalink / raw)
  To: Anibal David Acosta <aa@devshock.com>; +Cc: pgsql-performance

On Fri, Oct 12, 2012 at 2:05 PM, Anibal David Acosta <aa@devshock.com> wrote:
> I have a table with a column of type timestamp with time zone, this column
> has an index
>
> If I do a select like this
>
> select * from mytable where cast(my_date as timestamp without time zone) >
> '2012-10-12 20:00:00'
>
> this query will use the index over the my_date column?

No.  but it will use a functional index:

create index yada on blah (cast(my_date as timestaqmp without time zone));




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

* Re: Do cast affects index usage?
  2012-10-12 20:05 Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
@ 2012-10-12 20:38 ` Tom Lane <tgl@sss.pgh.pa.us>
  2012-10-13 00:27   ` Re: Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2012-10-12 20:38 UTC (permalink / raw)
  To: Anibal David Acosta <aa@devshock.com>; +Cc: pgsql-performance

"Anibal David Acosta" <aa@devshock.com> writes:
> I have a table with a column of type timestamp with time zone, this column
> has an index

> If I do a select like this
> select * from mytable where cast(my_date as timestamp without time zone) >
> '2012-10-12 20:00:00'
> this query will use the index over the my_date column?

No.  The cast seems rather pointless though ...

			regards, tom lane




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

* Re: Do cast affects index usage?
  2012-10-12 20:05 Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
  2012-10-12 20:38 ` Re: Do cast affects index usage? Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-10-13 00:27   ` Anibal David Acosta <aa@devshock.com>
  2012-10-13 01:34     ` Re: Do cast affects index usage? Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Anibal David Acosta @ 2012-10-13 00:27 UTC (permalink / raw)
  To: 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-performance

Because I need to get all rows where datetime is greater than (for example)
'2012-10-10 00:00:00' but ignoring timezone, so basically I need to truncate
timezone
This can be done by converting to timestamp without timezone.



-----Mensaje original-----
De: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Enviado el: viernes, 12 de octubre de 2012 05:39 p.m.
Para: Anibal David Acosta
CC: pgsql-performance@postgresql.org
Asunto: Re: [PERFORM] Do cast affects index usage?

"Anibal David Acosta" <aa@devshock.com> writes:
> I have a table with a column of type timestamp with time zone, this 
> column has an index

> If I do a select like this
> select * from mytable where cast(my_date as timestamp without time 
> zone) >
> '2012-10-12 20:00:00'
> this query will use the index over the my_date column?

No.  The cast seems rather pointless though ...

			regards, tom lane





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

* Re: Do cast affects index usage?
  2012-10-12 20:05 Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
  2012-10-12 20:38 ` Re: Do cast affects index usage? Tom Lane <tgl@sss.pgh.pa.us>
  2012-10-13 00:27   ` Re: Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
@ 2012-10-13 01:34     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2012-10-13 01:34 UTC (permalink / raw)
  To: Anibal David Acosta <aa@devshock.com>; +Cc: pgsql-performance

"Anibal David Acosta" <aa@devshock.com> writes:
> Because I need to get all rows where datetime is greater than (for example)
> '2012-10-10 00:00:00' but ignoring timezone, so basically I need to truncate
> timezone
> This can be done by converting to timestamp without timezone.

[ shrug... ]  It can also be done without that.  Whatever your cutoff
time is can be expressed as a timestamp *with* tz.

			regards, tom lane




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


end of thread, other threads:[~2012-10-13 01:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-10-12 20:05 Do cast affects index usage? Anibal David Acosta <aa@devshock.com>
2012-10-12 20:37 ` Scott Marlowe <scott.marlowe@gmail.com>
2012-10-12 20:38 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-10-13 00:27   ` Anibal David Acosta <aa@devshock.com>
2012-10-13 01:34     ` 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