Index Structure Logical vs Physical Indices Physical indices

  • Slides: 6
Download presentation
Index Structure

Index Structure

Logical vs. Physical Indices Physical indices map a key to a physical address. A

Logical vs. Physical Indices Physical indices map a key to a physical address. A physical address is an actual location in the hardware (a memory address or cylinder/disk/block on a hard drive). Logical indices instead map keys to the Primary Key of a table. To actually get to the row you need to use the Primary Key to get to the physical address using the Primary Index (which must be physical). Logical http: //www. startrek. com/database_article/spock

Logical vs. Physical Indices (cont. ) Physical indices are faster (they don't have the

Logical vs. Physical Indices (cont. ) Physical indices are faster (they don't have the indirection of logical indices). But if the physical addresses change (from insertion/deletion), physical indices must by updated as well. Changes to physical addresses don't affect logical indices. Physical http: //www. bookofdaystales. com/tag/original-series/

Which is the fastest? students (first_name, last_name, grade) Primary Key = first_name, last_name 1.

Which is the fastest? students (first_name, last_name, grade) Primary Key = first_name, last_name 1. Primary Index (first_name, last_name) 2. Physical Index on grade 3. Logical Index on first_name 4. Depends on the query using the index

Choosing the Primary Key Most DBMSs order the physical placement of rows in memory

Choosing the Primary Key Most DBMSs order the physical placement of rows in memory according to the Primary Key of the table. Thus queries based on the Primary Key are very fast. But if queries are primarily concerned with other attributes, those queries will be slow. You should choose Primary Keys oriented for the most common/important queries. http: //higher-quality. com/primary-key-image. html

Indices for Key Contraints Indices can be used outside of SELECT statements. One common

Indices for Key Contraints Indices can be used outside of SELECT statements. One common use is in the enforcement of key constraints. Reminder about constraints: Constraints are restrictions on what values an attribute can take. CREATE TABLE students (student_id NOT NULL UNIQUE INTEGER, course_id TEXT, FOREIGN KEY (course_id) REFERENCES courses(course_id)); You can use an index on student_id to check for each row modified that its student_id is unique. You can use an index on course_id (for the table courses) to check that each course_id in students has a key in the index.