๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SAP

[HANA] HANA DB ์‚ฌ์šฉ ์‹œ ์ฃผ์˜์  : SORT BY

by applemango2021 2021. 8. 30.

๊ฒฐ๋ก  : HANA DB์—์„œ๋Š” index๋‚˜ primary key์— ์˜ํ•œ ์•”๋ฌต์ ์ธ(implicit) ์ •๋ ฌ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค. READ...BINARY SEARCH๋‚˜ DELETE ADJACENT DUPLICATES ๋“ฑ ์ •๋ ฌ์ด ํ•„์ˆ˜์ธ ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์—๋Š” ๋ฐ˜๋“œ์‹œ ORDER BY๋‚˜ SORT BY ๊ตฌ๋ฌธ์„ ์ด์šฉํ•ด์„œ ๋ช…์‹œ์ ์œผ๋กœ ์ •๋ ฌ์„ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. 


๐Ÿ“ข๋ฌธ์ œ

์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž. EKPO ํ…Œ์ด๋ธ”์—๋Š” ํ‚ค๊ฐ’์œผ๋กœ EBELN(๊ตฌ๋งค๋ฌธ์„œ๋ฒˆํ˜ธ)์™€ EBELP(๊ตฌ๋งค๋ฌธ์„œ ์•„์ดํ…œ) ๋‘ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์žˆ์œผ๋ฉฐ, ๋ณ„๋„๋กœ ์ƒ์„ฑํ•œ ์ธ๋ฑ์Šค๋Š” ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž. 

EBELN EBELP
4500000001 1
4500000001 2
4500000002 1
4500000003 1

๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ๊ตฌ๋ฌธ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐœ์ทŒํ•ด์˜ค๋ฉด ์–ด๋–ค ๊ฒฐ๊ณผ๊ฐ’์ด ๋ฆฌํ„ด๋ ๊นŒ?  ์ •๋‹ต์€ ์–ด๋–ค DB๋ฅผ ์‚ฌ์šฉํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค. 

 SELECT EBELN,
 		EBELP,
   FROM EKPO
   INTO TABLE @DATA(LT_EKPO).

 

Row๊ธฐ๋ฐ˜์˜ DB (ex. ์˜ค๋ผํด)

์˜ค๋ผํด DB์— ๋Œ€ํ•ด ์ž˜์€ ๋ชจ๋ฅด์ง€๋งŒ, ์•„๋งˆ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฆฌํ„ด๋  ๊ฒƒ์ด๋‹ค. ํ‚ค๊ฐ’์œผ๋กœ EBELN, EBELP๊ฐ€ ์žกํ˜€์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด๊ฐ€ ๋ณ„๋„๋กœ SELECT๋ฌธ์—์„œ ORDER BY๋ฅผ ํ•˜๊ฑฐ๋‚˜ LT_EKPO ํ…Œ์ด๋ธ”์„ SORT BY ํ•˜์ง€ ์•Š์•„๋„ EBELN๊ณผ EBELP ๊ฐ’์— ๋”ฐ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ํ…Œ์ด๋ธ”์ด ๋ฆฌํ„ด๋œ๋‹ค. 

EBELN EBELP
4500000001 1
4500000001 2
4500000002 1
4500000003 1

์‹ค์ œ๋กœ ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ๋“ค ์ค‘์—์„œ๋Š” DB๊ฐ€ ์œ„์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™ํ•  ๊ฒƒ์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜๊ณ  ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋“ค์ด ์˜์™ธ๋กœ ๊ฝค ์žˆ๋‹ค. BINARY SEARCH๋ฅผ ํ•˜๊ธฐ ์ „์— ์ •๋ ฌ์„ ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ๋„ ์ง€๊ธˆ๊นŒ์ง€ ๋ฌธ์ œ์—†์ด ์‚ฌ์šฉํ•˜์˜€๊ธธ๋ž˜ ์ž์„ธํžˆ ํ™•์ธํ•ด๋ณด๋ฉด ํ…Œ์ด๋ธ”์˜ ํ‚ค๊ฐ’๊ณผ BINARY SEARCH ๊ตฌ๋ฌธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ•„๋“œ๋“ค์ด ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ๋“ค์ด ๋Œ€๋‹ค์ˆ˜์˜€๋‹ค. BINARY SEARCH๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— SORT BY ๊ตฌ๋ฌธ์„ ๋ฐ˜๋“œ์‹œ ์‚ฌ์šฉํ•˜๋ผ๊ณ  ๊ฐ•๋ ฅํžˆ ๊ถŒ๊ณ ํ•˜์ง€๋งŒ, ์–ด์จŒ๋“  ์ง€๊ธˆ๊นŒ์ง€ ๋ฌธ์ œ์—†์ด ์‚ฌ์šฉ๋˜์—ˆ์œผ๋ฉด ์ •๋ง ๋‹คํ–‰์ธ ์ผ์ด๋‹ค. 

 

Column๊ธฐ๋ฐ˜์˜ DB (ex. HANA)

๊ทธ๋ ‡๋‹ค๋ฉด HANA DB์—์„œ๋Š” ์–ด๋–ป๊ฒŒ ๋ฆฌํ„ด๋ ๊นŒ? ์ •๋‹ต์€ "์•Œ ์ˆ˜ ์—†๋‹ค"์ด๋‹ค. ์ค‘์š”ํ•œ ๊ฒƒ์€, ์˜ค๋ผํด DB์™€ ๊ฐ™์ด primary key์— ํ•ด๋‹นํ•˜๋Š” EBELN๊ณผ EBELP ๊ฐ’์— ๋”ฐ๋ผ ์ •๋ ฌ๋˜์–ด ๋‚˜์˜ค์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ๋‹ค๋ผ๋Š” ์ ์ด๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌ๋งค๋ฌธ์„œ 4500000001๋ฒˆ์˜ ๋‘ ๋ฒˆ์งธ ์•„์ดํ…œ์ด ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— ๋ฆฌํ„ด๋  ์ˆ˜๋„ ์žˆ๋‹ค. ์ด๋Ÿฐ ์ƒํ™ฉ์—์„œ READ... BINARY SEARCH ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‚ด๊ฐ€ ์˜๋„ํ•œ๋Œ€๋กœ ๊ฒฐ๊ณผ๊ฐ’์ด ๋‚˜์˜ค์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค. 

EBELN EBELP
4500000001 1
4500000002 1
4500000003 1
4500000001 2

๐Ÿ“ข ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

 ์œ„์™€ ๊ฐ™์ด Row๊ธฐ๋ฐ˜๊ณผ ๋‹ฌ๋ฆฌ Column๊ธฐ๋ฐ˜์˜ HANA DB์—์„œ๋Š” ์ธ๋ฑ์Šค/Primary Key์— ์˜ํ•œ ์•”๋ฌต์ ์ธ ์ •๋ ฌ์ด ์ง€์›๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋ฌธ์ œ์ ์ด ์žˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ด๋ฅผ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ• ๊นŒ?

 

โ— ํ•ด๊ฒฐ์ฑ…์€ ๊ฐ„๋‹จํ•˜๋‹ค. ์•ž์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ๊ฐœ๋ฐœํ•  ๋•Œ์—๋Š” ํ•„์š”์‹œ ๋ฌด์กฐ๊ฑด ๋ช…์‹œ์ ์œผ๋กœ ORDER BY๋‚˜ SORT BY ๊ตฌ๋ฌธ์„ ์ž‘์„ฑ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์‚ฌ์‹ค ์ •๋ ฌ์ด ์„ ํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ๊ตฌ๋ฌธ๋“ค(READ..BINARY SEARCH, DELETE ADJACENT DUPLICATES, AT NEW ๋“ฑ)์„ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์—๋Š” ๋Œ€๋ถ€๋ถ„์ด ์Šต๊ด€์ ์œผ๋กœ๋ผ๋„ SORT BY ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•œ๋‹ค. ๊ทธ๋ž˜์„œ HANA DB๋กœ ์ „ํ™˜ํ•œ ํ›„์—๋„ ๋ณ„๋‹ค๋ฅธ ์ด์Šˆ๊ฐ€ ์—†๋Š” ๊ฒƒ์ด ๋Œ€๋ถ€๋ถ„์ด๋‹ค. 

 

โ“ ๊ทธ๋Ÿฐ๋ฐ ๋˜ ๋‹ค๋ฅธ ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค. ๋งŒ์•ฝ ์˜ค๋ผํด DB์—์„œ HANA DB๋กœ ์ „ํ™˜ํ•˜๊ธฐ๋กœ ํ–ˆ๋Š”๋ฐ, ๊ทธ๋™์•ˆ ์ธ๋ฑ์Šค๋‚˜ ํ‚ค๊ฐ€ ์•Œ์•„์„œ ์ •๋ ฌํ•ด์ค„ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ž‘์„ฑํ–ˆ๋˜(SORT BY๋ฅผ ์ƒ๋žตํ–ˆ๋˜) ํ”„๋กœ๊ทธ๋žจ๋“ค์„ ์–ด๋–ป๊ฒŒ ์ฐพ์•„๋‚ผ๊นŒ? 

 

โ— SAP์—์„œ ์•Œ๋ ค์ค€ ๋ฐฉ๋ฒ•๋Œ€๋กœ ํ•˜๋ฉด ๋œ๋‹ค. SAP ๋‚ด๋ถ€์— ์žˆ๋Š” ์ฝ”๋“œ์ธ์ŠคํŽ™์…˜ ํˆด(T-code SCII, ๋์— ๋‘ ๊ธ€์ž๋Š” ๋Œ€๋ฌธ์ž i์ด๋‹ค)์„ ์ด์šฉํ•ด์„œ ์œ„ํ—˜์„ฑ์ด ์žˆ๋Š” ๊ตฌ๋ฌธ์„ ์ฐพ์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

 

T-code SCII๋ฅผ ์น˜๊ณ  ๋“ค์–ด๊ฐ€๋ฉด ์ฝ”๋“œ ์ธ์ŠคํŽ™ํ„ฐ๋ฅผ ํ†ตํ•ด ์ ๊ฒ€ํ•  ์ˆ˜ ์žˆ๋Š” ํ•ญ๋ชฉ๋“ค์ด ์ญ‰ ๋‚˜์—ด๋˜์–ด ์žˆ๋‹ค. ์ดํ•ด๋ฅผ ์œ„ํ•ด ํ•ด๋‹น ๋งํฌ๋ฅผ ์ผœ๋†“๊ณ  ํ™•์ธํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค. ์ด์ค‘์—์„œ Robust Programming์ด๋ผ๋Š” ์นดํ…Œ๊ณ ๋ฆฌ ์•„๋ž˜์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ•ญ๋ชฉ์ด ์žˆ๋‹ค. ์ด ํ•ญ๋ชฉ์„ ์ฒดํฌํ•˜๊ณ  ํŒจํ‚ค์ง€ ๋‹จ์œ„๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ๋Œ๋ฆฌ๋ฉด ์œ„ํ—˜์š”์†Œ๊ฐ€ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ๊ณผ ๊ตฌ๋ฌธ ์œ„์น˜๋ฅผ ์žก์•„๋‚ผ ์ˆ˜ ์žˆ๋‹ค. 

Search problematic statements for result of SELECT/OPEN CURSOR without ORDER BY

๐Ÿ“ข ์™œ HANA๋Š” ๋‹ค๋ฅผ๊นŒ

์‚ฌ์‹ค ์ด ๋ถ€๋ถ„์ด ์ œ์ผ ๊ถ๊ธˆํ•œ๋ฐ, ์•„์ง ๋ช…ํ™•ํ•œ ๋‹ต์„ ์ฐพ์ง€ ๋ชปํ–ˆ๋‹ค. ๊ทธ๋‚˜๋งˆ ์ฐพ์€ ์ž๋ฃŒ๋“ค์—์„œ๋Š” ๋Œ€๋ถ€๋ถ„ "HANA DB๊ฐ€ Column based DB์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค"๋ผ๊ณ ๋งŒ ์ด์•ผ๊ธฐํ•˜๊ณ , ๋” ์ž์„ธํ•œ ์ด์œ ๋‚˜ ์ž‘๋™ ๋ฐฉ์‹์„ ์„ค๋ช…ํ•˜์ง€๋Š” ์•Š๊ณ  ์žˆ๋‹ค. 

์™œ ๊ทธ๋Ÿด๊นŒ ์œ ์ถ”๋ผ๋„ ํ•˜๊ณ  ์‹ถ์€๋ฐ ์ผ๋‹จ DB ๊ณต๋ถ€๋ฅผ ์—ด์‹ฌํžˆ ํ•ด์•ผ๊ฒ ๋‹ค.

 


์ฐธ๊ณ 

https://launchpad.support.sap.com/#/notes/0002315679 

http://sapjoy.co.kr/index.php?mid=HANA&document_srl=113399&m=0 

https://cafe.naver.com/saphana/138

https://stackoverflow.com/questions/48690890/how-does-columnar-databases-do-indexing

'SAP' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[๊ธฐํƒ€] SAP GUI์™€ Application Server๊ฐ„ ํ†ต์‹  - DIAG ํ”„๋กœํ† ์ฝœ  (0) 2021.08.05