Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index란 ? #28

Open
thals0 opened this issue May 26, 2023 · 1 comment
Open

index란 ? #28

thals0 opened this issue May 26, 2023 · 1 comment

Comments

@thals0
Copy link
Owner

thals0 commented May 26, 2023

인덱스란 ?

인덱스(index)는 데이터 구조에서 요소들을 고유하게 식별하고 검색하기 위한 방법
주로 배열이나 리스트와 같은 순차적인 데이터 구조에서 사용되며, 각 요소에 할당된 고유한 식별자로 생각할 수 있음

예를 들어
image

이런 상황이 있을 때 데이터베이스는 하나하나 풀 스캔해가면서 age = 20인 데이터를 찾아야함

예 ) 영어 사전에 비유하면 쉬움 영어사전 마지막에 색인 생각하면 편함

1~100까지 카드가 있다고 했을 때 내가 고른 카드 숫자 맞추기 할 때 빠르게 맞추려면
50보다 큼니까 ? 75보다 큼니까 ? 이렇게 반씩 소거해나가면서 찾으면 훨씬 빠르게 찾을 수 있음

근데 여기서는 조건이 필요함
바로 . . 1~100까지 숫자가 정렬되어 있다는 것 !

비슷하게 데이터베이스에 있는 데이터들도 인덱싱을 하려면 정렬이 필요함

정렬해놓은 컬럼 사본을 index라고 함

image

Binary Search Tree

실제 데이터베이스에서는 tree 구조 사용
(아무렇게나 흩뿌려져있는 데이터들을 연결만 해놓은 구조)

image

B-tree

node마다 데이터를 하나만 넣는게 아니라 두 개 이상 넣으면 ?
반씩 잘라서 찾는게 아니라 3/2씩 자를 수 있음

image

B+tree

범위를 찾을 때 용이한 B+tree

image image image

왔다갔다 거리면서 찾아야해서 비효율적임

image

4부터 찾고 다음 노드로 쭉 이동만 하면 됨

그래서 요즘 데이터베이스에서는 B+tree로 index 만들어 주는 경우 많음

index 장점

image

index 단점

  1. 용량 차지
image

칼럼을 복사해서 정렬해두는 거기 때문에 인덱스 만들때마다 용량 차지함

  1. 기존 데이터의 삽입 및 삭제 시 인덱스에도 반영해야함
image

성능 하락 같은게 있을 수 있음

Reference

https://www.youtube.com/watch?v=iNvYsGKelYs&t=2s
코딩애플 선생님 감사합니다 ..

@thals0
Copy link
Owner Author

thals0 commented May 28, 2023

https://soft.plusblog.co.kr/87
기술면접스터디하는데 인준님이 index이야기에 cardinality이야기가 빠질 수 없다고 해서 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant