DataBase/튜닝
-
불친절 SQL 2장 정리 (인덱스 기본)DataBase/튜닝 2024. 8. 19. 21:21
1. 인덱스 튜닝의 핵심 요소 - 스캔 과정 비효율 줄이기 -> 인덱스 구성 및 순서에 영향 - 랜덤 엑세스 최소화 튜닝 -> 인덱스 구성에 영향 2. 인덱스 탐색 과정 -> 수직적 탐색을 통해 리프 블록을 찾는다 (루트에서 브랜치를 통해 리프까지) -> 이때 키에는 하위 브랜치의 범위가 담긴다. -> 비교해야하는 값과 키를 탐색하며, 자신의 값보다 같거나 큰 값을 만나면 그 옆의 브랜치로 이동한다. -> 수평적 탐색을 통해 값을 찾는다. (리프 사이 사이를 다니며 탐색) -> 리프 블록의 값을 비교하며 필요한 값을 찾는다. -> 인덱스의 값으로 충분하지 않으면, ROWID를 사용해서 테이블에 접근해서 필요..
-
불친절 SQL 1장 정리DataBase/튜닝 2024. 8. 19. 19:55
1. SQL이 느린 이유 -> 디스크 I/O 때문임! (I/O 처리하는 과정에서 프로세스가 잠을 자기 때문) 여러 프로세스가 하나의 CPU를 공유할 수 있지만, 특정 순간에는 하나의 프로세스만 CPU를 사용할 수 있다. 디스크에서 데이터를 읽어야 할 때 CPU를 OS에 반환하고 수면 상태에서 I/O 완료를 기다림 2. 데이터베이스 저장 구조(오라클) -> 테이블 스페이스 : 여러 세그먼트를 담음 세그먼트는 여러 카테고리가 있음 (테이블, 인덱스, 파티션 등) *세그먼트, 익스텐트,블록은 하나의 테이블에 대한 정보임 -> 세그먼트 -> 세그먼트 : 여러 익스텐트를 담는 저장 공간 -> 익스텐트 ..
-
조인 튜닝 - NL 조인DataBase/튜닝 2024. 8. 7. 18:14
1. NL 조인의 기본 메커니즘 NL조인은 Nested Loop 방식을 사용한다. 중첩 루프문으로 수행 된다는 뜻이다.NL 조인은 중첩 루프문과 같은 수행 구조를 사용한다. 일반적으로 NL 조인은 Outer와 Inner 양쪽 테이블 모두의 인덱스를 사용한다. Outer쪽 테이블 사이즈가 크지 않으면 인덱스를 이용하지 않을 수 있다. Table Full Scan 하더라도 한 번에 그치기 때문이다. 반면 Inner쪽 테이블은 인덱스를 사용해야 한다. 사원 X1 인덱스에서 입사일자 >= '19960101'인 첫번째 레코드를 찾는다.인덱스에서 읽은 ROWID로 사원 테이블 레코드를 찾아간다.사원 테이블에서 읽은 사원번호 0006으로 고객 X1 인덱스를 탐색한다.고객_X1 인덱스에서 읽은 ROWID로 고객 ..
-
인덱스 기본(1) - 인덱스 구조 및 탐색DataBase/튜닝 2024. 7. 17. 19:56
초등학교에 방문해 홍길동을 찾는 두 가지 방법 1. 1~6학년 모든 교실에서 홍길동 찾기 -> 홍길동이 많을 때 빠름 (테이블 풀)2. 교무실에서 명부 조회해서 홍길동이 있는 교실만 찾기 -> 홍길동이 별로 없으면 빠름 (인덱스) 이름으로 학생을 찾는 경우가 많다면, 학생명부를 아예 이름순으로 정렬해두면 편하다 이것이 인덱스다.이름에 딸린 학년-반-번호 컬럼이 인덱스 ROWID에 해당한다. 수십 년에 걸쳐 DBMS가 발전해 왔지만, 조회 방법은 위 두가지 방법에서 크게 벗어나지 못하고 있다.따라서 SQL 튜닝을 위해 인덱스를 공부하는 것은 매우 중요하다. 1. 인덱스 튜닝의 두 가지 핵심요소 인덱스는 큰 테이블에서 소량 데이터를 검색할 때 사용한다. 인덱스 튜닝의 핵심요소는 크게 두 가지이다...