<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>일상다반사(日常茶飯事) &amp;gt; 스터디 &amp;gt; Database</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db</link>
<language>ko</language>
<description>Database (2021-08-20 10:37:42)</description>

<item>
<title>MySQL 랜덤으로 열을 뽑을 때, order by rand() 보다 빠른 방법</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=1004</link>
<description><![CDATA[<p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">출처 : <a href="https://blog.naver.com/nwind7/100193752809" rel="nofollow">https://blog.naver.com/nwind7/100193752809</a></p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"><br /></p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"><br /></p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"><br /></p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">보통 랜덤으로 목록을 뽑을 때</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">select rnd_id, rnd_value from t_random_innodb order by rand() limit 10;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">이런식으로 쿼리하시죠? 이게 간단해서 좋기는 한데 대상 컬럼수가 1만줄이 넘으면 느린걸 느낍니다. 10만 줄 쯤 되면 테이블 구조에 따라 1초 넘어가는 경우도 있고.. 해서 다른 방법을 찾아보았습니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">1. 조건절에 random 확율연산만 넣는 방법</p><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">01.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">SELECT</code> <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">rnd_id, rnd_value</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">02.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">FROM</code>   <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">(</code></span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">03.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">SELECT</code> <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">@cnt :=<span class="Apple-converted-space"> </span></code><code class="color2" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(255,20,147);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">COUNT</code><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">(*) + 1,</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">04.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block">@lim := 10</span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">05.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">FROM</code>   <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">t_random_innodb</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">06.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block">) vars</span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">07.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block">STRAIGHT_JOIN</span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">08.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block">(</span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">09.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">SELECT</code> <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">r.*,</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">10.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block">@lim := @lim - 1</span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">11.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">FROM</code>   <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">t_random_innodb r</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">12.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block"><code class="keyword" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(0,102,153);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-weight:bold;vertical-align:baseline;float:none;background-image:none;">WHERE</code>  <span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">(@cnt := @cnt - 1)</code></span></span></div><div class="line alt1" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">13.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(255,255,255);"><span class="block"><code class="color1" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;color:rgb(128,128,128);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">AND</code><span class="Apple-converted-space"> </span><code class="plain" style="margin:0px;padding:0px;border:0px;width:auto;height:auto;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:none;background-image:none;">RAND(20090301) &lt; @lim / @cnt</code></span></span></div><div class="line alt2" style="border:0px;font-size:13px;line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;margin:0px;padding:0px;width:auto;height:auto;color:rgb(34,34,34);vertical-align:baseline;float:none;background-image:none;background-color:rgb(231,229,220);"><code class="number" style="margin:0px;padding:0px 0.3em 0px 0px;border:0px;width:3em;height:auto;text-align:right;color:rgb(92,92,92);line-height:normal;font-family:Consolas, Monaco, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;vertical-align:baseline;float:left;background-image:none;">14.</code><span class="content" style="border-width:0px 0px 0px 3px;margin:0px 0px 0px 3.3em;padding:0px 0px 0px 0.5em;width:auto;height:auto;color:rgb(0,0,0);vertical-align:baseline;border-left-color:rgb(108,226,108);border-left-style:solid;float:none;background-image:none;background-color:rgb(248,248,248);"><span class="block">) i</span></span></div><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">이 방법의 핵심은 아래쪽에 select 절에 있는 @lim := @lim -1 와 where 조건절에 있는 @cnt :=@cnt-1 입니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">select 절에 있는 저 문장은 select 하는 결과레코드가 있을 때만 동작합니다. 즉 레코드가 하나 나타날때는 @lim 은 9로 줄고... 해서 10개의 레코드가 보이면 @lim은 0이 되죠.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">아래 @lim/@cnt 의 random 확율에서 @lim 이 0이 되면 확률은 0이 되겠죠? 결과 레코드를 하나 뽑을 때마다 결과로 뽑힐 확률을 낮추는 효과가 있습니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">where 조건절에 있는 @cnt :=@cnt-1  문장은 모든 대상열에 대해서 동작합니다. 즉 레코드 수가 1000개라면 처음에는 @cnt가 1000이 되고 마지막 레코드에서는 1이 됩니다. 커서가 뒤로 갈 수록 뽑힐 확률을 높여주는 역할을 합니다. </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">이 방법의 장점은 order by rand() 보다 빠르다는 것입니다.  어떤 경우에든 목표로 하는 결과값이 다</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">나오며, 그 확률은 랜덤확률에 거의 근접합니다. (약간 차이가 있지만 무시할 수 있습니다)</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">500만건이 있는 테이블에서 10건을 뽑아내는데 order by rand()로 4.4초가 걸리는 쿼리가 이 방법을 쓰면 3.2초에 끝나게 됩니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">단점도 있습니다. PK가 있는 테이블은 PK순서대로 결과값이 나옵니다. 만일 11개의 대상열이 있는데 10개를 뽑는다면? 거의 같은 목록이 똑같은 순서로 계속 나오게 됩니다. 단, 이건 * 로 뽑을때의 이야기이고, pk만 뽑아낼때는 랜덤하게 뽑아집니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">또 CPU자원을 많이 사용합니다. 대상열이 100만줄 있으면 저 변수 변경, rand() 연산 및 비교연산을 100만번 반복해야 합니다...</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">상대적으로 innodb 보다는 myisam에서 빠른 쿼리입니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"><a class="con_link" href="http://explainextended.com/2009/03/01/selecting-random-rows/" target="_blank" rel="nofollow noreferrer noopener">http://explainextended.com/2009/03/01/selecting-random-rows/</a> 요기서 본 내용입니다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">2. 임시테이블을 만들어 원하는 값을 insert 하는 방법</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">자동증가하는 PK가 있을 때 유용한 방법입니다.  프로시저로 보여드릴께요.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">DELIMITER $$</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">CREATE PROCEDURE `pSelect_Random_Test`(<br />     In in_RecordCnt  int<br />)<br />BEGIN<br />    declare v_max_idx int default 0;<br />    declare v_idx int default 0;<br />    declare v_cnt int default 0;<br />    declare v_t_cnt int default 0;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">-- 임시테이블을 만들고</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    DROP TEMPORARY TABLE IF EXISTS tmp_random; </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    create temporary table tmp_random (rnd_id int not null, rnd_value int not null, primary key (rnd_id) ) engine=memory;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"><br /> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">-- key의 max값을 뽑은 다음</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    select max(rnd_id) from t_random_innodb into v_max_idx;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> loop_me : LOOP</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    -- 임시테이블에 원하는 레코드가 들어갔거나 원하는 레코드에 대해 10배수의 insert 시도를 했을 경우 루프에서 벋어난다.<br />    select count(*) from tmp_random into v_cnt;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    if (v_t_cnt&gt;=in_RecordCnt*10) or (v_cnt &gt;= in_RecordCnt) then<br />       LEAVE loop_me;<br />    end if;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    -- 최대 key값에 random 값을 곱해서 최대키값보다 작은 어떤 임의의 키값을 하나 임시테이블에 입력한다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">    set v_idx = v_max_idx * rand() + 1;<br />    insert into tmp_random (rnd_id, rnd_value)<br />       select rnd_id, rnd_value from t_random_innodb where rnd_id &lt;= v_idx order by id desc limit 1 on duplicate key update rnd_value=values(rnd_value);</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">  set v_t_cnt = v_t_cnt + 1;<br /> END LOOP loop_me;</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> -- 임시테이블에 들어있는 값을 정렬 random 으로 쿼리한다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> select * from tmp_random order by rand();<br />END $$<br />DELIMITER ; </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">insert 건수가 많을 수록 2번이 1번보다 훨~씬 빨라진다.</p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);"> </p><p style="line-height:1.5;color:rgb(51,51,51);font-family:'돋움';text-align:justify;background-color:rgb(255,255,255);">500만건 기준으로 방법 1은 3.2초가 걸리는 쿼리가 방법 2로 하면 0.1초가 걸립니다^^</p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2021-08-20T10:37:42+09:00</dc:date>
</item>


<item>
<title>그누보드 MySQL 8.0 에서 datetime default  에러시</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=1003</link>
<description><![CDATA[<p>mysql 8.0 에서</p><p>datetime 은 1000-01-01 00:00:00 ~ 9999-12-31 23:59:59 만 허용된다</p><p><br /></p><p>그누보드 이전 mysql 5.x 버전에서</p><p>datetime NOT NULL default '0000-00-00 00:00:00'<br /></p><p><br /></p><p>허용되지 않는 0000-00-00 00:00:00 값이 들어가서 에러가 발생한다</p><p><br /></p><p>이때는</p><p>SQL MODE 를 변경해주어야 한다</p><p><br /></p><p>mysql&gt; set sql_mode='ALLOW_INVALID_DATES';</p><p><br /></p><p>또는</p><p><br /></p><p>[my.cnf]</p><p>sql_mode=ALLOW_INVALID_DATES<br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2021-03-25T10:30:58+09:00</dc:date>
</item>


<item>
<title>[MySql] 중복값 입력시 처리 INSERT IGNORE INTO &amp; DUPLICATE ON KEY UPDATE</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=1002</link>
<description><![CDATA[<p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><b><span style="font-size:18pt;">INSERT IGNORE INTO -</span><span style="font-size:18pt;"></span></b> </p><hr class="tx-hr-image-2" style="margin:0px;padding:0px;border:0px;height:15px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-image:url(&quot;//i1.daumcdn.net/deco/contents/horizontalrule/line05.gif?v=2&quot;);background-position:left center;background-size:initial;background-repeat:repeat-x;background-attachment:scroll;" /><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">데이터가 이미 있으면 따로 후속처리없이</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">그냥 아무행위도 안하고 나머지 데이터들만 INSERT를 진행하고자할 때</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">INSERT INTO 구문에 IGNORE을 추가해주면 된다.</span></p><hr class="tx-hr-image-4" style="margin:30px auto;padding:0px;border:0px;height:15px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-image:url(&quot;//i1.daumcdn.net/deco/contents/horizontalrule/line08.gif?v=2&quot;);background-position:left center;background-size:initial;background-repeat:repeat-x;background-attachment:scroll;width:54px;" /><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">해당 구문은 다음과 같다</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;border-style:solid;border-width:1px;border-color:rgb(243,197,52);background-color:rgb(254,254,184);padding:10px;"><p style="margin-left:2em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);"></span><span style="color:rgb(255,94,0);">INSERT <span style="color:rgb(255,0,0);">IGNORE </span>INTO</span><span style="color:rgb(255,94,0);"></span> [TABLE] (COLUMN1, COLUMN2, ...)<br /></b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);">VALUES </span>(VALUE1, VALUE2, ...)</b></span></p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:16px;">기존 INSERT INTO 사이에 IGNORE을 추가해주기만 한거라</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:16px;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:16px;">구문 자체는 매우 간단하다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><br /></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">예)</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;border-style:double;border-width:3px;border-color:rgb(203,203,203);background-color:rgb(255,255,255);padding:10px;"><p style="margin-left:2em;"><span style="font-size:12pt;"><b>CREATE <span style="color:rgb(217,65,141);">TABLE </span>MINE(</b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b>id <span style="color:rgb(65,116,217);">VARCHAR</span>(10) <span style="color:rgb(217,65,141);">PRIMARY KEY</span>,</b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b>name <span style="color:rgb(65,116,217);">VARCHAR</span>(10),</b></span><br /></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b>salary NUMBER</b></span></p><p style="margin-left:2em;"><b style="font-size:medium;">)</b><span style="font-size:12pt;"> </span></p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">가볍게 테이블 하나 있다 치고</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;border-style:double;border-width:3px;border-color:rgb(203,203,203);background-color:rgb(255,255,255);padding:10px;"><p style="margin-left:2em;"><span style="font-size:12pt;"><b style="font-size:medium;text-align:center;"><span style="color:rgb(217,65,141);">INSERT IGNORE INTO</span> MINE <span style="color:rgb(217,65,141);">VALUES </span>(<span style="color:rgb(107,153,0);">"CD2</span><span style="color:rgb(107,153,0);">"</span>, <span style="color:rgb(107,153,0);">"HAN</span><span style="color:rgb(107,153,0);">"</span>, <span style="color:rgb(65,116,217);">20000</span>)</b></span></p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">위의 쿼리를 그대로 실행하면</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><table width="784" class="txc-table" border="0" cellspacing="0" cellpadding="0" style="max-width:100%;width:968px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);border:none;border-collapse:collapse;"><tbody><tr><td style="border:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">id</span></b></p></td><td style="border-top:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">name</span><span style="font-size:12pt;"> </span></b></p></td><td style="border-top:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">salary</span><span style="font-size:12pt;"> </span></b></p></td></tr><tr><td style="width:261px;height:24px;border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-left:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b> CD2</b></span></p></td><td style="width:261px;height:24px;border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b>HAN </b></span></p></td><td style="width:261px;height:24px;border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b>20000 </b></span></p></td></tr></tbody></table><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><b></b> </p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">이러한 결과가 나오며</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><br /></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);border-style:double;border-width:3px;border-color:rgb(203,203,203);padding:10px;"><p style="margin-left:2em;"><span style="font-size:12pt;"><b style="font-size:medium;text-align:center;"><span style="color:rgb(217,65,141);">INSERT IGNORE INTO</span> MINE <span style="color:rgb(217,65,141);">VALUES </span>(<span style="color:rgb(107,153,0);">"CD2</span><span style="color:rgb(107,153,0);">"</span>, <span style="color:rgb(107,153,0);">"PARK</span><span style="color:rgb(107,153,0);">"</span>, <span style="color:rgb(65,116,217);">40000</span>)</b></span></p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">해당 쿼리를 한번 더 실행하면</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><table width="784" class="txc-table" border="0" cellspacing="0" cellpadding="0" style="max-width:100%;width:968px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';background-color:rgb(255,255,255);border:medium none;border-collapse:collapse;font-size:13px;"><tbody><tr><td style="background-color:rgb(140,140,140);border-color:rgb(204,204,204);border-style:solid;border-width:1px;height:22px;"><p style="text-align:center;"><b><span style="font-size:12pt;">id</span></b></p></td><td style="background-color:rgb(140,140,140);border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-top:1px solid rgb(204,204,204);height:22px;"><p style="text-align:center;"><b><span style="font-size:12pt;">name</span><span style="font-size:12pt;"> </span></b></p></td><td style="background-color:rgb(140,140,140);border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-top:1px solid rgb(204,204,204);height:22px;"><p style="text-align:center;"><b><span style="font-size:12pt;">salary</span><span style="font-size:12pt;"> </span></b></p></td></tr><tr><td style="border-bottom:1px solid rgb(204,204,204);border-left:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b> CD2</b></span></p></td><td style="border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);"><p style="text-align:center;"><b style="font-size:16px;">HAN</b></p></td><td style="border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><b style="font-size:16px;">20000</b></p></td></tr></tbody></table><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><b></b><i></i><u></u><sub style="height:0px;line-height:0;font-size:10px;"></sub><sup style="height:0px;line-height:0;font-size:10px;"></sup><strike></strike> </p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">이미 PK값이 있기때문에 에러는 발생하지 않고 </span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">IGNORE 뜻과 마찬가지로 데이터를 INSERT 하지 않는다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><br /></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">그래서 결과는 그대로이다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">----------------</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><b><span style="font-size:18pt;">- DUPLICATE ON KEY UPDATE  -</span></b></span><span style="font-size:12pt;"> </span></p><hr class="tx-hr-image-2" style="margin:0px;padding:0px;border:0px;height:15px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-image:url(&quot;//i1.daumcdn.net/deco/contents/horizontalrule/line05.gif?v=2&quot;);background-position:left center;background-size:initial;background-repeat:repeat-x;background-attachment:scroll;" /><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><b style="font-size:12pt;">데이터가 있으면 UPDATE 없으면 INSERT 처리</b><span style="font-size:12pt;">를</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"> 제어할 수 있는 </span><b style="font-size:16px;"><span style="color:rgb(255,94,0);">DUPLICATE ON KEY UPDATE 구문</span></b><span style="font-size:16px;">이</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">어찌 보면 </span><span style="font-size:12pt;">오라클의 MERGE INTO 구문과 비슷하다고 느껴진다.</span></p><hr class="tx-hr-image-4" style="margin:30px auto;padding:0px;border:0px;height:15px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-image:url(&quot;//i1.daumcdn.net/deco/contents/horizontalrule/line08.gif?v=2&quot;);background-position:left center;background-size:initial;background-repeat:repeat-x;background-attachment:scroll;width:54px;" /><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">해당 구문에 대해 알아보자</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><b></b> </span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;padding:10px;border:1px solid rgb(243,197,52);background-color:rgb(254,254,184);"><p style="margin-left:2em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);">INSERT </span><span style="color:rgb(255,94,0);">INTO</span> [TABLE] (COLUMN1, COLUMN2, ...)</b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);">VALEUS </span>(VALUE1, VALUE2, ...)</b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,0,0);">ON DUPLICATE KEY</span></b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);">UPDATE </span>(COLUMN1 = VALUE1 , COLUMN2 = VALUE2, ...)</b></span></p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><b></b> </span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">기존 INSERT INTO 구문에 뒷부분에 추가해서 써주기만하면 된다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">성능면에서도 괜찮은 구문이라는 말이 많다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">예)</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;padding:10px;border:3px double rgb(203,203,203);background-color:rgb(255,255,255);"><span style="font-size:12pt;"></span><p style="font-family:'맑은 고딕', sans-serif;font-size:13px;margin-left:2em;"><span style="font-size:12pt;"><b>CREATE<span> </span><span style="color:rgb(217,65,141);">TABLE<span> </span></span>MINE(</b></span></p><p style="font-family:'맑은 고딕', sans-serif;font-size:13px;margin-left:4em;"><span style="font-size:12pt;"><b>id<span> </span><span style="color:rgb(65,116,217);">VARCHAR</span>(10)<span> </span><span style="color:rgb(217,65,141);">PRIMARY KEY</span>,</b></span></p><p style="font-family:'맑은 고딕', sans-serif;font-size:13px;margin-left:4em;"><span style="font-size:12pt;"><b>name<span> </span><span style="color:rgb(65,116,217);">VARCHAR</span>(10),</b></span><br /></p><p style="font-family:'맑은 고딕', sans-serif;font-size:13px;margin-left:4em;"><span style="font-size:12pt;"><b>salary NUMBER</b></span></p><p style="font-family:'맑은 고딕', sans-serif;font-size:13px;margin-left:2em;"><span style="font-size:12pt;"><b>)</b></span> </p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><b></b><i></i><u></u><sub style="height:0px;line-height:0;font-size:10px;"></sub><sup style="height:0px;line-height:0;font-size:10px;"></sup><strike></strike> </span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">간단하게 테이블 하나를 만들어놓고 시작해보자</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><div class="txc-textbox" style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;padding:10px;border:3px double rgb(203,203,203);background-color:rgb(255,255,255);"><p style="margin-left:2em;"><span style="font-size:12pt;"><b style="font-family:'맑은 고딕', sans-serif;font-size:medium;text-align:center;"><span style="color:rgb(217,65,141);">INSERT INTO</span><span> </span>MINE<span> </span><span style="color:rgb(217,65,141);">VALUES<span> </span></span>(<span style="color:rgb(107,153,0);">"CD2</span><span style="color:rgb(107,153,0);">"</span>,<span> </span><span style="color:rgb(107,153,0);">"HAN</span><span style="color:rgb(107,153,0);">"</span>,<span> </span><span style="color:rgb(65,116,217);">20000</span>)</b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(255,94,0);">ON DUPLICATE KEY</span></b></span></p><p style="margin-left:4em;"><span style="font-size:12pt;"><b><span style="color:rgb(217,65,141);">UPDATE </span>name = <span style="color:rgb(47,157,39);">"KIM"</span> , salary = <span style="color:rgb(102,153,255);">300000</span></b></span> </p></div><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">위의 쿼리를 그대로 실행하면</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><table width="784" class="txc-table" border="0" cellspacing="0" cellpadding="0" style="max-width:100%;width:968px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);border:none;border-collapse:collapse;"><tbody><tr><td style="border:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">id</span></b></p></td><td style="border-top:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">name</span><span style="font-size:12pt;"> </span></b></p></td><td style="border-top:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);background-color:rgb(140,140,140);"><p style="text-align:center;"><b><span style="font-size:12pt;">salary</span><span style="font-size:12pt;"> </span></b></p></td></tr><tr><td style="border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-left:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b> CD2</b></span></p></td><td style="border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b>HAN </b></span></p></td><td style="border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);"><p style="text-align:center;"><span style="font-size:12pt;"><b>20000 </b></span></p></td></tr></tbody></table><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><b></b> </p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">이러한 결과가 나오며</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">해당 쿼리를 <span style="color:rgb(255,0,0);"><b>다시한번 실행</b></span>하게 되면</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><table width="784" class="txc-table" border="0" cellspacing="0" cellpadding="0" style="max-width:100%;width:968px;border:medium none;border-collapse:collapse;font-size:13px;text-indent:0px;"><tbody><tr><td style="background-color:rgb(140,140,140);border-color:rgb(204,204,204);border-style:solid;border-width:1px;line-height:normal;"><p style="text-align:center;"><b><span style="font-size:12pt;">id</span></b></p></td><td style="background-color:rgb(140,140,140);border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-top:1px solid rgb(204,204,204);line-height:normal;"><p style="text-align:center;"><b><span style="font-size:12pt;">name</span><span style="font-size:12pt;"> </span></b></p></td><td style="background-color:rgb(140,140,140);border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);border-top:1px solid rgb(204,204,204);line-height:normal;"><p style="text-align:center;"><b><span style="font-size:12pt;">salary</span><span style="font-size:12pt;"> </span></b></p></td></tr><tr><td style="border-bottom:1px solid rgb(204,204,204);border-left:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);line-height:normal;"><p style="text-align:center;"><span style="font-size:12pt;"><b> CD2</b></span></p></td><td style="line-height:normal;border-right:1px solid rgb(204,204,204);border-bottom:1px solid rgb(204,204,204);"><p style="text-align:center;"><b><span style="font-size:12pt;"><span style="color:rgb(255,0,0);">KIM</span></span></b></p></td><td style="border-bottom:1px solid rgb(204,204,204);border-right:1px solid rgb(204,204,204);line-height:normal;"><p style="text-align:center;"><span style="font-size:12pt;"><b><span style="color:rgb(255,0,0);">300000</span></b></span></p></td></tr></tbody></table><p style="text-align:center;"><b></b><i></i><u></u><sub style="height:0px;line-height:0;font-size:10px;"></sub><sup style="height:0px;line-height:0;font-size:10px;"></sup><strike></strike> </p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">이런식으로 값이 변한것을 확인이 가능하다.</span></p><hr class="tx-hr-image-2" style="margin:0px;padding:0px;border:0px;height:15px;font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-image:url(&quot;//i1.daumcdn.net/deco/contents/horizontalrule/line05.gif?v=2&quot;);background-position:left center;background-size:initial;background-repeat:repeat-x;background-attachment:scroll;" /><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">추가적으로 실험은 해보지 않았지만</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><span style="font-size:12pt;"></span></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;">key 필드 값 역시 뒤에 UPDATE 구문에 써줄수 있다.</span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p><p style="font-family:'Ubuntu Condensed', 'Noto Sans Korean';font-size:15px;background-color:rgb(255,255,255);text-align:center;"><span style="font-size:12pt;"><br /></span></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2020-12-08T13:36:50+09:00</dc:date>
</item>


<item>
<title>[Mysql/Oracle] order by 특정값(순서) 우선정렬</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=1001</link>
<description><![CDATA[<p>출처 : <a href="https://blog.naver.com/zij08209712/221607262193" rel="nofollow">https://blog.naver.com/zij08209712/221607262193</a></p><p><br /></p><div class="se-component se-quotation se-l-quotation_line" style="margin:0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-quotation se-l-quotation_line" style="margin:0px auto;padding:10px 0px;border:0px;font:inherit;vertical-align:baseline;"><blockquote class="se-quotation-container" style="margin:auto;padding:0px 20px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text se-quote" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:19px;vertical-align:baseline;">필요한 작업</span></p></div></blockquote></div></div></div><div class="se-component se-text se-l-default" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-text se-l-default" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">나는 특정컬럼의 데이터가 'F','G', 'H', 'B', 'C', 'I', 'J' 이런식으로 들어가 있을때</span></p><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">'F','G', 'H', 'B', 'C', 'I', 'J' 이 순서대로 정렬하여 데이터를 추출 하고자 한다. </span></p><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">​</span></p></div></div></div></div><div class="se-component se-quotation se-l-quotation_line" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-quotation se-l-quotation_line" style="margin:0px auto;padding:10px 0px;border:0px;font:inherit;vertical-align:baseline;"><blockquote class="se-quotation-container" style="margin:auto;padding:0px 20px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text se-quote" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:19px;vertical-align:baseline;">ORACLE / Mysql</span></p></div></blockquote></div></div></div><div class="se-component se-code se-l-code_black" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-code se-l-code_black" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-code se-fs-fs13" style="margin:0px;padding:12px 0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:13px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(248,248,242);background:rgb(39,40,34);"><div class="se-code-source" style="margin:0px;padding:0px 17px;border:0px;font:inherit;vertical-align:baseline;"><div class="__se_code_view language-javascript" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:inherit;line-height:24px;font-family:'Source Code Pro', sourcecodepro, 'se-sourcecodepro', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace, sans-serif;vertical-align:baseline;color:rgb(255,255,255);background:none;white-space:pre;word-spacing:normal;"> order <span class="token se-code-function" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(54,188,252);">by</span> 
        <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">(</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CASE</span> c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'F'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">0</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'G'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">1</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'H'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">2</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'B'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">3</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'C'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">4</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'I'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">5</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'J'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">6</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">ELSE</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">7</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">END</span>
        <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">)</span></div></div></div></div></div></div><div class="se-component se-text se-l-default" style="margin:30px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-text se-l-default" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">- 꼭 then 뒤에는 숫자만 들어가야한다. 원하는 순서대로 !</span></p><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">​</span></p></div></div></div></div><div class="se-component se-quotation se-l-quotation_line" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-quotation se-l-quotation_line" style="margin:0px auto;padding:10px 0px;border:0px;font:inherit;vertical-align:baseline;"><blockquote class="se-quotation-container" style="margin:auto;padding:0px 20px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text se-quote" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:19px;vertical-align:baseline;">Mysql FIELD() 함수 사용</span></p></div></blockquote></div></div></div><div class="se-component se-code se-l-code_black" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-code se-l-code_black" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-code se-fs-fs13" style="margin:0px;padding:12px 0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:13px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(248,248,242);background:rgb(39,40,34);"><div class="se-code-source" style="margin:0px;padding:0px 17px;border:0px;font:inherit;vertical-align:baseline;"><div class="__se_code_view language-javascript" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:inherit;line-height:24px;font-family:'Source Code Pro', sourcecodepro, 'se-sourcecodepro', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace, sans-serif;vertical-align:baseline;color:rgb(255,255,255);background:none;white-space:pre;word-spacing:normal;"><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">ORDER</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">BY</span>
    <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">FIELD</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">(</span>c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'F'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span><span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'G'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'H'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'B'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'C'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'I'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'J'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">)</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">DESC</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span></div></div></div></div></div></div><div class="se-component se-quotation se-l-quotation_line" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-quotation se-l-quotation_line" style="margin:0px auto;padding:10px 0px;border:0px;font:inherit;vertical-align:baseline;"><blockquote class="se-quotation-container" style="margin:auto;padding:0px 20px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text se-quote" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:19px;vertical-align:baseline;">참고용 Query (전체 query)</span></p></div></blockquote></div></div></div><div class="se-component se-code se-l-code_black" style="margin:40px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-code se-l-code_black" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-code se-fs-fs13" style="margin:0px;padding:12px 0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:13px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(248,248,242);background:rgb(39,40,34);"><div class="se-code-source" style="margin:0px;padding:0px 17px;border:0px;font:inherit;vertical-align:baseline;"><div class="__se_code_view language-javascript" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:inherit;line-height:24px;font-family:'Source Code Pro', sourcecodepro, 'se-sourcecodepro', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace, sans-serif;vertical-align:baseline;color:rgb(255,255,255);background:none;white-space:pre;word-spacing:normal;">select c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>regid<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>companyname<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CASE</span> c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'F'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'0'</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'G'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'1'</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'H'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'2A'</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'B'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'2B'</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'C'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'2C'</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'I'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'3'</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'J'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'4'</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">ELSE</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'7'</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">END</span> <span class="token se-code-keyword" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(242,193,63);">as</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span>
        <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>name<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>position<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>part<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>phone<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>mobile<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>fax<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>email<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>post<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>address<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>hq_manager
<span class="token se-code-keyword" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(242,193,63);">from</span> company c
left join company_member ch on c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>regid <span class="token se-code-operator" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(159,186,69);">=</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>companyid
 where c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span> <span class="token se-code-keyword" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(242,193,63);">in</span> <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">(</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'F'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span><span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'G'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'H'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'B'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'C'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'I'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'J'</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">)</span>
 order <span class="token se-code-function" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(54,188,252);">by</span> 
        <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">(</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CASE</span> c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span><span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">CSTATUS2</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'F'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">0</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'G'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">1</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'H'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">2</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'B'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">3</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'C'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">4</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'I'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">5</span>
        <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">WHEN</span> <span class="token se-code-string" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(247,97,170);">'J'</span> <span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">THEN</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">6</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">ELSE</span> <span class="token se-code-number" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">7</span>
		<span class="token se-code-constant" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;color:rgb(248,102,52);">END</span>
        <span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">)</span><span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> c<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>companyname<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">,</span> ch<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">.</span>createdate 
<span class="token se-code-punctuation" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;">;</span></div></div></div></div></div></div><div class="se-component se-text se-l-default" style="margin:30px 0px 0px;padding:0px;border:0px;font-size:13.3333px;line-height:inherit;font-family:'se-nanumgothic', sans-serif;vertical-align:baseline;color:rgb(119,119,119);background-color:rgb(255,255,255);"><div class="se-component-content" style="margin:0px auto;padding:0px 40px;border:0px;font:inherit;vertical-align:baseline;max-width:100%;"><div class="se-section se-section-text se-l-default" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><div class="se-module se-module-text" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p class="se-text-paragraph se-text-paragraph-align-" style="border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:0px;line-height:1.8;font-family:inherit;vertical-align:baseline;white-space:pre-wrap;"><span class="se-fs- se-ff-" style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-size:15px;vertical-align:baseline;">​</span></p><div class="autosourcing-stub-extra" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;"><p style="margin-top:11px;margin-bottom:7px;border:0px;font-variant:inherit;font-size:12px;line-height:inherit;font-family:Dotum;vertical-align:baseline;"><strong style="padding:0px 7px 0px 0px;">[출처]</strong> <a href="https://blog.naver.com/zij08209712/221607262193" target="_blank" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;" rel="nofollow noreferrer noopener">[Mysql/Oracle] order by 특정값(순서) 우선정렬</a><span style="margin:0px;padding:0px 7px 0px 5px;border:0px;font:inherit;vertical-align:baseline;">|</span><strong style="padding:0px 7px 0px 0px;">작성자</strong> <a href="https://blog.naver.com/zij08209712" target="_blank" style="margin:0px;padding:0px;border:0px;font:inherit;vertical-align:baseline;" rel="nofollow noreferrer noopener">Hamzzi90</a></p></div></div></div></div></div><p><br /></p><p><br /></p>]]></description>
<dc:creator>최고관리자</dc:creator>
<dc:date>2020-12-03T10:04:33+09:00</dc:date>
</item>


<item>
<title>MySQL 8 암호 정책(Password policy) 확인 및 수정하기</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=1000</link>
<description><![CDATA[<p>펌 : <a href="https://www.lesstif.com/dbms/mysql-8-password-policy-89555994.html" rel="nofollow">https://www.lesstif.com/dbms/mysql-8-password-policy-89555994.html</a></p><p><br /></p><h2 style="margin-right:0px;margin-bottom:12px;margin-left:0px;padding:0px;color:rgb(0,12,52);font-weight:normal;font-size:34px;line-height:1.1;letter-spacing:0.25px;font-family:'roboto-regular', Helvetica, Roboto, Arial, sans-serif;border-bottom-color:rgb(255,255,255);width:686.125px;margin-top:24px;">개요<a class="js-anchor article__content__content__anchor" href="https://www.lesstif.com/dbms/mysql-8-password-policy-89555994.html#MySQL8%EC%95%94%ED%98%B8%EC%A0%95%EC%B1%85(Passwordpolicy)%ED%99%95%EC%9D%B8%EB%B0%8F%EC%88%98%EC%A0%95%ED%95%98%EA%B8%B0-%EA%B0%9C%EC%9A%94" style="color:rgb(0,82,204);line-height:inherit;height:100%;padding-left:1rem;padding-right:1rem;vertical-align:middle;" rel="nofollow"><img class="article__content__content__anchor--link-icon" src="https://www.lesstif.com/dbms/_/AC1F142D0171445D13DC476E4B36792B/1602581193540/images/common/link-solid.svg" alt="Link to 개요" style="margin:0px 0px 3px;padding:0px;border:0px;vertical-align:middle;height:auto;max-width:20px;" /></a></h2><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">MySQL 이 8로 업그레이드되면서 패스워드 정책이 더 깐깐해졌습니다.</p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">DBMS 이니 보안에 더 충실해진 면도 있고 어떻게 보면 예전 버전들이 너무 보안에 신경 안 쓴 부분도 꽤 있다고 생각합니다.</p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">운영 시스템이라면 이런 철저한 암호 정책을 따라야 겠지만 로컬이나 개발 환경에서는 이런 정책을 다 따르기 어려운 부분이 있습니다.</p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><h2 style="margin-right:0px;margin-bottom:12px;margin-left:0px;padding:0px;color:rgb(0,12,52);font-weight:normal;font-size:34px;line-height:1.1;letter-spacing:0.25px;font-family:'roboto-regular', Helvetica, Roboto, Arial, sans-serif;border-bottom-color:rgb(255,255,255);width:686.125px;margin-top:24px;">변경된 암호 정책<a class="js-anchor article__content__content__anchor" href="https://www.lesstif.com/dbms/mysql-8-password-policy-89555994.html#MySQL8%EC%95%94%ED%98%B8%EC%A0%95%EC%B1%85(Passwordpolicy)%ED%99%95%EC%9D%B8%EB%B0%8F%EC%88%98%EC%A0%95%ED%95%98%EA%B8%B0-%EB%B3%80%EA%B2%BD%EB%90%9C%EC%95%94%ED%98%B8%EC%A0%95%EC%B1%85" style="color:rgb(0,82,204);line-height:inherit;height:100%;padding-left:1rem;padding-right:1rem;vertical-align:middle;" rel="nofollow"><img class="article__content__content__anchor--link-icon" src="https://www.lesstif.com/dbms/_/AC1F142D0171445D13DC476E4B36792B/1602581193540/images/common/link-solid.svg" alt="Link to 변경된 암호 정책" style="margin:0px 0px 3px;padding:0px;border:0px;vertical-align:middle;height:auto;max-width:20px;" /></a></h2><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">5.7 이전까지 버전은 암호 정책을 낮추려면 다음 설정을 mysql 설정 파일에 추가하고 재구동하면 됐습니다.</p><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-none" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-$params.language language-none" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">validate_password_policy=LOW
default_password_lifetime=0<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">8 에서는 저 옵션이 안 먹어서 <em style="line-height:inherit;">SHOW VARIABLES LIKE 'validate_password%</em> 로 확인해 보니 아래와 같이 validate_password 뒤에 _ 문자가 . 으로 변경이 되었습니다. 즉 <em style="line-height:inherit;">validate_password_policy</em> 는 <em style="line-height:inherit;">validate_password.policy</em> 로 바뀌줘야 합니다.</p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">아마 설정을 더 체계적으로 관리하기 위해 도입한 방법인 것 같은데 <em style="line-height:inherit;">default_password_lifetime</em> 는 그대로 입니다.</p><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-sql" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-sql" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">mysql&gt; SHOW VARIABLES LIKE 'validate_password.%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+

<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><div class="expand-container conf-macro output-block" style="margin:1rem 0px;padding:0px;font-size:16px;"><div class="expand-control" style="margin:0px 0px 10px;padding:0px;"><span class="expand-icon aui-icon aui-icon-small aui-iconfont-chevron-right" style="background-repeat:no-repeat;background-position:0px 0px;border:none;height:16px;margin:0px;padding:0px;text-indent:-999em;vertical-align:text-bottom;width:16px;"> </span><span class="expand-control-text" style="vertical-align:top;color:rgb(0,82,204);">여기를 클릭하여 펼치기...</span></div></div><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">8.0 에서 qwert123 같은 암호를 사용하려면 다음 내용을 mysql 설정 파일에 넣어주고 재구동하면 됩니다.</p><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-bash" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-bash" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">echo 'validate_password.policy=LOW' | sudo tee -a /etc/my.cnf
echo 'default_password_lifetime=0' | sudo tee -a /etc/my.cnf<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-bash" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-bash" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">echo 'validate_password.policy=LOW' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
echo 'default_password_lifetime=0' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br /></p><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;">추가로 암호 자릿수 제한, 특수 문자 포함 여부, 대소문자 구분, 숫자 포함 여부를 모두 끄려면 아래 내용을 추가해 주고 재구동해주면 됩니다.</p><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-bash" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-bash" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">echo 'validate_password.length=6' | sudo tee -a /etc/my.cnf
echo 'validate_password.special_char_count=0' | sudo tee -a /etc/my.cnf
echo 'validate_password.mixed_case_count=0' | sudo tee -a /etc/my.cnf
echo 'validate_password.number_count=0' | sudo tee -a /etc/my.cnf<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><div class="code-toolbar" style="margin:0px;padding:1.5rem 0px 0px;font-size:16px;background-color:rgb(244,245,247);"><pre class="conf-macro output-block line-numbers language-bash" style="margin-top:0.5em;margin-bottom:0.5em;padding:1em 1em 1em 3.8em;font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;background:rgb(45,45,45);color:rgb(204,204,204);line-height:1.5;word-spacing:normal;"><code class="language-bash" style="font-family:Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;font-size:1em;border:none;background:none;max-width:100%;padding:0px;line-height:1.5;white-space:inherit;word-spacing:normal;">echo 'validate_password.length=6' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
echo 'validate_password.special_char_count=0' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
echo 'validate_password.mixed_case_count=0' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf
echo 'validate_password.number_count=0' | sudo tee -a /etc/mysql/mysql.conf.d/mysqld.cnf<span class="line-numbers-rows" style="width:3em;letter-spacing:-1px;border-right:1px solid rgb(153,153,153);"><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span><span style="font-size:inherit;"></span></span></code></pre><div class="toolbar" style="margin:0px;padding:0px;"><div class="toolbar-item" style="margin:0px;padding:0px;"><a style="color:rgb(151,160,175);background:transparent;line-height:inherit;font-size:14px;padding:0px 0.5em;">Copy</a></div></div></div><p style="margin-top:10px;font-size:16px;line-height:1.6;letter-spacing:0.5px;max-width:100%;"><br style="color:rgb(23,43,77);font-family:'-apple-system', BlinkMacSystemFont, Roboto, 'Apple SD Gothic Neo', 'Nanum Barun Gothic', Oxygen, 'Segoe UI', Ubuntu, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;background-color:rgb(254,254,254);" /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2020-10-16T15:23:49+09:00</dc:date>
</item>


<item>
<title>mysql concat 개행</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=999</link>
<description><![CDATA[<p>기존 내용을 유지하면서 개행(\n) 으로 구분하여 내용(컬럼)을 업데이트 하는경우 예시<br /></p><p><br /></p><p>update tableName set</p><p>    field1 = concat(if(isnull(field1), '', concat(field1, '\n')), '추가되는 내용')</p><p>    where uid = 1</p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2020-04-03T16:27:53+09:00</dc:date>
</item>


<item>
<title>MySQL explain 명령에 대한 type 컬럼 설명</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=998</link>
<description><![CDATA[<p>MySQL explain 명령에 대한 type 컬럼 설명은 다음과 같습니다.</p><p><br /></p><p>​</p><p><br /></p><p>* ALL</p><p><br /></p><p> - full table scan</p><p><br /></p><p> - MySQL 이 행을 찾기 위해 테이블의 처음부터 끝까지 스캔해야 한다는 것을 의미한다.</p><p><br /></p><p>​</p><p><br /></p><p>* index</p><p><br /></p><p> - index 순서로 스캔하므로 정렬할 필요가 없다는 장점이 있다.</p><p><br /></p><p> - 가장 큰 단점은 전체 테이블을 index 순서로 읽어들이는 비용에 있고 이는 임의의 순서로 행에 접근하는 데에 큰 비용이 필요하다는 의미이다.</p><p><br /></p><p> - Extra 컬럼에 "Using index" 가 출력된다면 MySQL 이 커버링 인덱스를 사용하게 되고, index 순서로 각 행을 읽는 것이 아니라 index 에 있는 데이터만을 스캔한다는 것을 의미하며 테이블을 index 순서로 스캔하는 것에 비해 비용이 적에 든다.</p><p><br /></p><p>​</p><p><br /></p><p>* range</p><p><br /></p><p> - index 의 특정 부분에서 시작해서 특정 범위에 있는 값을 가지는 행을 반환한다.</p><p><br /></p><p> - 전체 index 스캔보다 더 나은 성능을 보인다.</p><p><br /></p><p>​</p><p><br /></p><p>* ref</p><p><br /></p><p> - 어떤 값 하나에 대해 매치되는 행들을 반환해 주는 index 접근 방식이다.</p><p><br /></p><p>​</p><p><br /></p><p>* eq_ref</p><p><br /></p><p> - MySQL 이 기껏해야 값 하나만을 반환해준다는 것을 알고 있을 때 이런 index 탐색법이 사용되며, MySQL 이 쿼리를 실행하기 위해 참조 값을 기본 키 혹은 unique index 에 비교할 때 이런 접근 방법을 사용하는 것을 확인할 수 있다.</p><p><br /></p><p>​</p><p><br /></p><p>* const, system</p><p><br /></p><p> - 쿼리의 일부를 상수로 대체해서, 쿼리를 최적화할 수 있을 경우 MySQL 에서는 이런 접근 방법을 사용하게 된다.</p><p><br /></p><p> - WHERE 절에 기본 키를 이용해 검색하는 조건을 사용하는 경우 MySQL 에서는 쿼리를 상수로 바꿔버린 뒤 조인에서 테이블을 사실상 제거해 버린다.</p><p><br /></p><p>​</p><p><br /></p><p>* NULL</p><p><br /></p><p> - MySQL 이 최적화 단계에서 쿼리를 처리할 수 있으므로 실행 단계에서 index 나 테이블에 접근조차하지 않는다는 의미이다.</p><p><br /></p><p> - index 가 되어 있는 컬럼에서 최소값을 선택하려는 경우라면 index 만 찾아보면 되므로 실행 단계에서 테이블에 접근할 필요가 없다.</p><p><br /></p><p><br /></p><p><br /></p><p>출처 : <a href="https://blog.naver.com/websearch/221566114706" rel="nofollow">https://blog.naver.com/websearch/221566114706</a></p>]]></description>
<dc:creator>최고관리자</dc:creator>
<dc:date>2020-03-05T17:38:26+09:00</dc:date>
</item>


<item>
<title>MySQL 용량 큰 테이블 분할해서 dump</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=997</link>
<description><![CDATA[<p>[dump]</p><p>-w 옵션 사용 : 조건 입력</p><p>mysqldump -u [아이디] -p [DB명] [테이블명] -w "seq_id&lt;1000000 order by seq_id" &gt; backup_01.sql<br /></p><p>mysqldump -u [아이디] -p [DB명] [테이블명] -w "seq_id&gt;=1000000 order by seq_id" &gt; backup_02.sql<br /></p><p><br /></p><p>복구시</p><p><b><span style="color:rgb(255,0,0);">첫번째 파일 제외하고 아래 관련 구문 삭제 후 저장</span></b></p><p>DROP TABLE IF EXISTS `[테이블]`;</p><p>CREATE TABLE `[테이블]`<br /></p><p>.</p><p>.</p><p>.</p><p><br /></p><p><br /></p><p>[복구]</p><p>mysql -u [아이디] -p [DB명] &lt; backup_01.sql<br /></p><p>mysql -u [아이디] -p [DB명] &lt; backup_02.sql<br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2020-01-30T15:45:13+09:00</dc:date>
</item>


<item>
<title>MySQL UPDATE JOIN</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=996</link>
<description><![CDATA[<p style="margin-bottom:26px;font-family:'Open Sans', sans-serif;font-size:15px;background-color:rgb(255,255,255);">The syntax of the MySQL <code style="font-family:monospace, serif;font-size:0.9em;margin:0px;color:rgb(202,71,63);padding:0.25em;border:none;background:rgb(251,251,253);">UPDATE JOIN</code>  is as follows:</p><div class="crayon-syntax crayon-theme-coy-copied crayon-font-sourcecodepro crayon-os-pc print-yes notranslate crayon-wrapped" style="width:730px;padding:0px;margin:12px 0px;font-family:Monaco, MonacoRegular, 'Courier New', monospace;height:auto;font-size:14px;line-height:19px;border-width:1px;border-color:rgb(217,217,217);border-style:solid;background:rgb(248,248,248);"><div class="crayon-plain-wrap" style="background:0px center;border:0px;font-family:'Source Code Pro', 'source_code_proregular', Arial, sans-serif;padding:0px;margin:0px;height:auto;"></div><div class="crayon-main" style="background:0px center;border:0px;padding:0px;margin:0px;width:728px;font-family:'Source Code Pro', 'source_code_proregular', Arial, sans-serif;"><table class="crayon-table" style="font-size:12px;margin-left:0px;border-collapse:collapse;border-spacing:0px;background:none;border:none;margin-bottom:0px;width:auto;padding:0px;margin-right:0px;margin-top:0px;table-layout:auto;"><tbody><tr class="crayon-row" style="background:0px center;padding:0px;border:none;vertical-align:top;margin:0px;"><td class="crayon-nums" style="border-bottom:0px;border-top:0px;border-left:0px;padding:0px 0px 0px 1em;vertical-align:top;margin:0px;background:rgb(255,255,255);border-right:2px solid rgb(134,225,89);"><div class="crayon-nums-content" style="background:0px center;border:0px;padding-right:0px;padding-left:0px;margin:0px;white-space:nowrap;padding-top:5px;padding-bottom:3px;font-size:14px;line-height:19px;"><div class="crayon-num" style="font-family:inherit;background:0px center;border-top:0px;border-right:1px solid rgb(222,222,222);border-bottom:0px;border-left:0px;padding:0px 5px;margin:0px;text-align:right;height:19px;min-width:1.2em;color:rgb(170,170,170);">1</div><div class="crayon-num" style="font-family:inherit;background:0px center;border-top:0px;border-right:1px solid rgb(222,222,222);border-bottom:0px;border-left:0px;padding:0px 5px;margin:0px;text-align:right;height:19px;min-width:1.2em;color:rgb(170,170,170);">2</div><div class="crayon-num" style="font-family:inherit;background:0px center;border-top:0px;border-right:1px solid rgb(222,222,222);border-bottom:0px;border-left:0px;padding:0px 5px;margin:0px;text-align:right;height:19px;min-width:1.2em;color:rgb(170,170,170);">3</div><div class="crayon-num" style="font-family:inherit;background:0px center;border-top:0px;border-right:1px solid rgb(222,222,222);border-bottom:0px;border-left:0px;padding:0px 5px;margin:0px;text-align:right;height:19px;min-width:1.2em;color:rgb(170,170,170);">4</div><div class="crayon-num" style="font-family:inherit;background:0px center;border-top:0px;border-right:1px solid rgb(222,222,222);border-bottom:0px;border-left:0px;padding:0px 5px;margin:0px;text-align:right;height:19px;min-width:1.2em;color:rgb(170,170,170);">5</div></div></td><td class="crayon-code" style="border:0px;background:0px center;width:695px;padding:0px;vertical-align:top;margin:0px;"><div class="crayon-pre" style="padding-right:0px;padding-left:0px;margin:0px;white-space:pre;background:none;border:none;padding-top:5px;padding-bottom:3px;color:rgb(68,88,112);font-size:14px;line-height:19px;"><div class="crayon-line" style="font-family:inherit;background:0px center;border:0px;padding:0px 5px;margin:0px;height:inherit;white-space:pre-wrap;"><span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">UPDATE</span><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T1,<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T2,</div><div class="crayon-line" style="font-family:inherit;background:0px center;border:0px;padding:0px 5px;margin:0px;height:inherit;white-space:pre-wrap;">[<span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">INNER JOIN</span><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>|<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span><span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">LEFT JOIN</span>]<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T1<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span><span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">ON</span><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T1.C1<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>=<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T2.<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>C1</div><div class="crayon-line" style="font-family:inherit;background:0px center;border:0px;padding:0px 5px;margin:0px;height:inherit;white-space:pre-wrap;"><span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">SET</span><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T1.C2<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>=<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>T2.C2,<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span></div><div class="crayon-line" style="font-family:inherit;background:0px center;border:0px;padding:0px 5px;margin:0px;height:inherit;white-space:pre-wrap;"><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);">    </span>T2.C3<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>=<span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span>expr</div><div class="crayon-line" style="font-family:inherit;background:0px center;border:0px;padding:0px 5px;margin:0px;height:inherit;white-space:pre-wrap;"><span class="crayon-st" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">WHERE</span><span class="crayon-h" style="font-family:inherit;height:inherit;color:rgb(0,111,224);"> </span><span class="crayon-r" style="font-family:inherit;height:inherit;color:rgb(0,119,170);">condition</span></div></div></td></tr></tbody></table></div></div>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2019-11-13T17:11:32+09:00</dc:date>
</item>


<item>
<title>[펌] MySQL 대용량 DBMS 개선 사례</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=995</link>
<description><![CDATA[<p>원글</p><p><a href="http://www.joshi.co.kr/index.php?mid=board_iuyq53&amp;document_srl=305356" rel="nofollow">http://www.joshi.co.kr/index.php?mid=board_iuyq53&amp;document_srl=305356</a><b> </b></p><p><b><br /></b></p><p><b><br /></b></p><p><b>​</b><span style="font-family:'나눔고딕', NanumGothic, ng;font-size:13px;">최근 IT 비용 절감으로 인하여, 오픈 소스 소프트웨어 적용 비율이 높아지고 있는데, DB 쪽도 예외가 아닙니다.</span> </p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">비용이 그다지 문제가 되지 않는다면, Oracle Exadata를 구매해서 사용해보면 국내 웬만한 서비스들은 다 커버가능하지 않을까<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">하는 희망찬 꿈에 빠져보기도 하지만, 서비스 운영 시 비용은 반드시 고려해야할 난관입니다.<br />IT 비용을 절감하기 위해서, 물론 장비 도입 시기부터 결정하는 방법도 있겠지만,</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><span><span style="font-weight:700;">기존 장비를 오픈소스 소프트웨어(Oracle to MySQL)로 데이터 이관해야하는 경우</span></span>도 있습니다.<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">오늘 제가 말씀드리고 싶은 사항은 기존 Oracle로 구현되어 있던 솔루션을 MySQL로 포팅한 사례이며, MySQL로 서비스 후<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">나날이 성능 저하 현상이 발생한 원인과 개선 방안에 관한 내용입니다.<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">아무래도 솔루션인지라, 쉽게 Application을 변경하기 어려운 상황이고, 기존 구조를 거의 그대로 유지해야 하므로,<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">기존 SQL튜닝과는 다른 방향으로 문제를 해결하였습니다.</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><h1 style="font-size:18px;margin:20px 0px 10px;font-weight:normal;line-height:1.1;color:rgb(0,165,213);font-family:ngBold;"><span style="font-weight:700;">성능 저하 요소 분석</span></h1><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">통계 분석 시간이 시간이 지날수록 크게 소요되는 현상과 데이터 저장을 위한 디스크 사용 효율이 시간이 지남에 따라<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">나날이 떨어지는 현상이 발생하였습니다.<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">디스크는 사용량은 300G를 데이터 영역으로 사용 중이었고, 일부 테이블에서는 인덱스 파일 사이즈가 데이터 파일 사이즈보다<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">큰 현상도 존재하였습니다.<br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">다음은 개선 전 테이블이 사용하는 디스크 실제 크기입니다.</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><img width="637" height="226" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/376276e01148f6d2a09301a6dc85f5f9.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /> </p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><a class="con_link" href="http://dev.paran.com/2011/06/10/mysql-innodb-engine-3-tips-you-must-know/" target="_blank" style="background-position:0px 0px;background-size:initial;color:rgb(0,165,213);" rel="nofollow noreferrer noopener">InnoDB특성을 고려</a>하여 통계 DB의 성능 저하 원인을 다음과 같이 분석 하였습니다.</p><ul style="margin-top:0px;margin-bottom:10px;font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><li style="margin:10px 0px;"><span style="font-weight:700;">InnoDB Cluster Index (Primary Key) 로 인한 디스크 I/O</span></li><li style="margin:10px 0px;"><span style="font-weight:700;">InnoDB Secondary Index 구조 특성에 따른 인덱스 사이즈 거대화</span></li><li style="margin:10px 0px;"><span style="font-weight:700;">디스크 공간이 재사용되지 않아서 발생하는 저장 공간 낭비</span></li><li style="margin:10px 0px;"><span style="font-weight:700;">250G 한 개 파일로 inndb file이 생성되어 있어서 관리가 어려움</span></li><li style="margin:10px 0px;"><span style="font-weight:700;">이 외 Replication 관련 버그 Fix되기 버전 사용으로 인한 안정성 이슈</span></li></ul><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><h1 style="font-size:18px;margin:20px 0px 10px;font-weight:normal;line-height:1.1;color:rgb(0,165,213);font-family:ngBold;"><span style="font-weight:700;">DB 성능 최적화 적용</span></h1><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">DBMS 성능 최적화 활동InnoDB 특성을 고려하여 다음과 같이 최적화 활동을 진행하였습니다.</p><ol style="margin-top:0px;margin-bottom:10px;font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><li style="margin:10px 0px;"><span><span style="font-weight:700;">통계 쿼리 실행 최적화를 위해 Monthly Partitioning을 Daily Partitioning으로 변경</span></span><br />Primary Key 순으로 데이터가 순차 저장되지 않는 구조이기 때문에 DISK I/O가 크게 발생하였고, 기존 테이블 구조를 변경하기는 불가했습니다. Partitioning 관리를 월별에서 일별로 변경함으로써 기존 발생하던 DISK I/O이슈를 최소화하였습니다.자동 파티셔닝 관리를 위해 별도 Shell Script 작성</li><li style="margin:10px 0px;">Primary Key 및 Secondary Key 재구성<br />일별 Partitioning 적용된 로그성 테이블에는 Primary Key를 제거 및 날짜 관련 인덱스 제거하여, 디스크 공간 사용 최소화<br />(통계 처리 시 1일 단위로 처리되므로, 인덱스가 굳이 불필요함)</li><li style="margin:10px 0px;"><span><span style="font-weight:700;">로그 성 테이블 외 대용량 테이블은 Hash Partitioning을 활용하여 물리적으로 분리</span></span><br />로그 성 테이블을 제외한 테이블(일자 별 관리가 어려운 테이블)은 Primary Key 값을 기준으로 Hash Partitioning을 적용하여 물리적으로 분리하여 InnoDB Primary Key 유지를 위한 DISK I/O 발생 이슈를 최소화하였습니다.</li><li style="margin:10px 0px;"><span><span style="font-weight:700;">한 개 파일로 관리되고 있는 innodb file을 innodb_file_per_table 옵션을 적용</span></span><br />autoextend 옵션으로 innodb file유지 시 저장 공간 반환이 되지 않기 때문에 재사용되지 않습니다. autoextend 옵션 없이 innodb file 유지 시 추후 innodb tablespace 공간 확장 시 DB를 shutdown후 작업을 해야하는 이슈가 발생하기 때문에 innodb_file_per_table 옵션을 활용하여 테이블 별로 저장 공간을 할당하였습니다.</li><li style="margin:10px 0px;"><span><span style="font-weight:700;">Archive Storage 엔진 사용하여 과거 데이터 백업 관리</span></span><br />45일 이전 데이터는 다른 Database에 Archive Storage Engine 테이블에 백업 후 해당 일자 파티션 삭제하여 디스크 비효율을 제거하였습니다. Archive Storage Engine을 사용하게 되면 InnoDB 대비 1/5 정도 용량을 차지고, 인덱스를 제거하여 백업 데이터 유지한 결과 기존 대비 1/10 정도 Disk 공간으로 과거 데이터를 보관할 수 있습니다.</li><li style="margin:10px 0px;"><span><span style="font-weight:700;">MySQL 5.1.57 으로 버전 Upgrade하여 <a class="con_link" href="http://dev.paran.com/2011/05/25/mysql-replication-fail-bug-1032-error-resolution/" target="_blank" style="background-position:0px 0px;background-size:initial;color:rgb(0,165,213);" rel="nofollow noreferrer noopener">Replication Fail Error </a>방지</span></span></li></ol><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">다음은 파티셔닝 관리를 위해 나름 작성한 shell 스크립트입니다. shell 스크립트에 아직 익숙하지가 않은지라, 마음에 확 와닿게 짜지는 못했네요..^^;;</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><table class="__se_tbl" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;border-spacing:0px;max-width:100%;line-height:1.5;border-width:1px 1px 0px 0px;border-style:solid solid none none;border-color:rgb(204,204,204) rgb(204,204,204);font-family:'나눔고딕', NanumGothic, ng;"><tbody><tr><td width="677" style="padding:0px;font-size:13px;border-width:0px 0px 1px 1px;border-style:none none solid solid;border-color:rgb(204,204,204) rgb(204,204,204);background-color:rgb(255,255,255);"><p>#!/bin/sh<br />MYSQL_HOME="/usr/local/server/mysql"<br />EXECUTE_QUERY="$MYSQL_HOME/bin/mysql -u아이디 -p패스워드 -e "<br /><br />## 서버 목록 배열 "table명:파티셔닝필드" 로 정의<br /><br />SERVERS=(<br /><br />"tb01:field01"<br />"tb02:field02"<br />"tb03:field03"<br />"tb04:field04"<br />"tb05:field05"<br />"tb06:field06"<br /><br />)<br /><br />new_sdays=$1<br />new_edays=`expr $new_sdays + 1`<br /><br />del_sdays=$2<br />del_edays=`expr $del_sdays - 1`<br /><br />new_sdate=`date -d "+$new_sdays days" +%Y%m%d`<br />new_edate=`date -d "+$new_edays days" +%Y%m%d`<br />del_sdate=`date -d "-$del_sdays days" +%Y%m%d`<br />del_edate=`date -d "-$del_edays days" +%Y%m%d`<br /><br />for INFO in ${SERVERS[@]}<br />do<br /><br />tbl=`echo $INFO | cut -d: -f1`<br />col=`echo $INFO | cut -d: -f2`<br /><br />## 신규 파티션 생성<br />query=" ALTER TABLE mstat.$tbl<br />REORGANIZE PARTITION P_MAX into (<br />PARTITION P_$new_sdate VALUES LESS THAN (TO_DAYS('$new_edate')),<br />PARTITION P_MAX VALUES LESS THAN MAXVALUE<br />)"<br />$EXECUTE_QUERY "$query"<br /><br />## 데이터 다른 DB로 복사<br />query=" INSERT INTO 백업디비.$tbl<br />select * from mstat.$tbl<br />where $col &gt;= '$del_sdate'<br />and $col &lt; '$del_edate' "<br />$EXECUTE_QUERY "$query"<br /><br />## 파티션 삭제<br />query=" ALTER TABLE 통계디비.$tbl DROP PARTITION P_$del_sdate"<br />$EXECUTE_QUERY "$query"<br />done<br /></p></td></tr></tbody></table><br /><br /><div class="story-content"><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">실행은 다음과 같이 합니다.</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">## 2일 후의 파티션 선행 생성 및 45일 이전 데이터 백업 후 삭제</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">./start_partition.sh 2 45</p></div><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><h1 style="font-size:18px;margin:20px 0px 10px;font-weight:normal;line-height:1.1;color:rgb(0,165,213);font-family:ngBold;"><span style="font-weight:700;">DB성능 최적화 결과</span></h1><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">결과에 관한 요약은 다음과 같습니다. 그래프는 MySQL Enterprise Monitoring 에서 추출하였고, 동일 날짜 통계 추출 데이터 실행</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;">결과입니다.<br />개선 전/후 모두 6시간에 관한 모니터링 결과를 뽑아낸 것으로 가시적으로 실행시간이 단축된 것을 확인할 수 있습니다.<br />아직 SQL튜닝은 진행하지 않았기 때문에, 통계 TOP SQL 일부를 튜닝한다면 적어도 60분 이내로 가능하지 않을까 생각이 드네요.^^</p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><img width="599" height="129" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/f966307821734950bb49843e872e9dc3.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><img width="625" height="425" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/999a0e3032076fe74ab93bf08eb7b9c0.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /><br /><br /><br /><img width="621" height="424" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/ad778354fc73c40d6dbf773d1284eddd.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /><br /><br /><img width="605" height="409" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/ee06b26e4d3b234c9014fdf7590218f2.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><br /></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><span style="font-weight:700;">테이블 사이즈 순 상위 15개 테이블 저장 공간 비교</span></p><p style="font-size:13px;font-family:'나눔고딕', NanumGothic, ng;"><img width="740" height="363" class="_photoImage" alt="" src="http://www.joshi.co.kr/files/attach/images/134/356/305/500f846d9bd621de8371d3dc97bb22bd.png" style="border:0px;vertical-align:middle;max-width:818px;height:auto;" /></p><div class="autosourcing-stub-extra"><p style="margin-top:11px;margin-bottom:7px;font-family:Dotum;"><br style="font-family:'나눔고딕', NanumGothic, ng;background-color:rgb(255,255,255);" /></p></div>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2019-10-29T10:08:34+09:00</dc:date>
</item>


<item>
<title>양력 음력 간지 공휴일 MySQL DB 테이블</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=994</link>
<description><![CDATA[<p>양력 음력 간지 공휴일 MySQL DB 테이블<br /></p><p><br /></p><p>MySQL 5 이상 (MariaDB) UTF-8, MyISAM 엔진</p><p><br /></p><p>1900-01-01 ~ 2200-12-31 까지 데이터</p><p><br /></p><p><br /></p><p style="color:rgb(51,51,51);font-family:'Apple SD Gothic Neo', 'Malgun Gothic', '맑은 고딕', Dotum, '돋움', 'Noto Sans KR', 'Nanum Gothic', Lato, Helvetica, sans-serif;font-size:14px;"><a href="https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=download&amp;wr_id=16893" target="_blank" class="tx-link" style="color:rgb(102,102,102);" rel="nofollow noreferrer noopener">https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=download&amp;wr_id=16893</a></p><p style="color:rgb(51,51,51);font-family:'Apple SD Gothic Neo', 'Malgun Gothic', '맑은 고딕', Dotum, '돋움', 'Noto Sans KR', 'Nanum Gothic', Lato, Helvetica, sans-serif;font-size:14px;">상기 데이터 참고후 수정한 자료</p><p><br /></p><p><br /></p><p>-- num : 등록순번</p><p>-- lunar_date : 음력일자 (0000-00-00 형식)</p><p>-- solar_date : 양력일자 (0000-00-00 형식)</p><p>-- yun : 윤달여부 (0 : 평달, 1 :윤달)</p><p>-- ganji : 간지</p><p>-- memo : 공휴일 (연휴적용)</p><p>--</p><p>-- 공휴일 구분 (2013년 ~ 기준)</p><p>-- 신정</p><p>-- 설날</p><p>-- 3·1절</p><p>-- 어린이날</p><p>-- 석가탄신일</p><p>-- 제헌절 ? 국경일이지만 법정공휴일 제외</p><p>-- 광복절</p><p>-- 추석</p><p>-- 개천절</p><p>-- 한글날</p><p>-- 성탄절</p><p><br /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2019-09-19T15:50:22+09:00</dc:date>
</item>


<item>
<title>MySQL 쓰면서 하지 말아야 할 것 17가지</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=993</link>
<description><![CDATA[<p>출처 : <a href="https://blog.lael.be/post/370" rel="nofollow">https://blog.lael.be/post/370</a></p><p><br /></p><p>*MySQL 쓰면서 하지 말아야 할 것 17가지*</p><p>권장사항이다. 이것을 이해하면 당신의 어플리케이션이 더 나은 성능을 발휘할 것이다.</p><p><br /></p><p>다만 이것이 사람의 실력을 판단하는 척도로 사용되서는 안 될 것이다.</p><p><br /></p><p> </p><p><br /></p><p>작게 생각하기</p><p>- 조만간 규모가 커질거라면 MySQL ecosystem을 봐야된다.</p><p>- 그리고 캐싱 빡시게 안 하는 메이저 웹사이트는 없다.</p><p>- develooper.com의 Hansen PT랑 Ilia 튜토리얼 볼 것</p><p>- 처음부터 확장 가능하게 아키텍처 잘 쪼개놔야된다.</p><p>- 복제랑 파티셔닝 어떻게 할지 미리 계획 세워놔라.</p><p>- 파일 기반 세션 좀 쓰지마 -_-</p><p>- 그렇다고 너무 쓸데없이 크게 생각하지도 말 것</p><p>- 특히 성능하고 확장성 구분 못 하면 난감함</p><p><br /></p><p> </p><p><br /></p><p>EXPLAIN 안 써보기</p><p>- SELECT 앞에 EXPLAIN 이라고 붙이기만 하면 되는 것을 (..)</p><p>- 실행 계획 확인</p><p>- 타입 컬럼에 index 써있는거랑 Extra 컬럼에 index 써있는거랑 “매우 큰” 차이 있음</p><p>* 타입에 있으면 Full 인덱스 스캔 (안 좋다.)</p><p>* Extra 컬럼에 있으면 Covering 인덱스 찾았다는 의미임 (좋다!)</p><p>- 5.0 이후부터는 index_merge 최적화도 한다.</p><p><br /></p><p> </p><p><br /></p><p>잘못된 데이터 타입 선택</p><p>- 한 메모리 블럭 단위에 인덱스 레코드가 많이 들어갈수록 쿼리가 빨리 실행될 것이다. (중요)</p><p>- 아.. 정규화 좀 해 -_-… (이거 정말 충격과 공포인 듯)</p><p>- 가장 작은 데이터 타입을 써.. (진짜 BIGINT가 필요하냐고..)</p><p>- 인덱스 걸리는 필드는 정말 최소한으로 데이터 크기를 써야된다고.</p><p>- IP는 INT UNSIGNED로 저장해!! (아주 공감)</p><p>* 이럴 때 쓰라고 INET_ATON 함수가 아예 내장되어 있음.</p><p><br /></p><p> </p><p><br /></p><p>PHP에서 pconnect 쓰는 짓</p><p>- 아파치에서 좀비 프로세스라도 생기면 그 커넥션은 그냥 증발하는거야..</p><p>- 어차피 MySQL 접속 속도는 Oracle이나 PostgreSQL 보다 10~100배 빠르다고.</p><p><br /></p><p>너무 과도한 DB 추상화 계층을 두는 것</p><p>- 어디 포팅 열심히 할 거 아니면 추상화 계층 쓰지마 (ADODB, MDB2, PearDB 등)</p><p>- scale out 가능한걸 쓰라고.</p><p> </p><p><br /></p><p>스토리지 엔진 이해 못 하는 것</p><p>- 단일 엔진만으로 전체 아키텍처를 결정했다면 대부분 최적이 아님</p><p>- 엔진 별 장단점을 공부할 것</p><p>- ARCHIVE : zlib으로 압축해주고 UPDATE 안 되고 로그 Bulk Insert에 유용함.</p><p>- MEMORY : 서버 재시작하면 증발. 인덱스가 HASH나 BTREE로 가능함. 임시, 요약 데이터에 사용.</p><p>* 주간 top X 테이블 같은 것.</p><p>* 하여튼 메모리에 박아넣고 싶은 데이터 있으면..</p><p><br /></p><p> </p><p><br /></p><p>인덱스 레이아웃 이해 못 하는 것</p><p>- 제대로 인덱스랑 스토리지 엔진 선택하려면 공부 좀 해</p><p>- 엔진은 데이터와 인덱스 레코드를 메모리나 디스크에 레이아웃하는 걸 구현한 것</p><p>- clustered 구성은 데이터를 PK 순서에 따라 저장함.</p><p>- non-clustered 구성은 인덱스만 순서대로 저장하고 데이터는 순서 가정하지 않음.</p><p>- clustered에서는 인덱스만 타면 추가적인 조회 없이 바로 데이터 가져오는 것임.</p><p>- 그래서 clustered PK는 작은 놈으로 할 필요가 있다는거</p><p>* 다른 인덱스는 각 레코드마다 PK를 앞에 더 붙이게 되니까.</p><p>* PK 지정 안 하면 아무렇게나 해버림</p><p><br /></p><p> </p><p><br /></p><p>쿼리 캐시 이해 못 하는 것</p><p>- 어플리케이션 read/write 비율은 알고 있어야지</p><p>- 쿼리 캐시 설계는 CPU 사용과 읽기 성능 간의 타협</p><p>- 쿼리 캐시 크기를 늘린다고 읽기 성능이 좋아지는게 아님. heavy read라도 마찬가지.</p><p>- 과도한 CPU 사용을 막기 위해 무효화 할 때는 캐시 항목들을 뭉텅이로 날려버림</p><p>- 한마디로 SELECT가 참조하는 테이블 데이터 하나라도 변경되면 그 테이블 캐시는 다 날라간다는 얘기임</p><p>- 수직 테이블 파티셔닝으로 처방</p><p>* Product와 ProductCount를 쪼갠다든지..</p><p>* 자주 변하는 것과 변하지 않는 것을 쪼개는게 중요하다 이 말임.</p><p><br /></p><p> </p><p><br /></p><p>Stored Procedure를 쓰는 것</p><p>- 무조건 쓰면 안 된다는게 아니고..</p><p>- 컴파일 할 때 무슨 일이 일어나는지 이해 못 하고 쓰면 재앙이 된다 이 말.</p><p>- 다른 RDBMS랑 다르게 connection thread에서 실행 계획이 세워짐.</p><p>- 이게 뭔 얘기냐 하면 데이터 한 번 가져오고 연결 끊으면 그냥 CPU 낭비 (7~8% 정도)하는 꼴이라는 것.</p><p>- 웬만하면 Prepared 구문과 Dynamic SQL을 써라.. 아래 경우를 제외하고</p><p>* ETL 타입 프로시저</p><p>* 아주아주 복잡하지만 자주 실행되지는 않는 것</p><p>* 한 번 요청할 때마다 여러번 실행되는 간단한 것 (연결한 상태로 여러번 써야 된다니까)</p><p><br /></p><p> </p><p><br /></p><p>인덱스 컬럼에 함수 쓰는 것</p><p>- 함수에 인덱스 컬럼 넣어 호출하면 당연히 인덱스 못 탄다</p><p>- 함수를 먼저 계산해서 상수로 만든 다음에 = 로 연결해야 인덱스 탈 수 있다.</p><p>* 여기 실행 계획 보면 LIKE도 range type 인덱스 타는 것 보임</p><p><br /></p><p> </p><p><br /></p><p>인덱스 빼먹거나 쓸모없는 인덱스 만들어 놓는 것</p><p>- 인덱스 분포도(selectivity)가 허접하면 안 쓴다.</p><p>- S = d/n</p><p>* d = 서로 다른 값의 수 (# of distinct values)</p><p>* n = 테이블의 전체 레코드 수</p><p>- 쓸모없는 인덱스는 INSERT/UPDATE/DELETE를 느리게 할 뿐..</p><p>- FK는 무조건 인덱스 걸어라. (물론 FK 제약 걸면 인덱스 자동으로 생긴다.)</p><p>- WHERE나 GROUP BY 표현식에서 쓰이는 컬럼은 인덱스 추가를 고려할 것</p><p>- covering index 사용을 고려할 것</p><p>- 인덱스 컬럼 순서에 유의할 것!</p><p><br /></p><p> </p><p><br /></p><p>join 안 쓰는 짓</p><p>- 서브쿼리는 join으로 재작성해라</p><p>- 커서 제거해라</p><p>- 좋은 Mysql 성능을 내려면 기본</p><p>- 집합 기반으로 생각해야지 루프 돌리는거 생각하면 안 된다.</p><p><br /></p><p> </p><p><br /></p><p>Deep Scan 고려하지 않는 것</p><p>- 검색엔진 크러울러가 쓸고 지나갈 수 있다.</p><p>- 이 경우 계속해서 전체 집합을 정렬한 다음 LIMIT로 가져와야 하니 무진장 느려진다.</p><p>- 어떻게든 집합을 작게 줄인 다음 거기서 LIMIT 걸어 가져올 것</p><p><br /></p><p> </p><p><br /></p><p>InnoDB 테이블에서 WHERE 조건절 없이 SELECT COUNT(*) 하는 짓</p><p>- InnoDB 테이블에서는 조건절 없이 COUNT(*) 하는게 느리다.</p><p>- 각 레코드의 transaction isolation을 유지하는 MVCC 구현이 복잡해서 그렇다는..</p><p>- 트리거 걸어서 메모리 스토리지 엔진 쓰는 테이블에 통계를 별도로 유지하면 된다.</p><p><br /></p><p> </p><p><br /></p><p>프로파일링이나 벤치마킹 안 하는 것</p><p>- 프로파일링 : 병목 찾아내기</p><p>- 벤치마킹 : 시간에 따른 성능 변화 추이 평가, 부하 견딜 수 있는지 테스트</p><p>- 프로파일링 할 때는 실제 데이터를 옮겨와서 할 것</p><p>- 어디가 병목이냐~ Memory? Disk I/O? CPU? Network I/O? OS?</p><p>- 느린 쿼리 로그로 남기기</p><p>* log_slow_queries=/path/to/log</p><p>* log_queries_not_using_indexes</p><p>- 벤치마킹 시에는 다 고정시키고 변수 하나만 바꿔가면서 해야 함. (쿼리 캐시는 끌 것.)</p><p>- 도구를 써라~~</p><p>* EXPLAIN</p><p>* SHOW PROFILE</p><p>* MyTop/innotop</p><p>* mysqlslap</p><p>* MyBench</p><p>* ApacheBench (ab)</p><p>* super-smack</p><p>* SysBench</p><p>* JMeter/Ant</p><p>* Slow Query Log</p><p><br /></p><p> </p><p><br /></p><p>AUTO_INCREMENT 안 쓰는 것</p><p>- PK를 AUTO_INCREMENT로 쓰는건 무진장 최적화 되어 있음</p><p>* 고속 병행 INSERT 가능</p><p>* 잠금 안 걸리고 읽으면서 계속 할 수 있다는!</p><p>- 새 레코드를 근처에 놓음으로써 디스크와 페이지 단편화를 줄임</p><p>- 메모리와 디스크에 핫 스팟을 생성하고 스와핑을 줄임</p><p><br /></p><p> </p><p><br /></p><p>ON DUPLICATE KEY UPDATE를 안 쓰는 것</p><p>- 레코드가 있으면 업데이트하고 없으면 인서트하고 이런 코드 필요없다!! 다 날려버려라!!</p><p>- 서버에 불필요하게 왔다갔다 할 필요가 없어짐</p><p>- 5-6% 정도 빠름</p><p>- 데이터 입력이 많다면 더 커질 수 있음</p><p>하지 말아야 할 것 총정리</p><p>Thinking too small</p><p>Not using EXPLAIN</p><p>Choosing the wrong data types</p><p>Using persistent connections in PHP</p><p>Using a heavy DB abstraction layer</p><p>Not understanding storage engines</p><p>Not understanding index layouts</p><p>Not understanding how the query cache works</p><p>Using stored procedures improperly</p><p>Operating on an indexed column with a function</p><p>Having missing or useless indexes</p><p>Not being a join-fu master</p><p>Not accounting for deep scans</p><p>Doing SELECT COUNT(*) without WHERE on an InnoDB table</p><p>Not profiling or benchmarking</p><p>Not using AUTO_INCREMENT</p><p>Not using ON DUPLICATE KEY UPDATEK</p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2018-12-17T16:21:05+09:00</dc:date>
</item>


<item>
<title>mysql index의 order by desc 문제</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=992</link>
<description><![CDATA[<p>문제: </p><p>mysql에서 order by desc를 사용하면 성능이 급격히 낮아지는 경우가 있는데,</p><p>이유는 index를 역순으로 저장하는 방식을 mysql은 지원하지 않기 때문이다.</p><p>그래서 (key1 desc, key2 asc)와 같은 결합인덱스를 생성할 때 문제가 발생할 수 있다.</p><p><br /></p><p>문제 해결책 :</p><p>이런 문제를 해결하는 방법은 정렬 column 값에 -1을 곱해서 table에 넣어버려서 추후 order by asc로 해결하는 패턴을 많이 사용한다.</p><p><br /></p><p>심화문제 :</p><p>하지만 </p><p>desc 정렬 column이 auto_increment로 생성되는 값이라면 조금 더 복잡해진다.</p><p>심화문제 해결책 1 :</p><p>매우 제한적인 상황에서 통할 수 있는 엽기적인 방법인데 session variable 중 auto_increment_increment의 값을 -1로 해버리면 해결되는 경우가 있다.</p><p><br /></p><p>심화문제 해결책 2 :</p><p>last_insert_id()를 사용하는 방법으로 -1*(last_insert_id()+1) 으로 auto_decrement를 구현한다.</p><p><br /></p><p><br /></p><p><a href="https://blog.naver.com/lipaz/100047320100" rel="nofollow">https://blog.naver.com/lipaz/100047320100</a><br /></p><p>[출처] mysql index의 order by desc 문제|작성자 천재민</p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2018-12-17T16:09:38+09:00</dc:date>
</item>


<item>
<title>mariadb 원격접속 문제</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=991</link>
<description><![CDATA[<p>[서버환경]</p><p><br /></p><p>Ubuntu 16.04 </p><p>MariaDB 10.0.36</p><p><br /></p><p>사용자권한, 방화벽 등등 이상이 없는데도 원격접속이 되지 않을때</p><p><br /></p><p>Connect Error: Can't connect to MySQL server on 'domain.com' (111)<br /></p><p><br /></p><p><br /></p><p>vi /etc/mysql/mariadb.conf.d/50-server.cnf 파일을 열어서</p><p><br /></p><p>#bind-address = 127.0.0.1 를 주석처리 또는  </p><p>bind-address = 0.0.0.0 으로 설정하고 mysql 재시작<br /></p><p><br /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2018-08-29T14:47:58+09:00</dc:date>
</item>


<item>
<title>MySQL #1690 - BIGINT UNSIGNED value is out of range in ...</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=990</link>
<description><![CDATA[<p>#1690 - BIGINT UNSIGNED value is out of range in ...<br /></p><p><br /></p><p>mysql 에서 위와 같은 에러발생시 해결 방법</p><p><br /></p><p>unsigned 에러의 경우</p><p>unsigned 타입의 연산시 결과값이 unsigned 타입이 아닐 경우 발생한다</p><p><br /></p><p>예른 들어 unsigned 타입의 A 필드 값이 100인 경우</p><p>select (A - 200) from table<br /></p><p>위 쿼리는 마이너스값이 리턴되어 에러를 발생하게 된다</p><p><br /></p><p>[해결책]</p><p>select (<span style="color:rgb(255,0,0);"><b>CONVERT(A, SIGNED)</b></span> - 200) from table </p><p>또는<br /></p><p>select (<span style="color:rgb(255,0,0);"><b>CAST(A as SIGNED)</b></span> - 200) from table<br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p><p><br /></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2017-09-08T17:08:16+09:00</dc:date>
</item>


<item>
<title>MySQL ON DUPLICATE KEY UPDATE</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=988</link>
<description><![CDATA[<div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">$result = mysqli_query($con, "insert into goods (name, price, distance, department, count)</div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">  values ('$name','$price','$distance', '$department', '1')ON DUPLICATE KEY UPDATE count=count+1");</div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;"><br /></div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">    $checkValue = mysqli_affected_rows();</div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">    if($checkValue==0) echo 'None Insert/Update';</div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">    if($checkValue==1) echo 'Insert';</div><div style="margin:0px;padding:0px;color:rgb(64,64,64);font-family:gulim, sans-serif;font-size:13px;line-height:22.1px;">    if($checkValue==2) echo 'Update';</div>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2016-05-04T16:06:01+09:00</dc:date>
</item>


<item>
<title>InnoDB 형식의 테이블</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=987</link>
<description><![CDATA[<p>InnoDB 형식의 테이블 </p><p> 트랜젝션 기능을 가진 테이블(InnoDB, BDB) 중의 하나임</p><p> BEGIN/COMMIT/ROLLBACK</p><p> InnoDB 형식의 테이블을 만들 때 <br />    1) CREATE TABLE... TYPE=INNODB 문을 사용하여<br />    2) MyISAM 형식의 테이블을 InnoDB 형식의 테이블로 변경<br />       ALTER TABLE  ... TYPE=INNODB 문을 사용<br />       빈 InnoDB 테이블을 만들어 Insert into ... select * from ...문을 사용</p><p>--------------------------------------------------------------------------------</p><p>InnoDB에서 트랜젝션의 COMMIT, ROLLBACK을 사용하게 된다.<br />InnoDB는 row level로 lock할 수 있고, SELECT 문에서 읽을 수 있도록 non-lock할 수도 있다.<br /> 이렇게 함으로써 다중사용자의 동시 사용과 퍼포먼스를 증가시키게 된다.<br /> 이는 InnoDB의 단계적 lock이 요구되지 않기 때문에 InnoDB의 row level lock이 아주 적은 공간에 적합하다. <br />InnoDB는 FOREIGN KEY 제약을 지원한다.<br />InnoDB는 대용량의 데이터 처리에서 가장 좋은 퍼포먼스를 위하여 설계되었다.<br />InnoDB는 데이터와 인덱스를 캐시하기 위한 자체적인 buffer pool로 주 메모리를 사용한다.<br />InnoDB는 테이블과 인덱스를 여러 파일로 구성되기도 하는 tablespace에 저장한다.<br />  이는 MyISAM 테이블이 각각의 파일로 저장하는 것과 다르다.<br />InnoDB는 2GB의 파일크기까지 가능하지만 운영체제에 따라 다를 수 있다.<br />InnoDB에 관한 정보는 <a href="http://www.innodb.com" rel="nofollow">http://www.innodb.com</a>에서 제공하므로 참고하면 좋다.<br />InnoDB는 MySQL 4.0부터 디폴트로 사용할 수 있도록 허용된다.<br /> 그러므로  InnoDB를 허용하기 위해서 어떤 부분을 지정할 필요가 없다.<br />MySQL의 datadir에 'ibdata1'라는 10MB의 auto-extending 파일을 디폴트로 만들게 된다<br />InnoDB를 사용하지 않으려면 MySQL 옵션으로 skip-innodb를 부가하면 된다.<br />InnoDB가 시작되면 innodb_data_file_path 라인에 auto-extending을 추가되어 다음과 같은 형식이 된다.</p><p>   pathtodatafile:sizespecification;pathtodatafile:sizespecification;...<br />   ;pathtodatafile:sizespecification[:auto-extend[:max:sizespecification]]</p><p>이처럼 auto-extend 옵션이 데이터파일에 추가되면, InnoDB는 데이터파일을 확장하여 <br />tablespace의 여유공간을 탕진하게 되는데 한번에 8MB씩 증가되어 다음의 예처럼 된다.</p><p> innodb_data_home_dir=<br /> innodb_data_file_path=/idbata/ibdata1:100M:autoextend</p><p>위 예시는 InnoDB에게 하나의 데이터파일을 100MB크기로 만들며 공간이 소진될 때마다 <br />8MB씩 확장하도록 한 예이다.<br />점점 확장되어 디스크가 모두 차면 다른 디스크를 데이터 파일로 추가해야 한다. <br />먼저 'ibdata1'의 크기를 보고서 그 크기가 1MB의 배수에 가장 근접하면 <br /> innodb_data_file_path에 'ibdata1'의 값으로 그 크기를 지정해야 한다.<br /> 그런  다음에 다른 데이터 파일을 다음과 같이 추가할 수 있다:</p><p>innodb_data_home_dir=<br />innodb_data_file_path=/idbata/ibdata1:988M;/disk2/ibdata2:50M:autoextend</p><p>파일시스템의 최대 파일크기가 2GB인지 확인해 보라,<br /> InnoDB는 OS의 최대 파일크기를 인지하지 않는다.<br /> 그런 시스템에서는 다음과 같이 데이터파일의 최대 크기를 지정할 수 있다.</p><p>innodb_data_home_dir=<br />innodb_data_file_path=/idbata/ibdata1:100M:autoextend:max:2000M<br />        <br />'my.cnf'의 예<br />128MB RAM과 하나의 하드디스크로 된 컴퓨터라고 가정한다.<br /> 다음은 InnoDB를 위한 'my.cnf'의(윈도우 버전에서는 'my.ini') 구성 예이다.<br /> InnoDB와 여러 디스크에 대한 log 파일로서,<br />   데이터 파일 'ibdata1'과 <br />   두 개의 InnoDB log 파일인 'ib_logfile0'과 'ib_logfile1'가 /mysql/data라는 datadir에 있는 경우이다. <br /> 또한 datadir에 InnoDB log 파일인 ib_arch_log_0000000000가 존재한다.</p><p>    [mysqld]<br />    # Uncomment the following if you are using InnoDB tables<br />    innodb_data_file_path = ibdata1:10M:autoextend<br />    # You can set .._buffer_pool_size up to 50 - 80 %<br />    # of RAM but beware of setting memory usage too high<br />    set-variable = innodb_buffer_pool_size=70M<br />    set-variable = innodb_additional_mem_pool_size=10M<br />    # Set .._log_file_size to 25 % of buffer pool size<br />    set-variable = innodb_log_file_size=20M<br />    set-variable = innodb_log_buffer_size=8M<br />    innodb_flush_log_at_trx_commit=1</p><p>mysqld가 구동되면서 읽는 구성 파일은 다음과 같다.<br />• '/etc/my.cnf' : Global 옵션<br />• 'COMPILATION_DATADIR/my.cnf' : Server-specific 옵션<br />• 'defaults-extra-file' : --default-extra-file=...로 지정한 파일<br />• '~/.my.cnf' : User-specific 옵션</p><p>여기서 'COMPILATION_DATADIR' 이란 MySQL의 데이터 디렉토리로 mysqld가 컴파일 할 때 <br />./configure의 옵션으로 지정한 곳으로 source로 인스톨하는 경우에는 '/usr/local/var'이<br />지만, 본서에서는 /export/home/mysql/var이다..<br />mysqld --default-file=your_path_to_my_cnf처럼 mysqld가 구동될 때 읽을 my.cnf를 지정<br />해도 된다.<br />InnoDB의 데이터 파일에 대한 경로와 디렉토리 지정은 innodb_data_home_dir으로 데이터 <br />파일 디렉토리를 지정하고, innodb_data_file_path로 경로를 지정한다. 만약 <br />innodb_data_home_dir을 지정하지 않을 경우의 디폴트는 MySQL의 datadir을 의미하는 ./ 이 된다.</p><p>다음 my.cnf의 예는 2GB RAM과 60GB 디스크의 디렉토리 경로는 '/',  '/dr2', '/dr3'인 <br />경우의 예이다.</p><p>    [mysqld]<br />    # Uncomment the following if you are using InnoDB tables<br />    innodb_data_home_dir = /export/home/mysql/var/<br />    innodb_data_file_path = /ibdata/ibdata1:2000M;/dr2/ibdata/ibdata2:2000M:autoextend<br />    innodb_log_group_home_dir = /export/home/mysql/var/<br />    innodb_log_arch_dir = /export/home/mysql/var/<br />    # You can set .._buffer_pool_size up to 50 - 80 %<br />    # of RAM but beware of setting memory usage too high<br />    set-variable = innodb_buffer_pool_size=1G<br />    set-variable = innodb_additional_mem_pool_size=20M<br />    innodb_log_group_home_dir = /dr3/iblogs<br />    innodb_log_arch_dir = /dr3/iblogs<br />    set-variable = innodb_log_files_in_group=3<br />    # Set .._log_file_size to 25 % of buffer pool size<br />    set-variable = innodb_log_file_size=150M<br />    set-variable = innodb_log_buffer_size=8M<br />    innodb_flush_log_at_trx_commit=1<br />    set-variable = innodb_lock_wait_timeout=50<br /> <br />모든 데이터 파일을 동일 디스크에 놓지 않고 서로 다른 디스크에 각각 위치시키는 것 즉, <br />데이터가 있는 디스크와 다른 디스크에 log 파일을 위치시키는 것이 퍼포먼스상 유리하다. </p><p>mysqld의 다른 변수 튜닝<br />    skip-locking<br />    set-variable    = max_connections=200<br />    set-variable    = read_buffer_size=1M<br />    set-variable    = sort_buffer=1M<br />    set-variable    = key_buffer=16M<br /> <br />my.cnf의 numeric 변수 설정의 형식은 set-variable  = innodb....=123 형식이고, string과 <br />boolean 변수 설정의 형식은 innodb_...=.... 형식이다.<br />다음은 변수의 의미이다.</p><p>innodb_data_home_dir<br />        InnoDB의 데이터파일의 디렉토리. 'my.cnf'에 지정하지  않으면 MySQL의 datadir<br />        가 디폴트임, empty string(빈 공간)인 경우에는 innodb_data_file_path의 파일경로<br />        를 사용</p><p>innodb_data_file_path<br />        각  데이터파일의  경로와   그 크기.   각  데이터파일에   대한  절대   경로로 <br />        innodb_data_home_dir가 사용할 파일의  크기는 MB이며  'M'으로 표시한다.  또한 <br />        'G'는 GB를 의미한다. </p><p>innodb_mirrored_log_groups<br />        복사될 log 그룹의 수로 디폴트는 1임</p><p>innodb_log_group_home_dir<br />        InnoDB log 파일의 디렉토리 경로</p><p>innodb_log_files_in_group<br />        log 그룹에 존재할 log 파일의 수로 3을 추천함</p><p>innodb_log_file_size<br />        log 그룹에 존재할 log 파일의 크기로 MB이다. 1M에서 buffer spool의 1/nth까지의 <br />        범위이며 여기서 n은 그룹내 log 파일의 수이다.</p><p>innodb_log_buffer_size<br />        InnoDB가 log 파일에 기록할 log의 버퍼의 크기로 1M∼8M 범위이다.</p><p>innodb_flush_log_at_trx_commit<br />        디폴트로 1이며, transaction commit에서 log가 디스크에 flush됨<br />        0이면, log가 log 파일에 기록되며 1초마다 log 파일이 flush됨<br />        2이면, log가 commit 때마다 log 파일에 기록되며 1초마다 log 파일이 flush됨</p><p>innodb_log_arch_dir<br />        log 파일이 문서화(archive)될 디렉토리로 innodb_log_group_home_dir과 같다.</p><p>innodb_log_archive<br />        디폴트로 0이며,   백업으로부터 복구할  때  log  파일을 사용하므로   현재까지는 <br />        InnoDB log 파일을 archive할 필요가 없다.</p><p>innodb_buffer_pool_size<br />        데이터와 인덱스를 캐시하기 위해 InnoDB가 쓸 메모리 버퍼의 크기로 실제 메모리<br />        의 80%까지 사용할 수 있다.</p><p>innodb_buffer_pool_awe_mem_mb<br />        buffer   pool의  MB   크기로  32비트   윈도우에서  AWE(address   windowing <br />        extensions)를 사용하 수 있게 하며 최대값은 64000이다.</p><p>innodb_additional_mem_pool_size<br />        InnoDB가 데이터 dictionary 정보나 다른 내부 데이터 구조를 저장하기  사용할 메<br />        모리 pool의 크기로 디폴트는 2M이다.</p><p>innodb_file_io_threads<br />        InnoDB에서 파일 I/O 스레드의 수로 보통 4이다.</p><p>innodb_lock_wait_timeout<br />        rollback전에 deadlock까지 기다리는 timeout 시간(초)</p><p>innodb_flush_method<br />        디폴트로 fdatasync이며, 다른 옵션은 0_DSYNC이다.</p><p>1) InnoDB tablespace 만들기<br />2) InnoDB table 만들기 <br />3) InnoDB의 Foreign Key Constraints<br />4) InnoDB에 대한 Data 파일와 Log 파일의 추가와 제거<br />5) InnoDB database의 백업과 복구<br />6) InnoDB database를 다른 운영체제 기계로 이동하기<br />6) InnoDB 트랜젝션 모델<br />7) 다중-버전 기능<br />8) 테이블과 인덱스 구조<br />9) 파일 공간 관리와 디스크 I/O<br />10) 오류 처리<br />11) InnoDB 테이블의 제약조건</p><p><br />--------------------------------------------------------------------------------</p><p>【예제】  <br />mysql&gt; CREATE TABLE customer (a INT, b CHAR(20), INDEX (a) <br />    -&gt; ) TYPE=INNODB; <br />mysql&gt; SHOW TABLE STATUS; <br />+-----------+--------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+----------------+------------------------+ <br />| Name      | Type   | Row_format | Rows  | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment |  Create_time        | Update_time         |  Check_time         | Create_options |  Comment               | <br />+-----------+--------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+----------------+------------------------+ <br />| customer  | InnoDB | Fixed      |     0 |              0 |       16384 | NULL            |        16384 |         0 |           NULL | NULL                | NULL                | NULL                |                | InnoDB free: 381952kB  | <br />+-----------+--------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+----------------+------------------------+ <br /> <br />【예제】  <br />mysql&gt; CREATE TABLE test3 ( a int(11) default NULL) TYPE=MyISAM; <br />mysql&gt; SHOW TABLE STATUS; <br />mysql&gt; ALTER TABLE test3 type=innodb; <br />Query OK, 0 rows affected (0.29 sec) <br />Records: 0  Duplicates: 0  Warnings: 0 <br />mysql&gt; SHOW TABLE STATUS; </p><p>【예제】 <br />mysql&gt; create table test2 ( a int)type=innodb; <br />mysql&gt; set autocommit=0; <br />mysql&gt; insert into test2 values(10); <br />mysql&gt; select * from test2; <br />+------+ <br />| a    | <br />+------+ <br />|   10 | <br />+------+ <br />mysql&gt; commit; <br />mysql&gt; update test2 set a=20; <br />mysql&gt; select * from test2; <br />+------+ <br />| a    | <br />+------+ <br />|   20 | <br />+------+ <br />mysql&gt; rollback; <br />mysql&gt; select * from test2; <br />+------+ <br />| a    | <br />+------+ <br />|   10 | <br />+------+ <br />mysql&gt; <br /> <br /> <br />현재의 autocommit 상태를 확인하는 방법은 다음 예제와 같다.<br />【예제】<br />mysql&gt; select @@session.autocommit;<br />+----------------------+<br />| @@session.autocommit |<br />+----------------------+<br />|                    1 |<br />+----------------------+<br />1 row in set (0.03 sec)</p><p>mysql&gt; set autocommit=0;<br />Query OK, 0 rows affected (0.00 sec)</p><p>mysql&gt; select @@session.autocommit;<br />+----------------------+<br />| @@session.autocommit |<br />+----------------------+<br />|                    0 |<br />+----------------------+<br />1 row in set (0.01 sec)</p><p>mysql&gt;</p><p> </p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2015-07-24T19:21:27+09:00</dc:date>
</item>


<item>
<title>mysql 대용량처리</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=986</link>
<description><![CDATA[<p> </p><p><span style="text-align:justify;background-color:rgb(255,255,255);"><font color="#636363" face="����"><b>mysql 대용량처리 (페이지가 없어서 구글에 저장된 페이지를 잽싸게 가져옴 ㅇㅇ )</b></font></span></p><p><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);"><br /></strong></p><p><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">개요<br /></strong><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">일반적으로 </span><b style="text-align:justify;font-family:'����';background-color:rgb(255,255,102);">MYSQL</b><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">에서 자료가 많아지면 LIMIT절을 이용하여 자료를 분할하여 가져오는 방식으로 쓰인다. </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">여기서 발생하는 문제점으로, LIMIT는 첫번째 값만큼 자료를 '무시'하고 직접 가져오는게 아니라 실제로 모든 값을 읽되 가져올 필요가 없는 부분은 '스킵'해가는 방식이기 때문에 거대한 자료의 끝에 위치한 부분을 조회하려 하는 경우 심각한 부하가 일어날 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex)note_list라는 테이블에 로우가 1억개가 있고, 9999만9990의 자료부터 10개를 가져온다고 칠 경우 쿼리는 아래 형태가 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">SELECT * FROM note_list LIMIT 99999990, 10</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">보통은 저 쿼리에서 앞에 수만큼 건너뛰고 뒤에 수만큼 가져오는 것이라고 생각하기 쉽지만, 사실은 전부 읽되 앞에 수만큼을 스킵해버리고 뒤에 수만큼 가져오기 때문에 결과적으로는 1억개의 자료를 모두 읽는 것과 다를 바가 없게 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">해결책</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">해결책은 여러가지 방법이 존재한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">아래는 그 방법 중 시도해본 세가지이다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) 로우의 조회 범위를 구하여 해당 범위만큼 PK를 BETWEEN 연산으로 가져오기</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">인덱스를 타기 때문에 자료가 많아도 상당히 빠른 조회가 가능하다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex) SELECT * FROM note_list WHERE no BETWEEN 10001 AND 10010</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">여기서 no는 note_list의 PK자 Auto Increment 값이다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">단, PK가 무조건 순차적으로 저장이 되어있어야 가능하며 만약 중간에 비어버리는 값이 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">생기는 경우 자료를 올바르게 가져올 것이란 보장을 할 수 없다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex) 위의 쿼리를 기반으로, 만약 no가 10001인 로우와 no가 10007인 로우의 자료가 없다면</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">의도된 쿼리대로라면 총 10개의 자료가 조회되어야 하지만 8개가 조회되어 버린다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">이 단점을 보완하려면 총 자료가 원하는 갯수가 될 때 까지 초기 BETWEEN 범위에서 계속 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">늘려가면서 조회 쿼리를 반복해서 날리던지, 비어있는 값들을 구하여 BETWEEN의 범위를 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">보정해야 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) LIMIT를 사용하되, 조회 범위를 제한하여 가져오기</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">LIMIT를 사용하면 (1)에서처럼 중간에 비는 값이 있어도 갯수만큼 가져오기 때문에 (1)에서</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">의 문제는 해결할 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">다만 조회 범위를 제한하는 방법이 마땅치가 않다는 문제점이 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1)과 (2) 모두 로우의 순차정보를 담고 있는 컬럼이 존재한다면 무리없이 구현 가능하다.(ORACLE로 치면 ROWNUM과 비슷한 요소의 컬럼)</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">다만 특정 로우가 삭제될 경우, 해당 로우 위에 존재하는 모든 로우의 순차정보값을 갱신해야한다는 문제점이 존재한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex) 로우가 100만개 들어있는 테이블에서 맨 처음 들어간 자료(순차정보가 1인 자료)를 삭제한다면, 남은 99만9999개의 순차정보를 모두 -1 시켜버려야하므로 과부하가 발생한다</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(3) 로우를 특정 사이즈만큼 묶고, 묶은 값을 구분할 수 있는 컬럼과 테이블을 추가하여 관리</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">하는 방법</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2)의 방법에서 파생되었으며 실제로 조회 범위를 제한할 수 있는 방법으로, 기존에 있는 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">테이블에 별개의 구분값 컬럼을 줘서 해당 구분값으로 조회 범위를 제한하는 방법이다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">이후의 설명은 (3)을 사용한다는 조건 하의 설명이다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">조회범위의 제한 </strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">해당 컬럼의 이름은 segment 이고 해당 segment의 정보를 담은 note_list_게시판ID_segment 라는 테이블이 추가로 존재한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">로우를 묶는다?</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">자료가 1억개 있다고 치자.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">해당 1억개의 자료에서 LIMIT를 하는 것은 DB에 큰 부하를 준다고 위에서 설명했지만, 조회 범위가 정해진 상태에서 LIMIT를 하는 것은 그다지 부하를 주지 않는다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">즉, 1억개의 자료를 1만개씩 분할하고 해당 분할된 값을 구분할 수 있는 컬럼을 넣은 뒤 쿼리를 다음처럼 변경한다면 자료가 아무리 많아도 조회 범위가 정해져 있기 때문에 부하가 적다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">SELECT * FROM note_list WHERE segment = 7 LIMIT 9990, 10</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">세그먼트의 정보를 담는 테이블의 구조</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">CREATE TABLE `note_list_silver_segment` (</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">`no` int(11) NOT NULL AUTO_INCREMENT, -- 세그먼트 번호</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">`count` int(5) NOT NULL, --해당 세그먼트의 값을 갖는 게시물의 갯수</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">PRIMARY KEY (`no`)</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">) </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">고려해야 할 점</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) 세그먼트와 세그먼트끼리 걸치는 경우가 있기 때문에 해당 부분을 계산해 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">특정 테이블의 가장 최신 세그먼트의 값이 5이며 세그먼트 5의 게시물 갯수가 5개 있고, </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">세그먼트 4의 게시물 갯수가 1만개 있을 경우 자료의 조회 범위는 세그먼트 5개의 게시글 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">5개 + 세그먼트 4의 게시글 5개가 되어야 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) 게시물 갯수의 변동이 있을 때마다 세그먼트 테이블의 count값도 같이 변경해줘야 함</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">구현 순서</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) 현재 조회해야 하는 페이지를 기준으로 조회 범위를 구해야 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">조회 범위는 페이지-1한 값에 조회갯수를 곱한 값을 전체 게시물 갯수에서 뺀 값으로</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">구할 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex)전체 갯수가 34245개이고 조회하려는 페이지가 11페이지이고 조회갯수는 10일 경우, 페이지-1한 값은 10이며 여기에 10을 곱하면 100이 되고 이 값을 14245에서 빼면 실제 조회 범위는 34145가 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) 조회 범위를 구했다면 해당 조회 범위가 어떤 세그먼트에 속하는지 구해야 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">세그먼트의 목록을 불러온 다음, 세그먼트의 count를 처음부터 더해가면서 만약 더해지는 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">그 값이 조회 범위보다 커지거나 같아진다면 해당 세그먼트가 현재 페이지의 세그먼트이</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex) 아래와 같이 자료가 존재할 경우</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">no count</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">------------------------------------</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">4 4148</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">3 9998</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">2 10000</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">1 9999</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">조회 페이지가 11이라면 조회 범위는 34145가 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">아래서부터 count를 더해간 뒤 조회 범위와 비교를 한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">9999 &gt;= 34145 -&gt; FALSE</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">19999 &gt;= 34145 -&gt; FALSE</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">29997 &gt;= 34145 -&gt; FALSE</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">34245 &gt;= 34145 -&gt; TRUE</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">이로써 조회 범위 34145의 소속 세그먼트는 4라는 것을 알 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(3) 세그먼트 내에서의 조회 범위를 구해야 함</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">현재 조회해야 하는 세그먼트 내에서 LIMIT 해야 하는 범위를 구해야한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">공식은 다음과 같다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">현재 세그먼트의 게시물 합 - (현재 세그먼트 이전에 있는 세그먼트의 게시물 갯수 합 - (현재 조회 페이지 * 조회갯수)) - 조회갯수</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">ex)자료 형태가 위와 같다면</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">-&gt; 4148 - (4148 - (11 * 10)) - 10</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">-&gt; 4148 - (4148 - 110) - 10</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">-&gt; 4148 - 4038 - 10 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">-&gt; 100</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">그러므로 쿼리는</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">SELECT * FROM note_list WHERE segment IN (4, 3) ORDER BY no DESC LIMIT 100, 10</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">이 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">※ 맨 처음 세그먼트 조회가 아닌 경우는 위에서 설명했던 값이 걸쳐있는 경우가 있기 때문에 현재 세그먼트와 이전 세그먼트 모두 조회대상에 포함시켜야 한다.(고려해야할 점 1 참고)</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글 문제</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">위에서의 모든 전제는 답글이라는 요소를 배제하고 작성되었다. 그래서 답글 </span><b style="text-align:justify;font-family:'����';background-color:rgb(153,255,153);">처리</b><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">를 생각해봐야한다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글 </span><b style="text-align:justify;font-family:'����';background-color:rgb(153,255,153);">처리</b><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">에는 크게 두가지 방식이 있을 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) 실제 테이블에 답글 대상이 되는 게시물 밑에 끼워넣게 배치하기</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">이 경우 테이블 내의 로우 배치가 달라짐으로써 이런 저런 문제점을 야기할 수 있다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) 일반 게시물처럼 쓰이되 답글과 답글이 아닌 글을 구분지을 수 있게 하기</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">별도의 컬럼이 필요하다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">여기서는 (2)의 경우로 구현을 한다고 치겠다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글의 구현</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글과 답글이 아닌 글의 구분을 위해 2개의 컬럼을 추가했다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) parent_no : 답글의 대상이 되는 게시글의 고유번호를 담는다. 답글이 아닌 글의 경우는 이 </span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">값이 0으로 들어간다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) depth : 답글의 깊이를 나타낸다. 보통 답글은 1이 설정되며 답글의 답글은 2, 답글의 답글</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">의 답글은 3 이런 식으로 증가하게 된다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글은 세그먼트 정보 테이블에 count 정보에 포함시키지 않는데, 페이징을 용이하게 하기 위함이다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><strong style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">답글을 게시글 조회 결과에 더하기</strong><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(1) 위에서 정의된대로 조회하려는 페이지의 게시글을 가져온다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(2) 가져온 게시글 목록의 no를 parent_no로 갖는 글들을 가져온다.</span><br style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);" /><span style="text-align:justify;color:rgb(99,99,99);font-family:'����';background-color:rgb(255,255,255);">(3) 루프를 돌며 답글을 게시글에 알맞게 끼워맞춰준다.</span></p><div class="autosourcing-stub-extra"><p style="margin:11px 0px 7px;padding:0px;font-family:Dotum;font-size:12px;font-style:normal;font-weight:normal;"><strong style="padding:0px 7px 0px 0px;">[출처]</strong> <a href="http://blog.naver.com/jjusik2/165894833" target="_blank" rel="nofollow noreferrer noopener">mysql 대용량처리 </a><span style="padding:0px 7px 0px 5px;">|</span><strong style="padding:0px 7px 0px 0px;">작성자</strong> <a href="http://blog.naver.com/jjusik2" target="_blank" rel="nofollow noreferrer noopener">프시쵸</a></p></div>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2015-07-24T19:19:23+09:00</dc:date>
</item>


<item>
<title>MySQL  FULLTEXT 검색</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=985</link>
<description><![CDATA[<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;">MySQL은 % 연산자를 사용하여 패턴연산을 하는 대신, 단어 또는 구문에 대한 검색을 지원하며 FULLTEXT 검색이라고 부른다. MySQL은 3가지 종류의 FULLTEXT 검색 방식을 지원한다.</p>
<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;"><span style="font-size:12pt;">FULLTEXT 검색 방식</span></p>
<ul style="color:#666666;font-family:dotum;">
<li><span style="color:#0900ff;"><b>자연어 검색</b></span><br />검색 문자열을 단어 단위로 분리한 후, 해당 단어 중 하나라도 포함되는 행을 찾는다.</li>
<li><b><span style="color:#0900ff;">불린 모드 검색</span></b><br />검색 문자열을 단어 단위로 분리한 후, 해당 단어가 포함되는 행을 찾는 규칙을 추가적으로 사용할 수 있다.</li>
<li><b><span style="color:#0900ff;">쿼리 확장 검색</span></b><br />2단계에 걸쳐서 검색을 수행한다. 첫 단계에서는 자연어 검색을 수행한 후, 첫 번쨰 검색의 결과에 매칭된 행을 기반으로 검색 문자열을 재구성하여 두 번째 검색을 수행한다. 이는 1단계 검색에서 사용한 단어와 연관성이 있는 단어가 1단계 검색에 매칭된 결과에 나타난다는 가정을 전제로 한다.</li></ul>
<div style="color:#666666;font-family:dotum;">이 글에서는 자연어 검색과 불린 모드 검색만을 다루고자 한다. 그리고 영어 데이터가 아닌 한글 데이터를 기준으로 한다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><b><span style="font-size:12pt;">FULLTEXT 검색을 위한 주의사항</span></b></div>
<div style="color:#666666;font-family:dotum;">FULLTEXT 검색을 지원하기 위해서는 아래의 사항들을 주의해야 한다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><b>FULLTEXT 인덱스 생성</b></div>
<div style="color:#666666;font-family:dotum;">FULLTEXT 검색을 하려는 컬럼에 대해 FULLTEXT 인덱스를 생성해야 한다. FULLTEXT 인덱스는 MyISAM 엔진을 사용하는 테이블에 대해서만 생성할 수 있다. 또한 컬럼 데이터 타입은 반드시 Text, Binary Char, Varchar 타입을 가져야 한다. 또한 한글 데이터를 검색하려면 테이블 인코딩을 utf8을 사용해야 한다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">FULL TEXT 인덱스는 테이블을 생성할 때 생성하거나, 또는 이미 만들어진 테이블에 대해서도 테이블을 생성할 수 있다. 예를 들어 게시판 검색 기능을 만든다고 해보자. 게시글을 저장할 posts 테이블을 만들고, 여기에 게시글의 제목(gtitle), 본문(gdesc) 컬럼을 추가한다고 하자. 만약 제목만을 FULLTEXT 검색을 하고자 한다면,</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<div>create table posts(</div>
<div>    id <span style="background-color:transparent;font-size:9pt;line-height:1.5;">bigint(100) NOT NULL AUTO_INCREMENT,</span></div>
<div><span style="background-color:transparent;font-size:9pt;line-height:1.5;">    gtitle text NOT NULL,</span></div>
<div>    gdesc text NOT NULL,</div>
<div>    ....</div>
<div><span style="background-color:transparent;font-size:9pt;line-height:1.5;">
</span><div>    PRIMARY KEY (id),</div>
<div>    <span style="font-size:9pt;line-height:1.5;"><b><span style="color:#0900ff;">FULLTEXT KEY </span><span style="color:#0900ff;">gtitle</span><span style="color:#0900ff;"> (</span><span style="color:#0900ff;">gtitle</span><span style="color:#0900ff;">)</span></b></span></div></div>
<div>) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;</div></div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">와 같이 테이블을 생성한다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">만약 이미 만들어진 테이블에 대해 FULLTEXT 인덱스를 생성해야 한다면,</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">alter table posts <span style="color:#0900ff;"><b>add FULLTEXT(gtitle)</b></span>;</div>
<div style="color:#666666;font-family:dotum;"><br /><span style="width:1px;height:1px;float:right;"></span></div>
<div style="color:#666666;font-family:dotum;">와 같이 생성한다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">FULLTEXT 인덱스는 하나 이상의 컬럼에 대해서 생성할 수 있다. 만약 제목 검색뿐만 아니라, 본문 검색까지 지원하려면 아래와 같이 게시글 제목과 본문에 대해서도 FULLTEXT 인덱스를 생성해야 한다.</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">alter table posts <span style="color:#0900ff;"><b>add FULLTEXT(gtitle, gdesc)</b></span>;</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><b>FULLTEXT 검색 엔진 설정하기</b></div>
<div style="color:#666666;font-family:dotum;">검색어가 너무 짧은 경우 아무런 검색결과도 나오지 않는다. 이때 짧다는 기준은 4글자 이하다. 만약 2글자의 검색어를 지원하려면 최소 검색어 길이 값을 2로 수정해야 한다. my.cnf 설정파일을 열어서 <span style="color:#0900ff;"><b>ft_min_word_len</b></span> 변수 값을 기본값인 4에서 2로 변경한다.</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<div># my.cnf 파일</div>
<div>ft_min_word_len=2</div></div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">만약 FULLTEXT 인덱스를 생성한 경우라면 인덱스를 삭제한 후 재생성해야 한다. 또는 아래와 같이 인덱스를 갱신할 수 있다.</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">REPAIR TABLE posts QUICK;</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">이제 FULLTEXT 검색 본론으로 넘어가 보자.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;"><span style="font-size:12pt;"><b>자연어 검색</b></span></div>
<div style="color:#666666;font-family:dotum;">게시물의 제목과 본문에 "로고"라는 단어가 포함된 게시글을 검색하는 경우를 생각해 보자. FULLTEXT 검색은 아래와 같이 수행한다.</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">select P.gtitle, P.gdesc from posts P where <span style="color:#0900ff;"><b>match(gtitle, gdesc) against('로고')</b></span> limit 10;</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">검색 결과는 다음과 같다.</div>
<div style="color:#666666;font-family:dotum;">
<p style="text-align:center;clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:630px;height:auto;"><span><img src="http://cfile4.uf.tistory.com/image/274C4149529439E90A056D" height="198" width="630" style="border:0px;" alt="" /></span></span></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p></div>
<div style="color:#666666;font-family:dotum;">무언가를 해낸듯한 기분이 들겠지만 약간의 문제가 있다. 이 부분은 조금 후에 불린 검색에서 다루기로 하고, 검색의 정확도를 수치로 보여주는 방법을 살펴보자.</div>
<div class="txc-textbox" style="color:#666666;font-family:dotum;border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">select P.gtitle, P.gdesc, <span style="color:#0900ff;"><b>match(gtitle, gdesc) against('로고') as score</b></span> from posts P where <b><span style="color:#0900ff;">match(gtitle, gdesc) against('로고')</span></b> limit 10;</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">
<p style="text-align:center;clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:630px;height:auto;"><span><img src="http://cfile10.uf.tistory.com/image/2768774F52943A69310D4B" height="162" width="630" style="border:0px;" alt="" /></span></span></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">보는 바와 같이 검색의 정확도(score)에 따라 내림차순 정렬되어 결과가 표시됨을 알 수 있다. 물론 1단어뿐만 아니라 여러 단어로도 검색이 가능하다.</p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="padding-top:0px;padding-bottom:0px;">select P.gtitle, P.gdesc, match(gtitle, gdesc) against(<b style="color:#0900ff;">'귀여운 로고'</b>) as score from posts P where match(gtitle, gdesc) against(<span style="color:#0900ff;"><b>'귀여운 로고'</b></span>) limit 10;</p></div></div>
<div style="color:#666666;font-family:dotum;">
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="text-align:center;clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:630px;height:auto;"><span><img src="http://cfile1.uf.tistory.com/image/2166093C52943C0D271529" height="155" width="630" style="border:0px;" alt="" /></span></span></p>
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">자연어 검색은 구문을 단어 단위로 분할한 후, 해당 단어 중 1개라도 포함된 행을 검색한다. 따라서 6번째 결과와 같이 "예쁜 팔찌 만들어"와 같이 관련성이 낮은 게시글도 검색되게 된다.</p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;"><b><span style="font-size:12pt;">불린 모드 검색</span></b></p>
<p style="padding-top:0px;padding-bottom:0px;">이제 불린 모드 검색을 이용하여 자연어 검색에서 부딪혔던 문제를 완화해 보자. 불린 검색이 자연어 검색와 크게 차이나는 점은</p>
<ul>
<li>검색의 정확도에 따라 결과가 정렬되지 않는다.</li>
<li>구문 검색이 가능하다</li>
<li>필수(+), 예외(-), 부분(*) 연산자를 사용할 수 있다</li></ul>
<p style="padding-top:0px;padding-bottom:0px;">등이다.</p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">앞서 "귀여운 로고"를 단어 검색이 아닌 구문 검색, 즉 "귀여운 로고"가 그대로 포함된 게시글을 검색하고자 한다면,</p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="padding-top:0px;padding-bottom:0px;">select P.gtitle, P.gdesc from posts P where match(gtitle, gdesc) against('<span style="color:#0900ff;"><b>"</b></span>귀여운 로고<span style="color:#0900ff;"><b>"</b></span>' <span style="color:#0900ff;"><b>in boolean mode</b></span>);</p></div>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">구문을 쌍따옴펴(" ")로 묶은 후, 불린 모드(boolean mode)로 검색을 실행한다.</p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="text-align:center;clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:630px;height:auto;"><span><img src="http://cfile6.uf.tistory.com/image/2216444A52943D06368ED5" height="119" width="630" style="border:0px;" alt="" /></span></span></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">만약 맨 마지막의 여행영상 게시글은 검색에서 제외하려면 예외 연산자(-)를 사용할 수 있다.</p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="padding-top:0px;padding-bottom:0px;">select P.gtitle, P.gdesc from posts P where match(gtitle, gdesc) against('"귀여운 로고" <span style="color:#0900ff;"><b>-여행영상</b></span>' in boolean mode);</p></div>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">이제 부분 연산자(*)를 살펴보자. 앞서 자연어 검색 첫 번째 예제에서 "로고"를 검색한 결과를 보면, 모두 "로고" 단어가 독립적으로 존재한다. 다시 말해 "로고를", "로고와" 등과 같은 단어는 검색되지 않는다. 이처럼 한글에서 형태소를 잘라야만 제대로 인덱스가 구성되지만 쉬운일이 아니다. 따라서 검색할 때 "로고로 시작하는 모든 단어"와 같은 패턴을 사용할 수 있다. 명확한 예를 위해 게시글 제목(gtitle)에 대해서만 FULLTEXT 검색을 실행해 보자. 먼저 자연어 검색은 다음과 같다.</p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="padding-top:0px;padding-bottom:0px;">select P.id, P.gtitle from posts P where match(gtitle) against('<span style="color:#0900ff;"><b>로고를</b></span>') limit 10;</p></div>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">위와 같이 검색하면 </p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:232px;height:auto;"><span><img src="http://cfile27.uf.tistory.com/image/210AC53352943F1304A470" height="198" width="232" style="border:0px;" alt="" /></span></span></p>
<p style="padding-top:0px;padding-bottom:0px;"></p>
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;">와 같이 "로고를"이 포함된 행이 매칭된다. 하지만 자연어 검색에서 아래와 같이 '로고'를 사용하면 해당 행이 검색되지 않는다.</p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;">select P.id, P.gtitle from posts P where match(gtitle) against('<span style="color:#0900ff;"><b>로고</b></span>') <span style="color:#0900ff;"><b>and id = 911</b></span> limit 10;</p></div>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;">그러나 불린 검색을 이용하여 부분 검색 연산자를 사용하면 검색이 가능하다.</p>
<div class="txc-textbox" style="border:1px solid rgb(238,238,238);background-color:#eeeeee;padding:10px;">
<p style="padding-top:0px;padding-bottom:0px;">select P.id as id, P.gtitle from posts P where match(gtitle) against('<span style="color:#0900ff;"><b>로고*</b></span>' <b><span style="color:#0900ff;">in boolean mode</span></b>) and id = 911 limit 10;</p></div>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p></div>
<div style="color:#666666;font-family:dotum;"><span style="font-size:12pt;"><b>메타 검색 기능 UI 구성</b></span></div>
<div style="color:#666666;font-family:dotum;">이제 FULLTEXT 검색 기능을 사용하여 서비스에 메타 검색 기능을 추가한다면 아래와 같이 UI를 구성해볼 수 있다.</div>
<div style="color:#666666;font-family:dotum;">일단 기본적으로 모든 검색은 불린 검색을 사용한다. 그리고 사용자가 입력한 단어는 구문 검색(" ")이 아닌 경우 공백을 기준으로 분리한 후, * 연산자를 추가한다. 아래는 입력 예다.</div>
<div style="color:#666666;font-family:dotum;"><br /></div>
<div style="color:#666666;font-family:dotum;">
<p style="clear:none;float:none;padding-top:0px;padding-bottom:0px;"><span class="imageblock" style="border:1px solid rgb(221,221,221);padding:5px;margin:5px 0px;width:376px;height:auto;"><span><img src="http://cfile25.uf.tistory.com/image/25592E495294408F2C93BC" height="175" width="376" style="border:0px;" alt="" /></span></span></p>
<p style="padding-top:0px;padding-bottom:0px;"><br /></p><br /></div>
<div style="color:#666666;font-family:dotum;">1단어를 입력한 경우 --&gt; [로고*] 로 검색을 수행한다.</div>
<div style="color:#666666;font-family:dotum;">2단어를 입력한 경우 --&gt; <span style="background-color:transparent;font-size:9pt;line-height:1.5;">[</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">귀여운* 로고*</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">]</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;"> 로 검색을 수행한다.</span></div>
<div style="color:#666666;font-family:dotum;">구문 검색을 입력한 경우 --&gt; <span style="background-color:transparent;font-size:9pt;line-height:1.5;">[</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">"귀여운 로고"*</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">]</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;"> 로 검색을 수행한다.</span></div>
<div style="color:#666666;font-family:dotum;">예외 연산자를 사용한 경우 --&gt; <span style="background-color:transparent;font-size:9pt;line-height:1.5;">[</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">"귀여운 로고"* -영상</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;">]</span><span style="background-color:transparent;font-size:9pt;line-height:1.5;"> 으로 검색을 수행한다.</span></div>
<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;"><br /></p>
<p style="color:#666666;font-family:dotum;padding-top:0px;padding-bottom:0px;"><b><span style="font-size:12pt;">[참고자료]</span></b></p>
<ul style="color:#666666;font-family:dotum;">
<li><a href="http://blog.daum.net/kitekids/12379744" target="_blank" class="tx-link" style="color:#666666;text-decoration:none;" rel="nofollow noreferrer noopener">[MYSQL/MS-SQL] FULL TEXT SEARCH 간단히 정리</a></li>
<li><a href="http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&amp;wr_id=55543" target="_blank" class="tx-link" style="color:#666666;text-decoration:none;" rel="nofollow noreferrer noopener">DBMS] MySQL FULLTEXT을 이용한 형태소 분석없는 한글검색 방법</a></li>
<li><a href="http://radiocom.kunsan.ac.kr/lecture/mysql/fulltext_search.html" target="_blank" class="tx-link" style="color:#666666;text-decoration:none;" rel="nofollow noreferrer noopener">FULLTEXT 인덱스와 서치</a></li>
<li></li></ul>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2014-04-25T12:08:23+09:00</dc:date>
</item>


<item>
<title>MySQL 문자열 길이</title>
<link>http://www.nuno21.net/bbs/board.php?bo_table=db&amp;amp;wr_id=984</link>
<description><![CDATA[<p style="padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">MySQL 문자열 길이 구하는 함수 </span> </p>
<p style="padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">1. </span><b><span style="font-size:10pt;">LENGTH</span><span style="font-size:10pt;">()</span></b><span style="font-size:10pt;"> : 길이를 bytes로 나타낸다.</span> </p>
<p style="margin-left:2em;padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">SELECT</span><span style="font-size:10pt;"> LENGTH('한글') -&gt; 6</span><br /><span style="width:1px;float:right;height:1px;"></span><span style="font-size:10pt;">SELECT</span><span style="font-size:10pt;"> LENGTH('abc') -&gt; 3</span></p>
<p style="margin-left:2em;padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;"> </span></p>
<p style="padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">2. </span><b><span style="font-size:10pt;">CHAR_LENGTH()</span></b><span style="font-size:10pt;"> : 글자의 수를 나타낸다.</span> </p>
<p style="margin-left:2em;padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">SELECT CHAR_LENGTH('한글') -&gt; 2</span><br /><span style="font-size:10pt;">SELECT CHAR_LENGTH('abc') -&gt; 3</span></p>
<p style="margin-left:2em;padding:0px;color:#333333;font-family:'돋움';text-align:justify;"> </p>
<p style="padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">3. </span><b><span style="font-size:10pt;">BIT_LENGTH()</span></b><span style="font-size:10pt;"> : 길이를 bit로 나타낸다.</span> </p>
<p style="margin-left:2em;padding:0px;color:#333333;font-family:'돋움';text-align:justify;"><span style="font-size:10pt;">SELECT BIT_LENGTH('한글a') -&gt; 56</span><br /><span style="font-size:10pt;">SELECT BIT_LENGTH('한글')</span><span style="font-size:10pt;">   -&gt; 48</span></p>
<div class="autosourcing-stub-extra" style="line-height:1.5;">
<p style="margin-top:11px;margin-bottom:7px;padding:0px;line-height:1.5;font-family:Dotum;"><strong style="padding:0px 7px 0px 0px;">[출처]</strong> <a href="http://blog.naver.com/ntzkimy/50186000505" target="_blank" style="text-decoration:none;" rel="nofollow noreferrer noopener">MySQL 문자열 길이</a><span style="padding:0px 7px 0px 5px;">|</span><strong style="padding:0px 7px 0px 0px;">작성자</strong> <a href="http://blog.naver.com/ntzkimy" target="_blank" style="text-decoration:none;" rel="nofollow noreferrer noopener">키이미</a></p></div>
<p></p>]]></description>
<dc:creator>nuno</dc:creator>
<dc:date>2014-04-25T12:07:33+09:00</dc:date>
</item>

</channel>
</rss>
