<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>잠금 on 얼쑤 · Team Edo</title><link>https://team-edo.github.io/tags/%EC%9E%A0%EA%B8%88/</link><description>Recent content in 잠금 on 얼쑤 · Team Edo</description><generator>Hugo</generator><language>ko-kr</language><lastBuildDate>Wed, 28 Oct 2026 00:00:00 +0900</lastBuildDate><atom:link href="https://team-edo.github.io/tags/%EC%9E%A0%EA%B8%88/index.xml" rel="self" type="application/rss+xml"/><item><title>만료 배치에서 인덱스가 잠금 범위를 바꾸는 이유</title><link>https://team-edo.github.io/posts/2026/10/innodb-expiry-update-scan-locks/</link><pubDate>Wed, 28 Oct 2026 00:00:00 +0900</pubDate><guid>https://team-edo.github.io/posts/2026/10/innodb-expiry-update-scan-locks/</guid><description>&lt;p>얼쑤는 녹음 세션을 연 뒤 업로드가 오랫동안 오지 않으면 만료 배치에서 정리합니다. 쿼리는 &lt;code>RECORDING&lt;/code> 상태이면서 시작 시각이 마감보다 이른 세션만 찾아 &lt;code>FAILED&lt;/code>로 바꿉니다. 조건을 충족한 행이 적으면 쓰기 범위도 작아 보입니다. 잠금 범위를 검토할 때는 DB가 그 행들을 찾으려고 어떤 인덱스를 훑는지도 봐야 했습니다.&lt;/p>
&lt;h2 id="바꾼-행-수만으로는-잠금-범위를-알-수-없다">갱신 행 수와 잠금 범위의 차이&lt;/h2>
&lt;p>InnoDB의 &lt;code>UPDATE&lt;/code>는 조건에 맞는 행을 찾는 동안 잠금을 잡습니다. &lt;code>REPEATABLE READ&lt;/code>에서 범위를 훑으면 접근 경로에 따라 인덱스 레코드와 그 앞 간격에 next-key 잠금이 걸릴 수 있습니다. 조건을 좁히는 데 쓸 인덱스가 없어 전체 스캔을 택하면, 결과적으로 갱신한 행 수보다 넓은 범위가 잠길 수 있습니다. 새 세션을 넣을 자리가 그 간격 안에 있으면 삽입도 기다릴 수 있습니다. &lt;a href="https://dev.mysql.com/doc/refman/8.4/en/innodb-locks-set.html">InnoDB에서 문장별로 설정하는 잠금&lt;/a>&lt;/p></description></item></channel></rss>