Lecture 8 Objectives Physical Database Design
Lecture 8 Objectives Physical Database Design
Lecture 8 Objectives Physical Database Design
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Example 1: Dense Secondary Index<br />
Say we had the same relation:<br />
Cars(reg#, engine#, make, model, price)<br />
Assume that engine# (secondary key) is 7 bytes long.<br />
A secondary key field has a distinct value for each data record.<br />
Hence, the secondary index will be dense.<br />
We want to know if it would be better to use a secondary index file<br />
constructed with engine# as the secondary index key, or<br />
Perform a simple linear search on the data file (cost = 1500<br />
accesses).<br />
Example 2: Non-dense Secondary Index<br />
• We can also create a secondary index on a non-key field<br />
of a file. In this case, many records in the data file can<br />
have the same value for the indexing field. There are<br />
several options for implementing such an index.<br />
• The option which is more commonly used is to have a<br />
single entry for each index filed value, but to create an<br />
extra level of indirection. In this non-dense scheme, the<br />
secondary index pointer will point to a block of record<br />
pointers; each record pointer points to one record in the<br />
data file.<br />
41<br />
43<br />
Example 1: Dense Secondary Index<br />
30000 records, 13 bytes each<br />
385 blocks, 78 records each<br />
Secondary Index File<br />
2098377<br />
3096275<br />
4654786<br />
5673455<br />
5675489<br />
5675789<br />
6345234<br />
6587969<br />
7493874<br />
7648378<br />
7 bytes 6 bytes<br />
30,000 records, 100 bytes each<br />
3000 blocks, 10 records each<br />
Main Data File<br />
E246WFC 7648378<br />
F651DEK 3096275<br />
G123RMR 7493874<br />
G551JBA 2098377<br />
G889VDU 6587969<br />
G994PBR 5675789<br />
H203PBR 4654786<br />
H266MHU 6345234<br />
H311MHG 5675489<br />
H626RPG 5673455<br />
to read block<br />
Block access = ⎡log2 385⎤ + 1 = 10<br />
(Better than a linear search on the data file which needs 1500 accesses)<br />
Example 2: Non-dense Secondary Index<br />
30 records, 26 bytes each<br />
1 block, 30 records in it<br />
Secondary Index File<br />
Fiat<br />
Ford<br />
Renault<br />
Rover<br />
Vauxhall<br />
20 bytes 6 bytes<br />
Pointers<br />
to read block and pointer<br />
30,000 records, 100 bytes each<br />
3000 blocks, 10 records<br />
Main Data File<br />
E246WFC 7648378 Fiat<br />
F651DEK 3096275 Rover<br />
G123RMR 7493874 Ford<br />
G551JBA 2098377 Rover<br />
G889VDU 6587969 Renault<br />
G994PBR 5675789 Vauxhall<br />
H203PBR 4654786 Rover<br />
H266MHU 6345234 Ford<br />
H311MHG 5675489 Renault<br />
H626RPG 5673455 Fiat<br />
Block access = ⎡log2 1⎤ + 1+ 2 = 3<br />
(Better than a linear search on the data file which needs 1500 accesses)<br />
1<br />
2<br />
3<br />
4<br />
5<br />
1024<br />
block<br />
size<br />
42<br />
1<br />
2<br />
3<br />
4<br />
5<br />
44<br />
1024<br />
block<br />
size