๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ์ƒํ™œ/์ด์Šˆ ๋ฐœ์ƒ

Select ์ฟผ๋ฆฌ ์‹คํ–‰ ์ค‘ Apparent connection leak detected

by cocococo331 2022. 12. 1.

Batch ๋™์ž‘ ์ค‘ Select ์ฟผ๋ฆฌ ์‹คํ–‰ํ•˜๋ฉด์„œ ๊ฐ„ํ—์ ์œผ๋กœ Leak์ด ๋‚œ๋‹ค.
-> java.lang.Exception: Apparent connection leak detected

๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ์กฐ๊ฑด๊ณผ ๋™์ผํ•˜๊ฒŒ Database Tool๋กœ ๋Œ๋ ค๋ณด์•˜๋‹ค.
์ฟผ๋ฆฌ ์ž์ฒด๋Š” ์‹คํ–‰์ด ๋˜๋Š”๋ฐ Output์— ๊ฒฝ๊ณ ๊ฐ€ ๋œฌ๋‹ค.

-> Memory capacity of 8388608 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.

๋ฌธ์ œ๋Š” IN์ ˆ์— ๋„˜๊ธด ํŒŒ๋žŒ ๊ฐœ์ˆ˜..
IN์ ˆ์˜ ๊ฐœ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ๊ฒฝ์šฐ, Where ์กฐ๊ฑด ๋ฒ”์œ„๊ฐ€ DB์— ์ œํ•œ๋œ ๋ฉ”๋ชจ๋ฆฌ 8388608 Bytes๋ฅผ ์ดˆ๊ณผํ•œ๋‹ค.
์ด๋Ÿฐ ๊ฒฝ์šฐ Index๋ฅผ ํƒ€์ง€ ์•Š๊ณ  Full Scan ๋˜์–ด ๊ฒฐ๊ณผ์ ์œผ๋กœ Memory Leak์ด ๋ฐœ์ƒํ•˜๊ฒŒ ๋œ๋‹ค.

ํ•ด๋‹น ์ฟผ๋ฆฌ๋“ค์˜ IN์ ˆ ํŒŒ๋žŒ ๊ฐœ์ˆ˜๋ฅผ ์กฐ์ •ํ•ด๋ณด๋ฉด์„œ ์‹คํ–‰ ๊ณ„ํš์„ ํ™•์ธํ•ด๋ดค์„ ๋•Œ, IN์ ˆ์ด ๋ช‡ ๊ฐœ๋ƒ์— ๋”ฐ๋ผ ๋™์ผ ์ฟผ๋ฆฌ Explain์ด ๋‹ค๋ฅด๋‹ค.

ํ•ด๊ฒฐ์ฑ…์œผ๋กœ range_optimizer_max_mem_size๋ฅผ ์กฐ์ •ํ•˜๋ผ๊ณ  ํ•˜๋Š”๋ฐ.. DB ์„ค์ •์„ ๋‚ด๋ง˜๋Œ€๋กœ ๋ณ€๊ฒฝํ–ˆ๋”ฐ๊ฐ€ ๋‹ค๋ฅธ ์‚ฌ์ด๋“œ ์ดํŽ™์ด ์–ด์ผ€ ํ„ฐ์งˆ์ง€ ๋ชจ๋ฅธ๋‹ค.
์ผ๋‹จ in์ ˆ์˜ ๊ฐœ์ˆ˜๋ฅผ ์กฐ์ •ํ•ด๋ณด์ž.. application code level์—์„œ 200๊ฐœ๋กœ ์ œํ•œํ•˜๋‹ˆ memory leak์€ ์•ˆ๋‚˜๊ณ  ์ž˜ ๋„˜์–ด๊ฐ”๋‹ค