분류 전체보기
-
SQL BOOSTER - 인덱스 설계 과정DataBase/SQL 2024. 6. 12. 19:49
SQL 하나를 위한 인덱스 설계는 어렵지 않다. 테이블 관련 SQL을 모두 검토하고 종합적으로 인덱스를 설계하는 것이 가장 중요하다. SQL 하나만 보고 인덱스를 생성해서는 안 된다. 실무에서 이는 어려운 일이지만, 어떻든 간에 인덱스는 전체 SQL을 보고 설계하는 것이 정석이다. 전체 SQL을 볼 수 없다면 가능한 많은 SQL을 살펴보자 인덱스 종합적 설계 과정 SQL별 접근 경로 조사테이블 별 접근 경로 정리종합적인 인덱스 설계핵심 테이블 및 핵심 SQL 집중 설계생성 및 모니터링 SQL 별 접근 경로 조사 이 과정을 진행하기 위해서는 개발 완료된 모든 SQL을 살펴봐야한다. SQL을 살펴보면서 사용된 접근 경로들을 엑셀로 정리해 놓는다. 각 항목을 살펴보면, 파일명 SQL ID를 관리해 해당..
-
SQL BOOSTER - 인덱스로 커버된 SQLDataBase/SQL 2024. 6. 12. 19:14
인덱스를 이용해 검색할 때 테이블 접근 횟수를 줄이는 것이 매우 중요하다. 이 횟수를 얼만큼 줄이느냐에 따라 SQL의 성능이 좋아진다. 더 나아가 테이블 접근 자체가 생략된다면 성능에 가장 좋다. SELECT /*+ GATHER_PLAN_STATISTICS INDEX(T1 X_T_ORD_BIG_$) */T1.ORD_ST, COUNT(*)FROM T_ORD_BIG T1WHERE T1.ORD_YMD LIKE '201703%'AND T1.CUS_ID = 'CUS_0075'GROUP BY T1.ORD_ST; 실행계획의 Buffers 수치를 보면, TABLE ACESS BY INDEX ROWID 단계에서 30.125로 급증했다. 그러므로 TABLE ACESS BY INDEX ROWID만 제거하면 SQL 성능을 ..
-
SQL BOOSTER - 복합인덱스DataBase/SQL 2024. 6. 12. 15:13
복합 인덱스 - 컬럼 순정과 순서 A,B,C 칼럼 순서의 복합 인덱스와 C,B,A 컬럼 순서의 복합 인덱스는 완전히 다른 인덱스다 복합 인덱스를 만들 때 가장 중요한 것은 인덱스를 구성하는 컬럼 순서다. 어떤 순서로 컬럼을 정하는 지에 따라 강력한 성능을 발휘할 수도 있으며, 도움이 안 될 수도 있다. 이때, 컬럼 순서를 정할 때 관심 있게 봐야하는 것은 WHERE절의 조건이다. 같다 조건이 사용된 컬럼을 복합 인덱스에 앞 부분에 두는 것이 기본 원칙이다. CREATE INDEX X_T_ROD_BIG_$ ON T_ORD_BIF(CUS_ID,ORD_YMD);SELECT /*+GATHER_PLAN_STATISTICS INDEX(T1 X_T_ORD_BIG_3) */T1.ORD_ST, COUNT(*)FRO..
-
SQL BOOSTER - 단일 인덱스DataBase/SQL 2024. 6. 12. 11:31
단일 인덱스의 컬럼 정하기 인덱스는 조건에 맞는 데이터를 빠르게 찾기 위한 객체이다. WHERE 조건절에 사용된 컬럼에 인덱스를 구성하는 것이 기본 원리다. SELECT /*+ GATHER_PLAN_STATISTICS*/TO_CHAR(T1.ORD_DT,'YYYYMM'), COUNT(*)FROM T_ORD_BIG T1WHERE T1.CUS_ID = 'CUS_0064'AND T1.PAY_TP = 'BANK'AND T1.RNO = 2GROUP BY TO_CHAR(T1.ORD_DT,'YYYYMM'); 이제 성능 개선을 위해 단 하나의 단일 인덱스를 고려해보자 후버 컬럼은 WHERE 조건절에 사용된 CUS_ID, PAY_TP, RNO컬럼이다. SELECT 'CUS_ID' COL, COUNT(*) CNT FRO..
-
이펙티브 자바 Item 38 - 확장할 수 있는 열거 타입이 필요하면 인터페이스를 사용하라언어/Effective Java 2024. 6. 11. 09:31
열거 타입은 보통은 확장에 적합하지 않다. 확장할 수 있는 열거타입이 필요할 떄도 있는데, 연산 코드가 그 예시이다. 사용자 확장 연산을 추가할 수 있도록 열어주는 것이다. 열거 타입이 임의의 인터페이스를 구현하여 확장하면 된다. 인터페이스를 이용해 확장 가능 열거 타입처럼 만들어보기 public interface Operation{ double apply(double x, double y);} PLUS("+") { public double apply(double x, double y) { return x + y; } }, MINUS("-") { public double apply(double x, double y) { return x - y; } }, T..
-
이펙티브 자바 Item 36- 비트 필드 대신 EnumSet을 사용하라언어/Effective Java 2024. 6. 7. 11:08
열거한 값들이 주로 집합으로 사용될 경우, 예전에는 상수에 서로 다른 2의 거듭제곱 값을 할당한 정수 열거 패턴을 사용해 왔다. public class StyleWithBitField { public static final int STYLE_BOLD = 1 위와 같이 비트별 OR를 사용해 여러 상수르 ㄹ하나의 집합으로 모을 수 있으며, 이 집합을 비트 필드라한다.하지만, 비트 필드 또한 정수 열거 상수이므로, 정수 열거 상수의 단점을 그대로 지니며, 추가로 다른 문제도 가진다.비트 필드 값이 그대로 출력되면, 단순한 정수 열거 상수를 출력할 때보다 해석하기 더 어렵다비트 필드 하나에 녹아 있는 모든 원소를 순회하기 까다롭다.최대 몇 비트가 필요한지 처음부터 예상하고 적절한 타입을 선택해야한다.E..
-
이펙티브 자바 Item 35 : ordinal 메서드 대신 인스턴스 필드를 사용하라언어/Effective Java 2024. 6. 7. 10:14
열거 타입 상수는 하나의 정수값에 대응되며, 모든 열거 타입은 해당 상수가 몇 번째 위치인지 반환하는 ordinal()메서드를 제공한다. ordinal()의 잘못 사용한 예 해당 코드는 상수 선언 순서를 바꾸는 순간 오작동하며, 이미 사용 중인 정수와 값이 같은 상수는 추가할 방법이 없다. 동작은 하지만 유지보수의 어려움이 있다! public enum Ensemble { SOLO, DUET, TRIO, QUARTET, QUINTET, SEXTET, SEPTER, OCTET, DOUBLE_QUARTET, NONET, DECTET, TRIPLE_QUARTET; public int numberOfMusicians() { return ordinal() + 1; } 열거 타입 상수에..
-
성능 개선을 위한 기본 지식 - 실행 계획DataBase/SQL 2024. 6. 6. 17:12
1. 들어가며, SQL 성능 관련해서 '좌변은 절대 가공하지 말라'라는 말이 있다. WHERE를 사용하며, 왼쪽 컬럼을 가공하면 인덱스를 사용하지 못하기 때문이다. 이러한 사실을 망각하고, 무조건 좌변을 가공하지 않기 위해 WHERE '201701' = SUBSTR(T1.ORD_TMD,1,6)같은 SQL을 작성하거나, INNER JOIN 순서를 바꾼다고 성능이 좋아질 것이란 결론에 도달하기도한다. 결론적으로 SQL 성능 개선을 위한 방법들은 절대 암기할 것이 아니라, 원리를 잘 파헤치고 고민하는 과정이 중요하다 항상 실행계획을 확인하고, 문제점이 무엇인지 찾아보는 것이 좋다. 2. 실행 계획 이란 오라클과 같은 DBMS에서 데이터를 조회하거나 변경하려면, SQL을 사용해야한다. SELECT,UP..