이성욱
-
Real MySQL 8.0 6 - 데이터 타입책책책 책을 읽읍시다/프로그래밍 2023. 5. 5. 00:52
문자열(CHAR와 VARCHAR)저장 공간 우선 CHAR와 VARCHAR의 공통점은 문자열을 저장할 수 있는 데이터 타입이라는 점이고, 가장 큰 차이는 고정 길이냐 가변 길이냐다.고정 길이는 실제 입력되는 컬럼값의 길이에 따라 사용하는 저장 공간의 크기가 변하지 않는다. CHAR 타입은 이미 저장 공간의 크기가 고정적이다. 실제 저장된 값의 유효 크기가 얼마인지 별도로 저장할 필요가 없으므로 추가로 공간이 필요하지 않다.가변 길이는 최대로 저장할 수 있는 값의 길이는 제한돼 있지만, 그 이하 크기의 값이 저장되면 그만큼 저장 공간이 줄어든다. 하지만 VARCHAR 타입은 저장된 값의 유효 크기가 얼마인지를 별도로 저장해 둬야 하므로 1~2바이트의 저장 공간이 추가로 더 필요하다. 하나의 글자를 저장하기 ..
-
Real MySQL 8.0 5 - 파티션책책책 책을 읽읍시다/프로그래밍 2023. 5. 3. 07:11
개요파티션을 사용하는 이유 테이블의 데이터가 많아진다고 해서 무조건 파티션을 적용하는 것이 효율적인 것은 아니다. 하나의 테이블이 너무 커서 인덱스의 크기가 물리적인 메모리보다 훨씬 크거나 데이터 특성상 주기적인 삭제 작업이 필요한 경우 등이 파티션이 필요한 대표적인 예라고 할 수 있다. 각 경우에 대해 지금부터 하나씩 자세히 살펴보자.단일 INSERT와 단일 또는 범위 SELECT의 빠른 처리 데이터베이스에서 인덱스는 일반적으로 SELECT를 위한 것으로 보이지만 UPDATE나 DELETE 쿼리를 위해 필요한 때도 많다. 물론 레코드를 변경하는 쿼리를 실행하면 인덱스의 변경을 위한 부가적인 작업이 발생하긴 하지만 UPDATE나 DELETE 처리를 위해 대상 레코드를 검색하려면 인덱스가 필수적이다. 하지..
-
Real MySQL 8.0 4 - 쿼리 작성 및 최적화책책책 책을 읽읍시다/프로그래밍 2023. 5. 1. 22:45
MySQL 연산자와 내장 함수 숫자 숫자 값을 상수로 SQL에 사용할 때는 다른 DBMS와 마찬가지로 따옴표(' 또는 ") 없이 숫자 값을 입력하면 된다. 또한 문자열 형태로 따옴표를 사용하더라도 비교 대상이 숫자 값이거나 숫자 타입의 컬럼이면 MySQL 서버가 문자열 값을 숫자 값으로 자동 변환한다. 하지만 이처럼 숫자 값과 문자열 값을 비교할 때는 한 가지 주의할 사항이 있다. 서로 다른 타입으로 WHERE 조건 비교가 수행되는 다음 쿼리를 잠깐 살펴보자. SELECT * FROM tab_test WHERE number_cloumn='10001'; SELECT * FROM tab_test WHERE string_cloumn=10001; 위 쿼리와 같이 두 비교 대상이 문자열과 숫자 타입으로 다를 때는..
-
Real MySQL 8.0 3 : 옵티마이저와 힌트 그리고 실행계획책책책 책을 읽읍시다/프로그래밍 2023. 4. 29. 23:45
09 옵티마이저와 힌트Order by 처리(Using filesort)정렬 처리 방법 쿼리에 ORDER BY가 사용되면 반드시 다음 3가지 처리 방법 중 하나로 정렬이 처리된다. 일반적으로 아래쪽에 있는 정렬 방법으로 갈수록 처리 속도는 떨어진다.정렬 처리 방법실행 계획의 Extra 컬럼 내용인덱스를 사용한 정렬별도 표기 없음조인에서 드라이빙 테이블만 정렬"Using filesort" 메세지가 표시됨조인에서 조인 결과를 임시 테이블로 저장 후 정렬"Using temporary; Using filesort" 메세지가 표시됨 먼저 옵티마이저는 정렬 처리를 위해 인덱스를 이용할 수 있을지 검토할 것이다. 인덱스를 이용할 수 있다면 별도의 "Filesort" 과정 없이 인덱스를 순서대로 읽어서 결과를 반환한다...
-
Real MySQL 8.0 2 : 인덱스책책책 책을 읽읍시다 2023. 4. 29. 00:23
인덱스 기본 인덱스를 역할별로 구분해 본다면 프라이머리 키(Primary Key)와 보조 키(세컨더리 인덱스, Secondary key)로 구분할 수 있다.프라이머리 키는 이미 잘 아는 것처럼 그 레코드를 대표하는 컬럼의 값으로 만들어진 인덱스를 의미한다. 이 컬럼(때로는 컬럼의 조합)은 테이블에서 해당 레코드를 식별할 수 있는 기준값이 되기 때문에 우리는 이를 식별자라고도 부른다. 프라이머리 키는 NULL 값을 허용하지 않으며 중복을 허용하지 않는 것이 특징이다.프라이머리 키를 제외한 나머지 모든 인덱스는 세컨더리 인덱스(Secondary Index)로 분류한다. 유니크 인덱스는 프라이머리 키와 성격이 비슷하고 프라이머리 키를 대체해서 사용할 수도 있다고 해서 대체 키라고도 하는데, 별도로 분류하기도 ..
-
Real MySql 8.0 1 : 쿼리 실행, 트랜잭션과 잠금책책책 책을 읽읍시다/프로그래밍 2023. 4. 27. 00:15
저자 : 백은빈, 이성욱들어가며 MySql 동작 원리를 자세하고 이해하기 쉽게 알려주는 책이다. 동작 원리를 이해하고 나니 백엔드 개발자로서 테이블 설계와 쿼리 작성을 어떻게 해야하는지 감이 잡혔다. 데이터를 저장하고 가공하는 백엔드 개발자에게는 반드시 읽어야할 책이다. MySql을 사용하는 개발자에게는 더할나위없이 좋고, 오라클이나 postgreSql과 같이 다른 진영에 있더라도 RDBMS를 MySql 예제를 통해 학습할 기회로 삼으면 좋다.MySql에 대해 A부터 Z까지 풀어주는 책이므로 설치, 클러스터링, 복제 등 상대적으로 관여도가 낮은(DBA에게 높은) 단원은 가볍게 읽고 넘어갔다. 개발하면서 자주 접하는 문제들 위주로 정리하였다. 다음부터는 발췌한 내용이다.04 아키텍처쿼리 실행 구조MySql..