Index problem : max lenght exceed

Posted on 2001-09-17
Last Modified: 2010-08-05

I'm working with Oracle 8.1, and I have a little problem.
I need to create an index (UNIQUE) on 10 columns. The problem is that 3 of this columns have are VARCHAR2 (255).

So each time I tried to create my table I have this error message : ORA-01450: maximum key length (758) exceeded.

I've tried to create the constrainte in Alter table instead in the create table... but it gives the same message.

And I cannot remove any field in the constraint... there's a way to do the job ?




ALTER TABLE InterventionPlans
    ADD CONSTRAINT UniqueInterventionPlans
    UNIQUE(AgencyId, ResponseTypeId, RecommendationId, Data1,
      Data2, Data3, AlarmLevel, FromWeekDay, FromTime, ToWeekDay, ToTime)
Question by:msl22

Accepted Solution

mathavra earned 50 total points
ID: 6488482
This primarily depends upon your DB_BLOCK_SIZE. I think your DB_BLOCK_SIZE is set to 2K. Here are the maximum key length associated with the DB_BLOCK_SIZE value. If possible change the BLOCK size and create the database again to acheive the higher value.

NOTE: You cannot change the DB_BLOCK_SIZE once the database has been created. To change it, you need to create the entire database again.

2K (2048)         758 Bytes
4K (4096)         1578 Bytes
8K (8192)         3218 Bytes
16K (16384)       6498 Bytes

From a Oracle document:

This is how is the max. number calculated?

The maximum key size means:

The total index length + length of the key (2 Bytes) + ROWID (6 Bytes) + the length of the rowid (1 byte).

The total index length is computed as the sum of the width of all indexed columns plus the number of indexed columns. Date fields have a length of 7, character fields have their defined length, and numeric fields have a length of 22. Numeric length = (precision/2) + 1. If negative, add +1. For Funtion-based indexes, we must calculate the length of the return type.

This index key size is limited by the value of db_block_size, because a key value may not span multiple blocks. In fact, it is required that any index block must contain at least TWO index entries per block.

Therefore, the maximum key length for an index will be less than half of the DB_BLOCK_SIZE. The Oracle 8i Administrator's Guide states that the maximum size of a single index entry is approximately one-half the data block size. However, when considering that we must also leave space in the blockaccording to PCTFREE, INITRANS, and space for block overhead (Block Header,ROW Directory, Table Directory, etc) the actual space that can be used for the Index key is actually just over 1/3 of the DB_BLOCK_SIZE.

Using default values for these storage options, the maximum length for indexes is as follows for different block sizes:

DB_BLOCK_SIZE: Maximum Index Key Length:
=============== =====================

2K (2048) 758 Bytes
4K (4096) 1578 Bytes
8K (8192) 3218 Bytes
16K (16384) 6498 Bytes

If you hit a maximum key length in an index according to the DB_BLOCK_SIZE, you may need to recreate the database with a larger block size. The otheralternative is to limit the size of the index. This is slightly more difficult with a Function-based index, when the return type is a varchar or RAW.

To limit the size of a function-based index you should consider using the SUBSTR or SUBSTRB function, to limit the number of Characters or Bytes returned. For more information on SUBTR and SUBSTRB, refer to the Oracle8i SQL Reference Guide.

Hope this helps!



Expert Comment

ID: 6505844
There might be something wrong in your design if you have that many columns in your key. You might want to use a system-generated sequence number instead and store the other columns as not null attributes. With that many columns, joins will be real messy.

Expert Comment

ID: 7045880
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.



** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
LVL 49

Expert Comment

ID: 7058522
Recommended disposition:

    Accept mathavra's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't Access My Database 57 84
constraint check 2 55
form builder not starting 3 70
How to find the cost of a stored procedure in Oracle and optimize it ?? 2 35
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question