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}}
    -
제목 작성자 날짜
공대여자
공대여자
mins01
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자