473,657 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17385
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_e nabled = 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****@ipolicyn et.com (Tuhin Kumar) wrote in message news:<e4******* *************** ****@posting.go ogle.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_e nabled = 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****@ipolicyn et.com (Tuhin Kumar) wrote in message news:<e4******* *************** ****@posting.go ogle.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_E NABLED=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.go ogle.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_e nabled = 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_E NABLED=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.go ogle.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_e nabled = 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_E NABLED=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.go ogle.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_e nabled = 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****@ipolicyn et.com (Tuhin Kumar) wrote in message news:<e4******* *************** ****@posting.go ogle.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_E NABLED=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.go ogle.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_e nabled = 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****@ipolicyn et.com (Tuhin Kumar) wrote in message news:<e4******* *************** ****@posting.go ogle.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_e nabled 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_e nabled 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_e nabled= 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_e nabled= 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.goog le.com>...
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_e nabled 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

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

Similar topics

0
369
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 "create index `index_name` on table(`column`)", MySQL uses every available connection to attempt the creation of the index, and does not allow the web site to access the database.
7
5588
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 which makes a big Catalogue. A Printed version of the Catalogue is done every 2 Months and we manually create an Index which takes HOURS, the problem is the Catalogue page numbers change depending on New or Deleted product ranges.
2
35122
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. CREATE INDEX reports.Ivendorname ON reports.transbyvendor05 (vendorname) However I get the following error:
2
5114
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 separate foreign keys to two other tables. I have read that it is always a good idea to create indexes on foreign keys. Should I create single indexes on each of these fields? Or is that not necessary since they are already part of a composite...
3
2430
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 like: Clients..............p1 Sales................p3 Salesmen.........p4
12
4522
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 code and this then fills details on 2 list boxs for course module code and description. The course section can then be selected from another combo box (filtered by the value in the first combo box) . Finally the course session name is entered...
0
1364
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 ran for more than 24 hours. I cannot afford to give that much down time. Could you tell me a way to create this index at a faster speed? Thanks,
2
326
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 as below: ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_PK PRIMARY KEY (EntryId) USING INDEX t1_pk;
6
4315
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 Alvin Leader
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.