dbTalk Databases Forums  

Index on timestamp with timezone AT LOCAL

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Index on timestamp with timezone AT LOCAL in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Björn Wächter
 
Posts: n/a

Default Index on timestamp with timezone AT LOCAL - 11-05-2009 , 02:51 PM






Hi all,

I have a table with a time stamp with timezone column:


CREATE TABLE TEST_TZ
(
DATE_TIME_TZ TIMESTAMP(3)
);


CREATE INDEX IDX_DATE_TIME_TZ ON TEST_TZ
(DATE_TIME_TZ);


I want to use a view to get the time stamp column at the timezone
of the session:


CREATE OR REPLACE FORCE VIEW VI_TEST_TZ
(DATE_TIME_LOCAL)
AS
SELECT
DATE_TIME_TZ AT LOCAL DATE_TIME_LOCAL
FROM
TEST_TZ;


But the problem is that queries using the time stamp column as a filter
like this:


SELECT
DATE_TIME_LOCAL
FROM VI_TEST_TZ
WHERE
DATE_TIME_LOCAL = :T;


are not using the index on the column. I tried to force the index usage
but with no success. I also tried to use the AT LOCAL in a function
based index:


CREATE INDEX SCOTT.IDX_TEST ON SCOTT.TEST_TZ
(SYS_EXTRACT_UTC(DATE_TIME_TZ AT LOCAL))
LOGGING
NOPARALLEL;


but than i get an ORA-01743 only pure functions can be indexed.
Anyone an idea how i can solve the problem? I don't want to use
different columns in the selected columns and in the where statement.
I have to keep downward compatibility.

Thanks Björn

Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Index on timestamp with timezone AT LOCAL - 11-06-2009 , 09:12 AM






On Nov 5, 3:51*pm, Björn Wächter <Bjoern.Waechter (AT) _NOSPAM_web (DOT) de>
wrote:
Quote:
Hi all,

I have a table with a time stamp with timezone column:

CREATE TABLE TEST_TZ
(
* DATE_TIME_TZ *TIMESTAMP(3)
);

CREATE INDEX IDX_DATE_TIME_TZ ON TEST_TZ
(DATE_TIME_TZ);

I want to use a view to get the time stamp column at the timezone
of the session:

CREATE OR REPLACE FORCE VIEW VI_TEST_TZ
(DATE_TIME_LOCAL)
AS
SELECT
DATE_TIME_TZ AT LOCAL * * * * DATE_TIME_LOCAL
FROM
TEST_TZ;

But the problem is that queries using the time stamp column as a filter
like this:

SELECT
DATE_TIME_LOCAL
FROM VI_TEST_TZ
WHERE
DATE_TIME_LOCAL = :T;

are not using the index on the column. I tried to force the index usage
but with no success. I also tried to use the AT LOCAL in a function
based index:

CREATE INDEX SCOTT.IDX_TEST ON SCOTT.TEST_TZ
(SYS_EXTRACT_UTC(DATE_TIME_TZ AT LOCAL))
LOGGING
NOPARALLEL;

but than i get an ORA-01743 only pure functions can be indexed.
Anyone an idea how i can solve the problem? I don't want to use
different columns in the selected columns and in the where statement.
I have to keep downward compatibility.

Thanks Björn

What full version of Oracle?
What data type is bind variable :T ?
Did you generate statistics on the Table and Index?

If :T is not declared as a timestamp what happens if you change the
query to the form:

where date_time_local = to_timestamp(:T)


Also there is mention of Time Zone in the post but the Timestamp data
type does not include the time zone. Should you be using one of the
Timestamp data types that does?

From Concepts Manual chapter on native data types
Datatype Time
Zone Fractional Seconds
DATE
No No
TIMESTAMP
No Yes
TIMESTAMP WITH TIME ZONE Explicit Yes
TIMESTAMP WITH LOCAL TIME ZONE Relative Yes


HTH -- Mark D Powell --

Reply With Quote
  #3  
Old   
Robert Klemme
 
Posts: n/a

Default Re: Index on timestamp with timezone AT LOCAL - 11-06-2009 , 03:39 PM



On 11/06/2009 04:12 PM, Mark D Powell wrote:
Quote:
On Nov 5, 3:51 pm, Björn Wächter <Bjoern.Waechter (AT) _NOSPAM_web (DOT) de
wrote:
Hi all,

I have a table with a time stamp with timezone column:

CREATE TABLE TEST_TZ
(
DATE_TIME_TZ TIMESTAMP(3)
);

CREATE INDEX IDX_DATE_TIME_TZ ON TEST_TZ
(DATE_TIME_TZ);

I want to use a view to get the time stamp column at the timezone
of the session:

CREATE OR REPLACE FORCE VIEW VI_TEST_TZ
(DATE_TIME_LOCAL)
AS
SELECT
DATE_TIME_TZ AT LOCAL DATE_TIME_LOCAL
FROM
TEST_TZ;

But the problem is that queries using the time stamp column as a filter
like this:

SELECT
DATE_TIME_LOCAL
FROM VI_TEST_TZ
WHERE
DATE_TIME_LOCAL = :T;

are not using the index on the column. I tried to force the index usage
but with no success. I also tried to use the AT LOCAL in a function
based index:

CREATE INDEX SCOTT.IDX_TEST ON SCOTT.TEST_TZ
(SYS_EXTRACT_UTC(DATE_TIME_TZ AT LOCAL))
LOGGING
NOPARALLEL;

but than i get an ORA-01743 only pure functions can be indexed.
Anyone an idea how i can solve the problem? I don't want to use
different columns in the selected columns and in the where statement.
I have to keep downward compatibility.

Thanks Björn


What full version of Oracle?
What data type is bind variable :T ?
Did you generate statistics on the Table and Index?

If :T is not declared as a timestamp what happens if you change the
query to the form:

where date_time_local = to_timestamp(:T)


Also there is mention of Time Zone in the post but the Timestamp data
type does not include the time zone. Should you be using one of the
Timestamp data types that does?

From Concepts Manual chapter on native data types
Datatype Time
Zone Fractional Seconds
DATE
No No
TIMESTAMP
No Yes
TIMESTAMP WITH TIME ZONE Explicit Yes
TIMESTAMP WITH LOCAL TIME ZONE Relative Yes
It seems TIMESTAMP WITH LOCAL TIME ZONE seems the most appropriate type
if the query is to show timestamps in session timezone most of the time.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.