Index

꾸Jun·2023년 12월 11일
0

📚 Database

목록 보기
19/20

Index

  • Block
    • 하드디스크와 메모리에 왔다갔다하는 데이터의 논리적인 단위
    • 대략 4k bytes
  • Sector와 block이 맵핑

가령 아래와 같다고 생각해보자.

  • query

    • select * from product where product_id = '101';
  • product table

    • 1M records, 각각의 record는 200bytes long
    • Block은 1개당 4KB, block의 access time은 0.01s
    • 4KB/200B = 하나의 block당 20records
    • block의 개수 = 1M/20 = 50K
  • sequential search

    • 평균 시간 = 25K * 0.01s = 250s = 4m
    • 결과를 얻는데 4분이면 사용하지 못함. 따라서 indexing 없이는 사용할 수 없다.
    • 따라서 index 테이블을 만든다.
  • index

    • 찾고자 하는 record의 block을 가리키고 있는 key pointer를 담고 있는 테이블
    • select index_name from user_indexes where table_name = 'product';
      • product에 걸었던 인덱스를 찾기 위한 query
    • drop index index_name;
      • index를 drop하기 위한 query
profile
꾸준🐢

0개의 댓글