Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Question about Index in data selection

Former Member
0 Likes
580

Hi experts,

I am reading the documents about index today and find there are some questions confused me. Plz help, thx!

1 What is the technical structure of index?

For example, I have a table ztable with 5 fields, F1(key), F2(key). F3. F4.F5. If I create a index on F3,F4, the system will create a copy of this table. Is the structure of this copy as follow?

F3, F4, pointer(for the lineno of the recorder)

So this copy will have fewer lines than the ZTABLE and is sorted. If the DB optimizer choose this index in selection, it will be fast for the 2 reasons?

2 By what is the sequence of the fields in the index determined? I read a BLOG about permance, the author make a example with DB05, and say if the distinct values of certain field is between 1-1000 lines, it is good to set a secondary index for the field.

I wonder, if the F3 has only 5 distinct value for all the data in the ZTABLE, and the F4 has 100 distinct value. Which one should be the first field in the index and why?

Thx!!~

Hi experts,

I am reading the documents about index today and find there are some questions confused me. Plz help, thx!

1 What is the technical structure of index?

For example, I have a table ztable with 5 fields, F1(key), F2(key). F3. F4.F5. If I create a index on F3,F4, the system will create a copy of this table. Is the structure of this copy as follow?

F3, F4, pointer(for the lineno of the recorder)

So this copy will have fewer lines than the ZTABLE and is sorted. If the DB optimizer choose this index in selection, it will be fast for the 2 reasons?

2 By what is the sequence of the fields in the index determined? I read a BLOG about permance, the author make a example with DB05, and say if the distinct values of certain field is between 1-1000 lines, it is good to set a secondary index for the field.

I wonder, if the F3 has only 5 distinct value for all the data in the ZTABLE, and the F4 has 100 distinct value. Which one should be the first field in the index and why?

Thx!!~

3 REPLIES 3
Read only

ravi_lanjewar
Contributor
0 Likes
537

Hi,


1 What is the technical structure of index?
For example, I have a table ztable with 5 fields, F1(key), F2(key). F3. F4.F5. If I create a index on F3,F4, the system will create a copy of this table. Is the structure of this copy as follow?
F3, F4, pointer(for the lineno of the recorder)

So this copy will have fewer lines than the ZTABLE and is sorted. If the DB optimizer choose this index in selection, it will be fast for the 2 reasons?

2 By what is the sequence of the fields in the index determined? I read a BLOG about permance, the author make a example with DB05, and say if the distinct values of certain field is between 1-1000 lines, it is good to set a secondary index for the field.
I wonder, if the F3 has only 5 distinct value for all the data in the ZTABLE, and the F4 has 100 distinct value. Which one should be the first field in the index and why?

You seem to be correct for some but not all.

Struture of index will

for unique key index F3, F4, row id of database

it could have only one row id when your where condition match with the index then it goes to only index table first and read the row id and read record directly from the row id.

But for non unique key table store all the F3, F4, row id of record which math value of F1 and F4. It can have multiple value.

When your where condition math with condition partially ie left part of the key or whole part key then read all match record from the index table and then read the database physical table and check for addation where condition if any.

Index is determine on basis of the where condtion which is most left part of index will match.

if your where condition F4 and in your index has f3 f4 then index will not consider, It create gap between index condition and read whole table database. But if you consider f3 then only it consider the index to read because it match the left most part with index fields.

For more details How to create secondary index ? Search for blog in sdn I reply many time.

Read only

Former Member
0 Likes
537

And index is in principle easily explained, it is something like a telephone book:

Name Firstname Street House number telephone number.

Your primary key is: Name Firstname Street House number

You need name and firstname to find the wanted telephone number.

Sometimes you will know where somebody lives, street and number .... but the telephone book can not help you.

You would another telephone book, ordered by the streets.

If you know the number, it will not give you name and street, this is deliberately not supported in many countries!

=> So evey index has a certain order and can only support searches where you know the first fields.

>So this copy will have fewer lines than the ZTABLE

No, same number of lines, less columns. Rowid or pointer is not used by all databases, sometimes the primary key is used as reference, i.e. the secondary key is not much smaller!

Siegfried

Read only

Former Member
0 Likes
537

Thanks both. It really helps.