|
23 | 23 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
24 | 24 | </a> |
25 | 25 | </span> |
26 | | -</h1><p><a href="https://github.com/orm712/CS-712">CS 스터디</a>에서 12월 12일 발표 예정인 <a href="https://github.com/orm712/CS-712/blob/main/08-JAVASCRIPT/16_Typescript/Readme.md">공간 인덱스</a>에 대해 정리하고, 이를 실습해본 문서를 블로그에 공유하고자 한다.</p> |
| 26 | +</h1><hr> |
| 27 | +<p><a href="https://github.com/orm712/CS-712">CS 스터디</a>에서 12월 12일 발표 예정인 <a href="https://github.com/orm712/CS-712/blob/main/08-JAVASCRIPT/16_Typescript/Readme.md">공간 인덱스</a>에 대해 정리하고, 이를 실습해본 문서를 블로그에 공유하고자 한다.</p> |
27 | 28 | <h1 id="공간-인덱스spatial-index란" ><code>공간 인덱스(Spatial Index)</code>란? |
28 | 29 | <span> |
29 | 30 | <a href="#%ea%b3%b5%ea%b0%84-%ec%9d%b8%eb%8d%b1%ec%8a%a4spatial-index%eb%9e%80"> |
30 | 31 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
31 | 32 | </a> |
32 | 33 | </span> |
33 | | -</h1><ul> |
| 34 | +</h1><hr> |
| 35 | +<ul> |
34 | 36 | <li><code>공간 데이터(Spatial Data)</code>를 지원하는 데이터베이스에서 <code>공간 쿼리(Spatial Query)</code>를 <code>최적화</code>하기 위해 사용되는 <code>인덱스</code> |
35 | 37 | <ul> |
36 | 38 | <li>기존의 <code>인덱스</code>는 데이터들을 <code>선형 순서</code>로 정렬해 조회 속도를 최적화하는 반면, <code>2차원/3차원 공간 상의 데이터</code>들을 정렬하기 위해 <code>R-Tree</code>와 같은 자료구조를 사용</li> |
|
80 | 82 | </ul> |
81 | 83 | </li> |
82 | 84 | </ul> |
83 | | -<h4 id="epsg4326---wgs-84httpsepsgio4326" ><a href="https://epsg.io/4326"><code>EPSG:4326 - WGS 84</code></a> |
| 85 | +<h4 id="epsg4326---wgs-84httpsepsgio4326" >EPSG:4326 - WGS 84<a href="https://epsg.io/4326">#</a> |
84 | 86 | <span> |
85 | 87 | <a href="#epsg4326---wgs-84httpsepsgio4326"> |
86 | 88 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
|
91 | 93 | <li><code>GPS</code>, <code>Google Earth</code> 등에서 사용됨</li> |
92 | 94 | <li><code>각도(Degree)</code>를 <code>단위</code>로 함</li> |
93 | 95 | </ul> |
94 | | -<h4 id="epsg3857---wgs-84--pseudo-mercator--spherical-mercatorhttpsepsgio3857" ><a href="https://epsg.io/3857">EPSG:3857 - WGS 84 / Pseudo-Mercator / Spherical Mercator</a> |
| 96 | +<h4 id="epsg3857---wgs-84--pseudo-mercator--spherical-mercatorhttpsepsgio3857" >EPSG:3857 - WGS 84 / Pseudo-Mercator / Spherical Mercator<a href="https://epsg.io/3857">#</a> |
95 | 97 | <span> |
96 | 98 | <a href="#epsg3857---wgs-84--pseudo-mercator--spherical-mercatorhttpsepsgio3857"> |
97 | 99 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
|
112 | 114 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
113 | 115 | </a> |
114 | 116 | </span> |
115 | | -</h3><ul> |
| 117 | +</h3><hr> |
| 118 | +<ul> |
116 | 119 | <li><code>MySQL</code>에는 크게 <code>단일 지오메트리 값</code>을 저장할 수 있는 자료형과 <code>지오메트리 값의 집합</code>을 저장할 수 있는 자료형으로 나뉨</li> |
117 | 120 | </ul> |
118 | | -<h3 id="wkb와-wkt" >WKB와 WKT |
| 121 | +<h4 id="wkb와-wkt" >WKB와 WKT |
119 | 122 | <span> |
120 | 123 | <a href="#wkb%ec%99%80-wkt"> |
121 | 124 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
122 | 125 | </a> |
123 | 126 | </span> |
124 | | -</h3><ul> |
| 127 | +</h4><ul> |
125 | 128 | <li><code>OpenGIS</code>에서는 <code>기하학적 객체</code>의 표현을 위해 <code>WKT(Well-Known Text)</code> 포맷과 <code>WKB(Well-Known Binary)</code> 포맷을 사용 |
126 | 129 | <ul> |
127 | 130 | <li><code>MySQL</code>에서는 내부적으로 지오메트리 값을 WKT, WKB가 아닌 다른 포맷을 사용해 저장 |
|
136 | 139 | </ul> |
137 | 140 | </li> |
138 | 141 | </ul> |
139 | | -<h4 id="wktwell-known-text" >WKT(Well-Known Text) |
| 142 | +<h5 id="wktwell-known-text" >WKT(Well-Known Text) |
140 | 143 | <span> |
141 | 144 | <a href="#wktwell-known-text"> |
142 | 145 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
143 | 146 | </a> |
144 | 147 | </span> |
145 | | -</h4><ul> |
| 148 | +</h5><ul> |
146 | 149 | <li>지오메트리 값을 <code>ASCII</code> 형태로 교환하기 위해 설계됨</li> |
147 | 150 | <li><code>OpenGIS</code> 사양에서는 <code>WKT</code>값 작성을 위한 <code>배커스-나우르</code> 문법을 제공</li> |
148 | 151 | <li>자료형에 따라 필요한 점의 갯수는 다르지만 X-Y 좌표 값을 <code>(X Y)</code> 형태로, 즉 쉼표가 아닌 공백을 통해 구분하는 문법을 공통적으로 사용함 |
|
166 | 169 | </ul> |
167 | 170 | </li> |
168 | 171 | </ul> |
169 | | -<h4 id="wkbwell-known-binary" >WKB(Well-Known Binary) |
| 172 | +<h5 id="wkbwell-known-binary" >WKB(Well-Known Binary) |
170 | 173 | <span> |
171 | 174 | <a href="#wkbwell-known-binary"> |
172 | 175 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
173 | 176 | </a> |
174 | 177 | </span> |
175 | | -</h4><ul> |
| 178 | +</h5><ul> |
176 | 179 | <li><code>지오메트리 WKB 정보</code>를 담고있는 <code>BLOB</code> 형태의 <code>이진 스트림</code> 형태로 지오메트리 값을 교환하기 위해 사용됨</li> |
177 | 180 | <li><code>WKB</code>는 1바이트의 <code>unsigned Integer</code>(<code>byte order</code>), 4바이트의 <code>unsigned Integer</code>(<code>WKB type</code>), 8바이트의 <code>배정밀도(double precision) 숫자 값</code>(<code>X, Y 좌표</code>)들을 사용 |
178 | 181 | <ul> |
|
215 | 218 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
216 | 219 | </a> |
217 | 220 | </span> |
218 | | -</h4><ul> |
| 221 | +</h4><hr> |
| 222 | +<ul> |
219 | 223 | <li><code>GEOMETRY</code>는 어떤 유형의 지오메트리 값이든 저장할 수 있으며, 나머지 단일 값 유형은 특정 도형의 유형으로 값을 제한함</li> |
220 | 224 | </ul> |
221 | 225 | <h5 id="geometry" >GEOMETRY |
|
338 | 342 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
339 | 343 | </a> |
340 | 344 | </span> |
341 | | -</h4><ul> |
| 345 | +</h4><hr> |
| 346 | +<ul> |
342 | 347 | <li><code>GEOMETRYCOLLECTION</code>은 모든 유형의 객체 집합을 저장할 수 있으며, 나머지 집합 자료형은 집합 멤버를 특정 도형 유형을 가진 멤버로 제한함</li> |
343 | 348 | </ul> |
344 | 349 | <h5 id="multipoint" >MULTIPOINT |
|
403 | 408 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
404 | 409 | </a> |
405 | 410 | </span> |
406 | | -</h2><h3 id="공간-인덱스와-비공간-인덱스" >공간 인덱스와 비공간 인덱스 |
| 411 | +</h2><hr> |
| 412 | +<h3 id="공간-인덱스와-비공간-인덱스" >공간 인덱스와 비공간 인덱스 |
407 | 413 | <span> |
408 | 414 | <a href="#%ea%b3%b5%ea%b0%84-%ec%9d%b8%eb%8d%b1%ec%8a%a4%ec%99%80-%eb%b9%84%ea%b3%b5%ea%b0%84-%ec%9d%b8%eb%8d%b1%ec%8a%a4"> |
409 | 415 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
|
454 | 460 | <svg viewBox="0 0 28 23" height="100%" width="19" xmlns="http://www.w3.org/2000/svg"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" fill="none" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2"/></svg> |
455 | 461 | </a> |
456 | 462 | </span> |
457 | | -</h3><ul> |
| 463 | +</h3><hr> |
| 464 | +<ul> |
458 | 465 | <li><code>옵티마이저</code>는 <code>WHERE</code>절에서 <code>MBRContains()</code>, <code> MBRWithin()</code>와 같은 함수를 사용하는 쿼리에 대해, 가용한 <code>공간 인덱스</code>를 검색에 포함할 수 있는지 조사</li> |
459 | 466 | <li>따라서 <code>공간 인덱스</code>를 사용하는 함수를 통해 탐색할 row의 범위를 줄이면 <code>최적화가 가능</code></li> |
460 | 467 | <li>예시 |
|
0 commit comments