[데이터베이스] Relational Algebra1 (관계대수)

MySQL index 관련 이모저모

인덱스는 B+tree 자료구조로 이루어져 있다.

https://zorba91.tistory.com/293

img

성능 향상을 위한 SQL 작성법

https://d2.naver.com/helloworld/1155

인덱스 스캔을 이용한 SQL flow

다음과 같은 SQL로 테이블 & 인덱스 설정

CREATE TABLE tbl  
(a INT NOT NULL,
b STRING,  
c BIGINT);

CREATE INDEX idx ON tbl  
(a, b);

INSERT INTO tbl VALUES  
(1, 'ZZZ', 123456),
(4, 'BBB', 123456789),
(1, 'AAA', 123'),
…
(이하 생략)

sql3

SELECT * FROM tbl  
WHERE a > 1 AND a < 5  
AND b < 'K'  
AND c > 10000  
ORDER BY b;  

위와 같은 SELECT 질의에서 WHERE 절에 있는 검색 조건은 다음과 같이 3가지로 나눌 수 있다.

복합인덱스 (Multi-column index)

인덱스 활용 최적화

LIMIT 최적화

IN 절을 사용한 질의에도 LIMIT 최적화를 적용할 수 있다.

SELECT * FROM tbl  
WHERE a IN (2, 4, 5)  
AND b < 'K'  
ORDER BY b  
LIMIT 3;  

그 외 이런저런 팁

Clustered Index & Secondary Index

https://ducmanhphan.github.io/2020-04-12-Understanding-about-clustered-index-in-RDBMS/

https://jojoldu.tistory.com/172

https://medium.com/free-code-camp/database-indexing-at-a-glance-bb50809d48bd