• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 728
  • Last Modified:

Table and Index in the same tablespace. Performance issue?

Hi All,

I have a column in a table which is being populated by a sequence. And I have an index on this column. Both the table and the index are located in the same tablespace.  I am noticing multiple blocking sessions which exist for a very breif period. The wait event is TX : row lock contention. Is is correct to assume that the index is sequntial as the colum is being populated by a sequence? Because of this reason, would both table and the index element be sharing the same block? As I am doing multiple DMLs on this table, is this resulting in the TX : row lock contention?

Would it help creating the index in a different tablespace for columns populated with a sequence? or, would it be better if I created a reverse key index on this column?

Any input regarding this is greatly appreciated. My database is on 10.2.0.4 , (SunOS wust4019 5.10 Generic_142900-13 sun4u sparc SUNW,Sun-Fire)

Thank you,
0
GP7
Asked:
GP7
3 Solutions
 
sdstuberCommented:
you've sort of combined 3 questions into one

yes/no - your index will be sequential (ordered) but not because the column is populated by an index, but rather because indexes are always sorted

no,  a table and an index won't share the same block,  every segment (table/index/lob/etc) is allocated in blocks and those blocks aren't shared

nor will having them in the same tablespace cause row lock contention
0
 
AkenathonCommented:
You have made so many questions that it's not easy where to start, I'll try to put some order:

- A table and each of its indexes have entirely separated segments, so there's no way they share ANY block whatsoever
- There is no such thing as a "sequential" index. Oracle uses BALANCED trees for index structures, so it's always a tree, and it's always balanced (i.e. all leaves are at the same level)
- The row lock contention only happens because more than one session is trying to write to THE SAME TABLE ROW. The exact same thing would happen if the index didn't exist, and the lock will only be released when the locking transaction ends (typically commits or rolls back). It's also unrelated to the fact that the index keys come from a sequence, the only thing which matters is that you are trying to write to the same row(s) at the same time
- You *could* separate the index segment to another tablespace, but for that to give you any difference, the corresponding datafiles would have to reside in separate physical disks or volume groups etc. With the many caches and RAIDs you have these days, I would recommend that you don't go that way... you'll hardly notice the difference on most cases, plus you can certainly make matters worse if you start herding some segments to some particular storage
- The reverse key index is nice for avoiding hot index blocks (if you have many inserts, or if "most" activity occurs in the "new" end of the index, this could well be your case). However, it is terrible for range scans, so doublecheck that you only do index lookups for exact key matches, and that you will never want anything other than that. Again, this has no relation to locking issues

As a general advice, don't embark into a tuning excercise if your users don't see any problem at present or in the near future. If you do, benchmark and trace whatever they accuse of "being slow" and try to understand what's taking the DBMS so long.
0
 
Geert GruwezOracle dbaCommented:
a sequence ...

are you talking about a oracle sequence ?
or something using a trigger like this:

insert into table_x (b, c, d) values (2, 3, 4);

> a insert trigger on table_x is used to fill column a with a sequence

trigger content
 
CREATE TRIGGER ins_table_x
BEFORE INSERT ON table_x
FOR EACH ROW
DECLARE 
  aa NUMBER;  
BEGIN
  IF :new.a=0 or :new.a IS NULL THEN
    UPDATE SEQUENCES SET SEQUENCE = NVL(SEQUENCE, 0)+1 WHERE TABLE_NAME = 'table_x';
    SELECT SEQUENCE INTO aa FROM SEQUENCES WHERE TABLE_NAME = 'table_x';
    :new.a := aa;
  END IF;
END;
/

Open in new window


using a trigger like this can cause row lock contention
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Franck PachotCommented:
Hi,

So you have sessions waiting for 'enq: TX - row lock contention'
This is not a lock at block level or you would have 'TX - allocate ITL entry'
Now try to find the lock mode. If you got the event from v$session, then check P1 column:
If P1=1415053316 (hexadecimal 54580004) it is a mode 4 lock
If P1=1415053318 (hexadecimal 54580006) it is a mode 6 lock

Mode 6 lock is contention on table row
Mode 4 lock is probably contention on unique index entry

Nothing to do with blocks, nor tablespaces, nor sequences (if you insert from a sequence, you cannot have a contention as you cannot have same number for 2 sessions).
In v$session, you also have information to identify the row it is waiting on.

Regards,
Franck.
0
 
GP7Author Commented:
Thank you all for your input.

@frackpachot - It is a mode 6 lock.

The app team has been informed about this and they are making some code changes to avoid these blocking sessions.

I appreciate your time and your comments. Thank you.
0
 
GP7Author Commented:
Thank you all...
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now