원본 : http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html

8.8.2. Using PROCEDURE ANALYSE

ANALYSE([max_elements[,max_memory]])

ANALYSE() examines the result from a query and returns an analysis of the results that suggests optimal data types for each column that may help reduce table sizes. To obtain this analysis, append PROCEDURE ANALYSE to the end of a SELECT statement:

SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max_elements,[max_memory]])

For example:

SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);

The results show some statistics for the values returned by the query, and propose an optimal data type for the columns. This can be helpful for checking your existing tables, or after importing new data. You may need to try different settings for the arguments so that PROCEDURE ANALYSE() does not suggest the ENUM data type when it is not appropriate.

The arguments are optional and are used as follows:

  • max_elements (default 256) is the maximum number of distinct values that ANALYSE() notices per column. This is used by ANALYSE() to check whether the optimal data type should be of type ENUM; if there are more than max_elements distinct values, then ENUM is not a suggested type.

  • max_memory (default 8192) is the maximum amount of memory that ANALYSE() should allocate per column while trying to find all distinct values.

 

처음 DB를 구성해서 일정기간 사용하다보면 특정 테이블에 데이터가 편중되고, 그러다 보면 해당 테이블 때문에 병목현상이 발생하는 경우가 종종 있다. 그때부터 해당 테이블을 어떻게 커스터마이징 해야할까 고민하게 되고 각 컬럼이 제대로 사용되는지 체크해보고 싶은 욕구가 생긴다. 가령 VARCHAR(100) 으로 선언했음에도 불구하고  실제 데이터는 20 byte 미만으로 사용된다면 해당 컬럼의 선언은 굳이 varchar(100) 이 아니라 varchar(20)으로 하는것이 좋다는 것은 누구나 아는 사실이다.

이를 분석하기 위한 방법이 바로 PROCEDURE ANALYSE 이다.

 

 



내장함수를 한눈에 볼수 있도록 정리했다.

 

어떤 함수들이 있는지 출력해서 가까운데 두고 자주 보면서 코딩하자.

 

pdf 파일로 정리했으며 자세한 사용법은 해당링크를 클릭하면 mysql 공식사이트 manual 로 이동한다.

 

http://dev.mysql.com/doc/refman/5.5/en/

 

한글화가 필요한 부분은 추후 번역하겠지만 공식사이트 샘플만 보면 다 이해 할 수 있어서 굳이 필요없을듯 싶다.

 

MySQL 함수모음표.pdf



mysql index추가/삭제하기

Posted 2012. 4. 12. 18:18

Table에 index를 추가하는 방법 (참고)


0. show index from [table_name] 을 이용하여 현재 테이블의 index를 조회한다.

또는 show keys from [table_name]


1. Alter table을 이용한 추가방법

 alter table [table name] add index [index_name]([column_name],...)


ex1) USER 에 user_id라는 컬럼이 있고 이 컬럼을 index에 추가하고자 할때

alter table USER ADD INDEX  idx_user_id(user_id);


ex2) unique 형태의 index를 추가하고자 할때

alter table USER ADD UNIQUE(user_id);


ex3) primary key로 index를 추가하고잘 할때

alter table user ADD PRIMARY KEY(user_id);



2. Create index를 이용한 추가방법


CREATE INDEX  [index_name]  ON [table_name]([column_name])


ex) CREATE INDEX idx_user_id ON USER(user_id);


ex) unique index를 추가할때는 

CREATE UNIQUE INDEX idx_user_id ON USER(user_id);



3. 삭제는 drop을 이용한다.

 ALTER TABLE [table_name] DROP INDEX [index_name] 


ex)) ALTER TABLE USER DROP INDEX idx_user_id;

또는

   DROP INDEX  idx_user_id ON USER;




« PREV : 1 : 2 : 3 : 4 : 5 : 6 : ··· : 15 : NEXT »