사용자 도구

사이트 도구


database:mysql:index

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
database:mysql:index [2019/01/23 11:18]
kwon37xi
database:mysql:index [2020/11/24 18:55]
kwon37xi [Covering Index]
줄 6: 줄 6:
   * [[https://stackoverflow.com/questions/14230892/difference-between-using-references-with-and-without-foreign-key|mysql - Difference between using REFERENCES with and without FOREIGN KEY? - Stack Overflow]]   * [[https://stackoverflow.com/questions/14230892/difference-between-using-references-with-and-without-foreign-key|mysql - Difference between using REFERENCES with and without FOREIGN KEY? - Stack Overflow]]
   * https://dev.mysql.com/doc/refman/5.7/en/create-table.html   * https://dev.mysql.com/doc/refman/5.7/en/create-table.html
-> MySQL parses but **ignores “inline REFERENCES specifications”** (as defined in the SQL standard) where the references are defined as part of the column specification. MySQL accepts REFERENCES clauses only when specified as part of a separate FOREIGN KEY specification. + > MySQL parses but **ignores “inline REFERENCES specifications”** (as defined in the SQL standard) where the references are defined as part of the column specification. MySQL accepts REFERENCES clauses only when specified as part of a separate FOREIGN KEY specification.
- +
- +
- +
  
 ===== Index 생성 ===== ===== Index 생성 =====
줄 72: 줄 68:
 WHERE type=12345 AND level > 3 WHERE type=12345 AND level > 3
 ORDER BY id ORDER BY id
 +</code>
 +
 +
 +===== Covering Index =====
 +  * [[https://gywn.net/2012/04/mysql-covering-index/|MySQL에서 커버링 인덱스로 쿼리 성능을 높여보자!! | gywndi's database]]
 +  * Index 에 있는 값만으로 ''where'', ''order by'', ''select 각 필드''를 처리할 수 있는 상황.
 +  * Query 실행계획에서 **Extra:  Using index**가 나오는 상황.
 +  * 실제 데이터를 찾아 읽는 것보다 훨씬 빠르다.
 +  * 또한, 테이블 전체 컬럼이 select 대상이더라도 먼저 커버링 인덱스로 PK값만가져오고, 그 결과로 나머지 컬럼을 가져오는게 훨씬 빠른 경우도 많다.
 +<code sql>
 +select a.*
 +from (
 +  -- 서브쿼리에서 커버링 인덱스로만 데이터 조건과 select column을 지정하고,
 +      select userno
 +      from usertest
 +      where chgdate like '2012%'
 +      limit 100000, 100
 +) b join usertest a on b.userno = a.userno
 +-- 조인을 통해 나머지 모든 컬럼(a.*) 조회
 </code> </code>
  
database/mysql/index.txt · 마지막으로 수정됨: 2020/11/24 18:55 저자 kwon37xi