MySQL에서 INDEX와 NULL의 관계에 대한 알아보자.

MySQL에서 INDEX와 NULL의 관계에 대한 알아보자.

http://dev.mysql.com/doc/refman/5.1/en/create-index.html 
  • Available only for MyISAM tables. Specifying SPATIAL INDEX for other storage engines results in an error.

  • Indexed columns must be NOT NULL.
    -> 인덱스된 컬럼은 NULL이 되면 안된다. 하지만 밑에 예외가 있다.

  • In MySQL 5.1, column prefix lengths are prohibited. The full width of each column is indexed. Characteristics of nonspatial indexes (created with INDEXUNIQUE, or PRIMARY KEY):

  • Permitted for any storage engine that supports spatial columns except ARCHIVE.

  • Columns can be NULL unless the index is a primary key.
    -> PK 로 설정된 컬럼은 NULL이 될 수 없다.(숫자일경우 0, 문자열의 경우 ''가 들어간다.)

  • For each spatial column in a non-SPATIAL index except POINT columns, a column prefix length must be specified. (This is the same requirement as for indexed BLOB columns.) The prefix length is given in bytes.

  • The index type for a non-SPATIAL index depends on the storage engine. Currently, B-tree is used.In MySQL 5.1:

  • You can add an index on a column that can have NULL values only if you are using the MyISAMInnoDB, orMEMORY storage engine.
    -> MyISAM, InnoDB , MEMORY의 경우에만 컬럼의 인덱스에 NULL 값을 추가할 수 있다.
    -> 예외 사항이다.(오라클의 경우는 NULL은 인덱스에 포함되지 않는다.(NULL 검색은 풀스캔))

  • You can add an index on a BLOB or TEXT column only if you are using the MyISAM, or InnoDB storage engine.




NULL 검색에서 INDEX를 사용하는가?


EXPLAIN SELECT * FROM testf
WHERE f5 IS NULL;
->
    id  select_type  table   type    possible_keys  key     key_len  ref       rows  Extra      
------  -----------  ------  ------  -------------  ------  -------  ------  ------  -----------
     1  SIMPLE       testf   ref     f5             f5      403      const        6  Using where
->
NULL로 검색해도 index를 사용하는걸 알 수 있다.
(테스트는 MyISAM 으로 하였음)
댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
4.28
4.29
4.30
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
5.11
5.12
5.13
5.15
5.16
5.17
5.18
5.19
5.20
5.22
5.23
5.24
5.25
5.26
5.27
5.28
5.29
5.30
5.31
6.1