473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to create a descending index on the primary key.

Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin
Jul 19 '05 #1
12 17344
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
.. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #2
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
.. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #3
Hi Farheem,

Thanks for the response. I tried with
ALTER SESSION set QUERY_REWRITE_ENABLED=TRUE;
but the explaun plan still picked up the primary key index. If I drop the
primary key constraint from the table, the it do full table scam but doesn't use
the index t1_pk.

Thanks,
Tuhin

fa*******@yahoo.com (FaheemRao) wrote in message news:<43**************************@posting.google. com>...
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

Jul 19 '05 #4
Hi Farheem,

Thanks for the response. I tried with
ALTER SESSION set QUERY_REWRITE_ENABLED=TRUE;
but the explaun plan still picked up the primary key index. If I drop the
primary key constraint from the table, the it do full table scam but doesn't use
the index t1_pk.

Thanks,
Tuhin

fa*******@yahoo.com (FaheemRao) wrote in message news:<43**************************@posting.google. com>...
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

Jul 19 '05 #5
Hi Faheem,

Thanks for the response.
I tried using ALTER SESSION set QUERY_REWRITE_ENABLED=TRUE; but still
the primary key index was picked up. When I dropped the primary key constraint
from the table, the explain plan showed doing the full table scan.

Thanks,
Tuhin

fa*******@yahoo.com (FaheemRao) wrote in message news:<43**************************@posting.google. com>...
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #6
Hi Faheem,

Thanks for the response.
I tried using ALTER SESSION set QUERY_REWRITE_ENABLED=TRUE; but still
the primary key index was picked up. When I dropped the primary key constraint
from the table, the explain plan showed doing the full table scan.

Thanks,
Tuhin

fa*******@yahoo.com (FaheemRao) wrote in message news:<43**************************@posting.google. com>...
Oracle treats desc indexes as function bases indexes .

First of all try to create a normal index (without desc) and see how
oracle responds. I ecatly dont know why oracle is throwing that error
. Check that table and index are in same schema .
Following is an alternae solution.
I guess you are trying to use desc indexes for query using

order by column_name desc

Optimizer uses function bases index only if you use exact function in
query.

you can create primary key with normal index and then create a desc
index and then set parameter query_rewrite_enabled = true in session
or system level and see explain plan to see if desc index is being
used or not.
There are good chances if you use order by column_name desc that
optimizer going to use desc index.

Faheem
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #7
Guys,
I was able on my 9R2 version to reproduce this ORA-01418 error. It
looks like Oracle doesn't "see" the index when creating the PK
constraint, if this index was created with the DESC option. I think
that a more meaningful error message in that scenario would be that
Oracle can't use a function-based index to enforce a PK constraint.
Note also that as far as I know, the parameter query-rewrite_enabled
applies to MV's, which are not in the picture in this case. The CBO
should use the DESC index if appropriate, no matter what the
query_rewrite_enabled parameter is set at (sorry, I don't have any
Oracle to test that at the moment). Could the OP please post the
query, create a DESC index, and then post the execution plan, and we
could start from there in trying to tune it.

Daniel
Jul 19 '05 #8
Guys,
I was able on my 9R2 version to reproduce this ORA-01418 error. It
looks like Oracle doesn't "see" the index when creating the PK
constraint, if this index was created with the DESC option. I think
that a more meaningful error message in that scenario would be that
Oracle can't use a function-based index to enforce a PK constraint.
Note also that as far as I know, the parameter query-rewrite_enabled
applies to MV's, which are not in the picture in this case. The CBO
should use the DESC index if appropriate, no matter what the
query_rewrite_enabled parameter is set at (sorry, I don't have any
Oracle to test that at the moment). Could the OP please post the
query, create a DESC index, and then post the execution plan, and we
could start from there in trying to tune it.

Daniel
Jul 19 '05 #9
Daniel,

Thats right query_rewrite_enabled= true is also concerned with
matrialized views , but it also affect optimizer to choose function
based index becuse when you create function based index orale
pre-calclate the value of that function and store in index. Now when
you use exactly same function in SQL optimizer uses that index, but it
has to be that excat same function.

Tuhin my guess is that you are using desc index becasuse you need to
get your sql results in desc order(let me know If I am wrong), for
that you have put

"order by column_name desc" in sql to make optimizer take advantage of
function-based index.

Now sometimes even after setting query_rewrite_enabled= true optimizer
does not use functiobased index.
There is a solution to that there is an other parameter the name of
which is not on top of my head. the default value of that paramet is
100 which means that optimizer think if it going to use function based
index coast going to be 100 which is not the case in real. you have to
set the value of that parameter less than 100.
I will do a search for you to find excat name of that parameter.


Faheem

da*************@hotmail.com (Daniel Roy) wrote in message news:<37************************@posting.google.co m>...
Guys,
I was able on my 9R2 version to reproduce this ORA-01418 error. It
looks like Oracle doesn't "see" the index when creating the PK
constraint, if this index was created with the DESC option. I think
that a more meaningful error message in that scenario would be that
Oracle can't use a function-based index to enforce a PK constraint.
Note also that as far as I know, the parameter query-rewrite_enabled
applies to MV's, which are not in the picture in this case. The CBO
should use the DESC index if appropriate, no matter what the
query_rewrite_enabled parameter is set at (sorry, I don't have any
Oracle to test that at the moment). Could the OP please post the
query, create a DESC index, and then post the execution plan, and we
could start from there in trying to tune it.

Daniel

Jul 19 '05 #10
Daniel,

Thats right query_rewrite_enabled= true is also concerned with
matrialized views , but it also affect optimizer to choose function
based index becuse when you create function based index orale
pre-calclate the value of that function and store in index. Now when
you use exactly same function in SQL optimizer uses that index, but it
has to be that excat same function.

Tuhin my guess is that you are using desc index becasuse you need to
get your sql results in desc order(let me know If I am wrong), for
that you have put

"order by column_name desc" in sql to make optimizer take advantage of
function-based index.

Now sometimes even after setting query_rewrite_enabled= true optimizer
does not use functiobased index.
There is a solution to that there is an other parameter the name of
which is not on top of my head. the default value of that paramet is
100 which means that optimizer think if it going to use function based
index coast going to be 100 which is not the case in real. you have to
set the value of that parameter less than 100.
I will do a search for you to find excat name of that parameter.


Faheem

da*************@hotmail.com (Daniel Roy) wrote in message news:<37************************@posting.google.co m>...
Guys,
I was able on my 9R2 version to reproduce this ORA-01418 error. It
looks like Oracle doesn't "see" the index when creating the PK
constraint, if this index was created with the DESC option. I think
that a more meaningful error message in that scenario would be that
Oracle can't use a function-based index to enforce a PK constraint.
Note also that as far as I know, the parameter query-rewrite_enabled
applies to MV's, which are not in the picture in this case. The CBO
should use the DESC index if appropriate, no matter what the
query_rewrite_enabled parameter is set at (sorry, I don't have any
Oracle to test that at the moment). Could the OP please post the
query, create a DESC index, and then post the execution plan, and we
could start from there in trying to tune it.

Daniel

Jul 19 '05 #11
Tuhin,

Here is the init parameter I was talking about
OPTIMIZER_INDEX_COST_ADJ
default value is 100 .

optimal value is different for every database.

you can find out the value by query this
select 100*(sum(decode(event,'db file sequential read',
average_wait,0))/
sum(decode(event,'db file scattered read', average_wait,0))) as
optimizer_index_cost_adj
from V$SYSTEM_EVENT
where event like 'db file s%';

VALUE is based on average wait time to perform an I/O , do not
measure its value immediately after db startup give it some time.
I used that in dataware house so I can tell you what mine valus was
mine was 1.
If it did not work with your calculated value put "1" for last resort.
If this parameter does not work then you might wanna consider playing
with parameter
DB_FILE_MULTIBLOCK_READ_COUNT.

I hope this help.
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #12
Tuhin,

Here is the init parameter I was talking about
OPTIMIZER_INDEX_COST_ADJ
default value is 100 .

optimal value is different for every database.

you can find out the value by query this
select 100*(sum(decode(event,'db file sequential read',
average_wait,0))/
sum(decode(event,'db file scattered read', average_wait,0))) as
optimizer_index_cost_adj
from V$SYSTEM_EVENT
where event like 'db file s%';

VALUE is based on average wait time to perform an I/O , do not
measure its value immediately after db startup give it some time.
I used that in dataware house so I can tell you what mine valus was
mine was 1.
If it did not work with your calculated value put "1" for last resort.
If this parameter does not work then you might wanna consider playing
with parameter
DB_FILE_MULTIBLOCK_READ_COUNT.

I hope this help.
Faheem

tk****@ipolicynet.com (Tuhin Kumar) wrote in message news:<e4**************************@posting.google. com>...
Hi,
Oracle give the error ORA-01418 when I try to do the
following;

Create unique index t1_pk on TABLE1(EntryId DESC) ;

If the I try to add primary key Contraint using the above index t1_pk
as below:
ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId)
USING INDEX t1_pk;

the following error comes "ORA-01418: specified index does not exist"
but the index t1_pk exists.

My requirement is to create a descending index on EntryId which gets
applied for all the queries.

Thanks
Tuhin

Jul 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: LaidBackWebSage | last post by:
Hi, All! I've got a very large table (149 fields -- I know, I didn't create it, and I'm working on changing it...) and I need to add an index to speed up a join query. However, when I run the...
7
by: Ross Hamilton | last post by:
I have a Report that creates a Catalogue of Products we sell under various Headings eg: Books, Recordings, Health Food, Diet Foods, etc There are 82 Headings and a total of 6000+ products...
2
by: Shirley | last post by:
We are running DB2 on iSeries V5R2. Using AQUA DATA STUDIO with a connection to our iSeries, I created a view using SQL and I am trying to create an index on this view using the code below. ...
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
3
by: Vayse | last post by:
I have a report which has several sub reports. Each sub report starts on its own page, and may be 2 or 3 pages long. I'd like to create an index on the first page of the main report. Something...
12
by: Aidan | last post by:
I have a form to create a new record for a training course. The form is based on one table that has 4 keys set to primary key. The first combo box on the form allows selection of the course POP...
0
by: hedonist123 | last post by:
Hi, I have a table with close to 30 lakh records. Now I wish to create an index on one of the columns. Earlier when I had tried to create an index on another column on the same table, the query...
2
by: Tuhin Kumar | last post by:
Hi, Oracle give the error ORA-01418 when I try to do the following; Create unique index t1_pk on TABLE1(EntryId DESC) ; If the I try to add primary key Contraint using the above index t1_pk...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.