Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Spiros.

Asked: February 15, 2018 - 10:18 am UTC

Last updated: February 15, 2018 - 2:24 pm UTC

Version: Oracle 12C R2

Viewed 1000+ times

You Asked

Hi Tom,

We have a table with a non incremental composite key of (dialaog_id, insertion_date).

This creates problems since we have insertions in the middle of the leaves. Data has to be relocated.

We cannot use incremental keys since this creates problems when importing/exporting data from/to different DBs. (We would have collisions)

Is it a good idea to use a clustered key (different from the composite primary key) on insertion_date?

This would create a non-unique clustered index on insertion_date. Some DBs support this by adding a uniquifier.

Questions:
1) Does Oracle support this?
2) Would this solve our non incremental issue? Would the new non unique clustered index on insertion_date be incremental?
3) Is it recommended? I read that it will perform well on date range queries.

What do you propose?

and Chris said...

1. No, Oracle Database doesn't have clustered indexes. The closest we have is index-organized tables. But you can only do this using the primary key.

2. Do you have a problem? i.e. one you've measured in production? Or are you hypothesising?

3. If most/all of your queries search for a specific dialog_id and sometimes insertion_date ranges, such as:

select * from t where dialaog_id = :id;

select * from t where dialaog_id = :id and insertion_date > :start_date


Then, yes, creating an index-organized table of the form:

create table t (
  dialaog_id int, insertion_date date, ... other cols ...,
  primary key ( dialaog_id, insertion_date )
) organization index;


Could be a great idea. This guarantees that all the rows for a particular dialog_id are physically stored close to each-other. For a discussion of why, I recommend reading Martin Widlake's series on IOTs:

https://mwidlake.wordpress.com/2011/07/18/

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks Tom

Spiros Methenitis, February 15, 2018 - 1:20 pm UTC

You answer was most helpful.
Chris Saxon
February 15, 2018 - 2:24 pm UTC

It's Chris ;) But thanks anyway!

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.