'Mysql'에 해당되는 글 2건

  1. 2009.09.03 Pros and Cons of a Denormalized Schema 1
  2. 2009.09.03 mysql event 삭제시
프로젝트하면서 mysql 관해 작업하는데 OTL 로 만든 글귀하나;;
시간내서 이 책도 봐야겠다;; 볼께 너무 많아 ㅜ.ㅜ


Pros and Cons of a Denormalized Schema
A denormalized schema works well because everything is in the same table, which
avoids joins.
If you don’t need to join tables, the worst case for most queries—even the ones that
don’t use indexes—is a full table scan. This can be much faster than a join when the
data doesn’t fit in memory, because it avoids random I/O.
A single table can also allow more efficient indexing strategies. Suppose you have a
web site where users post their messages, and some users are premium users. Now
say you want to view the last 10 messages from each of the premium users. If you’ve
normalized the schema and indexed the publishing dates of the messages, the query
might look like this:
Normalization and Denormalization | 141

mysql> SELECT message_text, user_name
-> FROM message
-> INNER JOIN user ON message.user_id=user.id
-> WHERE user.account_type='premium'
-> ORDER BY message.published DESC LIMIT 10;

To execute this query efficiently, MySQL will need to scan the published index on
the message table. For each row it finds, it will need to probe into the user table and
check whether the user is a premium user. This is inefficient if only a small fraction
of users have premium accounts.
The other possible query plan is to start with the user table, select all premium users,
get all messages for them, and do a filesort. This will probably be even worse.
The problem is the join, which is keeping you from sorting and filtering simultaneously
with a single index. If you denormalize the data by combining the tables and
add an index on (account_type, published), you can write the query without a join.
This will be very efficient:

mysql> SELECT message_text,user_name
-> FROM user_messages
-> WHERE account_type='premium'
-> ORDER BY published DESC
-> LIMIT 10;

발췌: High Performance_mysql_2nd_edition 중에서

Posted by 빈솔B
,

mysql event 삭제시

Mysql 2009. 9. 3. 21:39
mysql client 프로그램 yog로  아무리 event row값을 삭제해봐도 이상하게 제대로 동작되지 않는것이다;;
그런데..
아래 블로그에서 발견한 엄청난 사실!!!
이런 Event 를 삭제하기 위해서는 아래와 같은 SQL 문을 실행하면 된다.
drop event 이벤트명;
즉 위의 e1 이라는 event 를 삭제하기 위해서는 drop event e1; 인 SQL문을 실행하면 된다.
event는 mysql.event 테이블에 등록된다고 했는데 mysql.event 에서 바로 삭제하는경우
메모리의 영향때문인지 삭제후 똑같은 event 명으로 등록을 한경우 앞전에 사용한 event 가 제대로 지워지지 않고 동작하는 경우를 볼수 있다. 그러니 삭제시는 꼭 drop event 이벤트명; 을 이용하길 바란다.

이런 캐삽질;; 나의 아까운 2시간..ㅜ.ㅜ
Posted by 빈솔B
,