본문 바로가기
보관용

[MySQL] Desc /Asc index => 지정 안된다 => 우회방법

by 크크다스 2014. 11. 8.
반응형

= index values are always stored in ascending order

= 참고> http://stackoverflow.com/questions/10109108/how-do-i-create-a-desc-index-in-mysql

= 참고> Reserved Key words : http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

= 개요

예> ORDER BY log_time DESC, msgid LIMIT 256]

위처럼 DESC으로 인덱싱이 필요한데 인덱스 설정시 키워드로는 존재하지만 구현이 안되어 있어서 실제 인덱싱이 안되고

무조건 ASC로만 동작하여 성능이 안나온다는 얘기임.


= 그러나 방법을 찾으면 ......

= reverse 매퍼를 두어서 해결하는 방법을 제시하고 있는 곳이 있음.

= 참고> http://stackoverflow.com/questions/10382346/is-it-possible-to-make-mysql-use-an-index-for-the-order-by-1-desc-2-asc

As a suggestion you would better have a reversed_root column which is Integer.MAX_VALUE - root AND have an index on (reversed_root, path). Then you can have a query as :

SELECT * FROM Board ORDER by reversed_root ASC,path ASC LIMIT 0,100

TIMESTAMP 최대값 =>
참고> http://dev.mysql.com/doc/refman/5.6/en/datetime.html

DATETIME : '1000-01-01' to '9999-12-31'
TIMESTAMP: '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07'
참고> 타입별 최대값 : http://help.scibit.com/mascon/masconMySQL_Field_Types.html

자동으로 Reverse값 넣는 방법

Google key Word> mysql default value other column

http://stackoverflow.com/questions/15384429/mysql-set-field-default-value-to-other-column

Oracle> REMAINING INT default MAX_VALUE - BOOKED_UNITS,

MySQL>

TimeStamp> 참고> 날짜 시간 연산 : http://www.nazuni.pe.kr/web/dev/mysql/functions_datetime.php


reverse_time ==> INT(10)

<Below Why Syntax Error ??? > => Use Below Command
delimiter //
CREATE TRIGGER MyTrigger_ReverseTimeStamp BEFORE INSERT ON ac_ap_log FOR EACH ROW
BEGIN
 IF NEW.reverse_time IS NULL THEN SET
NEW.reverse_time := UNIX_TIMESTAMP('2038-01-19 03:14:07') - UNIX_TIMESTAMP(CURRENT_TIMESTAMP); END IF;
END;//

CREATE TRIGGER MyTrigger_ReverseTimeStamp BEFORE INSERT ON ac_ap_log FOR EACH ROW
 IF NEW.reverse_time IS NULL THEN SET
NEW.reverse_time := UNIX_TIMESTAMP('2038-01-19 03:14:07') - UNIX_TIMESTAMP(CURRENT_TIMESTAMP); END IF;;//

delimiter ;


반응형

'보관용' 카테고리의 다른 글

[jiffies] 값에 대한 단상  (0) 2014.11.14
[sHash] Simple Hash  (0) 2014.11.10
[HTTPs] POST form  (0) 2014.11.07
[전시회] 사물 인터넷 - 코엑스  (0) 2014.11.04
[Util] SlidingVal  (0) 2014.10.29