Skip to content

Commit 9d547eb

Browse files
docs(blog): 13차 배치 팁 포스트 5개 추가 (3개 언어)
1 parent 0ccad33 commit 9d547eb

15 files changed

Lines changed: 993 additions & 0 deletions
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: post
3+
title: "git bisect - Find the Bug-Introducing Commit with Binary Search"
4+
date: 2026-03-15 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [Git, git bisect, Debugging, Binary Search]
7+
author: "Kevin Park"
8+
lang: en
9+
excerpt: "Use git bisect to quickly find the exact commit that introduced a bug using binary search."
10+
---
11+
12+
## Problem
13+
14+
A bug appeared at some point, but with hundreds of commits to check, going through them one by one was impossible. All I knew was "it worked last week."
15+
16+
## Solution
17+
18+
`git bisect` uses binary search to find the commit that introduced a bug. Even 1024 commits only need 10 checks.
19+
20+
```bash
21+
# Start bisect
22+
git bisect start
23+
24+
# Mark current state (has bug) as bad
25+
git bisect bad
26+
27+
# Mark a known working commit as good
28+
git bisect good abc1234
29+
```
30+
31+
Git checks out a commit in the middle. Test it and report the result.
32+
33+
```bash
34+
# If this commit has the bug
35+
git bisect bad
36+
37+
# If this commit works fine
38+
git bisect good
39+
40+
# Repeat until it finds the culprit
41+
# "abc5678 is the first bad commit"
42+
```
43+
44+
With a test script, you can fully automate the process.
45+
46+
```bash
47+
# Exit code 0 = good, non-zero = bad
48+
git bisect run npm test
49+
50+
# Or use a custom script
51+
git bisect run ./check-bug.sh
52+
```
53+
54+
When done, return to your original branch.
55+
56+
```bash
57+
git bisect reset
58+
```
59+
60+
## Key Points
61+
62+
- For N commits, you need at most log2(N) checks. 1000 commits? Just 10 checks
63+
- `git bisect run` automates the entire process — hands-free bug hunting
64+
- If you hit a commit that doesn't build, use `git bisect skip` to skip it
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: post
3+
title: "git bisectでバグの原因コミットを特定する - 二分探索デバッグ"
4+
date: 2026-03-15 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [Git, git bisect, Debugging, Binary Search]
7+
author: "Kevin Park"
8+
lang: ja
9+
excerpt: "git bisectを使って、バグを導入したコミットを二分探索で素早く特定する方法をご紹介します。"
10+
---
11+
12+
## 問題
13+
14+
ある時点からバグが発生しましたが、コミットが数百件あり、一つずつ確認するのは不可能でした。「先週までは動いていたのに...」と繰り返すばかりでした。
15+
16+
## 解決方法
17+
18+
`git bisect`は二分探索でバグを導入したコミットを見つけてくれます。1024個のコミットでも10回の確認で済みます。
19+
20+
```bash
21+
# bisectを開始
22+
git bisect start
23+
24+
# 現在の状態(バグあり)をbadとしてマーク
25+
git bisect bad
26+
27+
# バグがなかった時点をgoodとしてマーク
28+
git bisect good abc1234
29+
```
30+
31+
gitが中間のコミットにチェックアウトしてくれます。テストして結果を報告します。
32+
33+
```bash
34+
# このコミットにバグがある場合
35+
git bisect bad
36+
37+
# このコミットにバグがない場合
38+
git bisect good
39+
40+
# 繰り返すと原因コミットを特定してくれます
41+
# "abc5678 is the first bad commit"
42+
```
43+
44+
テストスクリプトがあれば完全自動化も可能です。
45+
46+
```bash
47+
# スクリプトの終了コード0ならgood、それ以外ならbad
48+
git bisect run npm test
49+
50+
# または特定のスクリプトを指定
51+
git bisect run ./check-bug.sh
52+
```
53+
54+
終了したら元のブランチに戻ります。
55+
56+
```bash
57+
git bisect reset
58+
```
59+
60+
## ポイント
61+
62+
- コミット数がN個なら最大log2(N)回の確認で済みます。1000コミットでも10回で十分です
63+
- `git bisect run`でテストを自動化すれば、完全に手放しで原因を特定できます
64+
- bisect中にビルドできないコミットに当たった場合は`git bisect skip`でスキップできます
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: post
3+
title: "git bisect로 버그 원인 커밋 찾기 - 이진 탐색 디버깅"
4+
date: 2026-03-15 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [Git, git bisect, Debugging, Binary Search]
7+
author: "Kevin Park"
8+
lang: ko
9+
excerpt: "git bisect를 사용해 버그를 만든 커밋을 이진 탐색으로 빠르게 찾는 방법을 정리한다."
10+
---
11+
12+
## 문제
13+
14+
어느 시점부터 버그가 생겼는데 커밋이 수백 개라 하나씩 확인하는 건 불가능했다. "분명 지난주까지는 됐는데..."라는 말만 반복하고 있었다.
15+
16+
## 해결
17+
18+
`git bisect`는 이진 탐색으로 버그를 만든 커밋을 찾아준다. 1024개 커밋도 10번만 확인하면 된다.
19+
20+
```bash
21+
# bisect 시작
22+
git bisect start
23+
24+
# 현재(버그 있음)를 bad로 표시
25+
git bisect bad
26+
27+
# 버그 없던 시점을 good으로 표시
28+
git bisect good abc1234
29+
```
30+
31+
이제 git이 중간 커밋으로 체크아웃해준다. 테스트하고 결과를 알려주면 된다.
32+
33+
```bash
34+
# 이 커밋에서 버그가 있으면
35+
git bisect bad
36+
37+
# 이 커밋에서 버그가 없으면
38+
git bisect good
39+
40+
# 반복하면 원인 커밋을 찾아준다
41+
# "abc5678 is the first bad commit"
42+
```
43+
44+
테스트 스크립트가 있으면 완전 자동화도 가능하다.
45+
46+
```bash
47+
# 스크립트 종료코드 0이면 good, 아니면 bad
48+
git bisect run npm test
49+
50+
# 또는 특정 스크립트
51+
git bisect run ./check-bug.sh
52+
```
53+
54+
끝나면 원래 브랜치로 돌아간다.
55+
56+
```bash
57+
git bisect reset
58+
```
59+
60+
## 핵심 포인트
61+
62+
- 커밋 수가 N개면 최대 log2(N)번만 확인하면 된다. 1000개 커밋도 10번이면 충분하다
63+
- `git bisect run`으로 테스트를 자동화하면 아예 손 안 대고 원인을 찾을 수 있다
64+
- bisect 중에 빌드가 안 되는 커밋을 만나면 `git bisect skip`으로 건너뛸 수 있다
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
layout: post
3+
title: "PostgreSQL JSONB Query Optimization with GIN Index"
4+
date: 2026-03-16 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [PostgreSQL, JSONB, GIN Index, Database]
7+
author: "Kevin Park"
8+
lang: en
9+
excerpt: "Speed up PostgreSQL JSONB queries by adding a GIN index for fast key-value lookups inside JSON data."
10+
---
11+
12+
## Problem
13+
14+
Stored user settings in a JSONB column, but querying by specific keys triggers a full table scan.
15+
16+
```sql
17+
-- metadata column is JSONB
18+
SELECT * FROM users
19+
WHERE metadata->>'role' = 'admin';
20+
-- Seq Scan... slow
21+
```
22+
23+
## Solution
24+
25+
A GIN index enables indexed lookups inside JSONB data.
26+
27+
```sql
28+
-- Create GIN index
29+
CREATE INDEX idx_users_metadata ON users USING GIN (metadata);
30+
31+
-- Use @> containment operator (uses GIN index)
32+
SELECT * FROM users
33+
WHERE metadata @> '{"role": "admin"}';
34+
```
35+
36+
If you only query specific keys, an expression index is more efficient.
37+
38+
```sql
39+
-- B-tree index on a specific path
40+
CREATE INDEX idx_users_role ON users ((metadata->>'role'));
41+
42+
-- This query now uses the index
43+
SELECT * FROM users
44+
WHERE metadata->>'role' = 'admin';
45+
```
46+
47+
Nested JSON is accessible via path operators.
48+
49+
```sql
50+
-- Access nested keys
51+
SELECT * FROM users
52+
WHERE metadata #>> '{address,city}' = 'Seoul';
53+
54+
-- jsonpath also works (PostgreSQL 12+)
55+
SELECT * FROM users
56+
WHERE metadata @? '$.tags[*] ? (@ == "vip")';
57+
```
58+
59+
## Key Points
60+
61+
- Use the `@>` containment operator to leverage GIN indexes. The `->>` operator requires an expression index instead
62+
- GIN indexes slow down writes — best suited for read-heavy tables
63+
- Always use JSONB over JSON. JSONB stores data in binary format, making searches significantly faster
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
layout: post
3+
title: "PostgreSQL JSONBクエリ最適化 - GINインデックスで高速検索"
4+
date: 2026-03-16 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [PostgreSQL, JSONB, GIN Index, Database]
7+
author: "Kevin Park"
8+
lang: ja
9+
excerpt: "PostgreSQLのJSONBカラムにGINインデックスを設定し、JSONデータを高速に検索する方法をご紹介します。"
10+
---
11+
12+
## 問題
13+
14+
ユーザー設定をJSONBカラムに保存しましたが、特定のキーで検索するとフルスキャンが走って遅くなりました。
15+
16+
```sql
17+
-- metadataカラムがJSONBのテーブル
18+
SELECT * FROM users
19+
WHERE metadata->>'role' = 'admin';
20+
-- Seq Scan... 遅い
21+
```
22+
23+
## 解決方法
24+
25+
GINインデックスを作成すると、JSONB内部のキー・値検索がインデックスを利用できます。
26+
27+
```sql
28+
-- GINインデックスを作成
29+
CREATE INDEX idx_users_metadata ON users USING GIN (metadata);
30+
31+
-- @>演算子で検索(GINインデックスを使用)
32+
SELECT * FROM users
33+
WHERE metadata @> '{"role": "admin"}';
34+
```
35+
36+
特定のキーだけを頻繁に検索する場合は、Expressionインデックスがより効率的です。
37+
38+
```sql
39+
-- 特定パスにB-treeインデックス
40+
CREATE INDEX idx_users_role ON users ((metadata->>'role'));
41+
42+
-- このクエリがインデックスを利用するようになります
43+
SELECT * FROM users
44+
WHERE metadata->>'role' = 'admin';
45+
```
46+
47+
ネストされたJSONもパス演算子でアクセスできます。
48+
49+
```sql
50+
-- ネストされたキーへのアクセス
51+
SELECT * FROM users
52+
WHERE metadata #>> '{address,city}' = 'Seoul';
53+
54+
-- jsonpathも使用可能(PostgreSQL 12以降)
55+
SELECT * FROM users
56+
WHERE metadata @? '$.tags[*] ? (@ == "vip")';
57+
```
58+
59+
## ポイント
60+
61+
- `@>`包含演算子を使うことでGINインデックスが利用されます。`->>`演算子にはGINではなくExpressionインデックスが必要です
62+
- GINインデックスは書き込みが遅くなるトレードオフがあります。読み取り中心のテーブルに適しています
63+
- JSONBはバイナリ形式で保存されるため、JSONより検索が高速です。カラム型はJSONではなくJSONBを使いましょう
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
layout: post
3+
title: "PostgreSQL JSONB 쿼리 최적화 - GIN 인덱스로 빠르게 검색하기"
4+
date: 2026-03-16 09:00:00 +0900
5+
categories: [Development, Tips]
6+
tags: [PostgreSQL, JSONB, GIN Index, Database]
7+
author: "Kevin Park"
8+
lang: ko
9+
excerpt: "PostgreSQL JSONB 컬럼에 GIN 인덱스를 걸어 JSON 데이터를 빠르게 검색하는 방법을 정리한다."
10+
---
11+
12+
## 문제
13+
14+
사용자 설정을 JSONB 컬럼에 저장했는데, 특정 키로 검색하면 풀 스캔을 때려서 느렸다.
15+
16+
```sql
17+
-- metadata 컬럼이 JSONB인 테이블
18+
SELECT * FROM users
19+
WHERE metadata->>'role' = 'admin';
20+
-- Seq Scan... 느리다
21+
```
22+
23+
## 해결
24+
25+
GIN 인덱스를 걸면 JSONB 내부 키/값 검색이 인덱스를 탄다.
26+
27+
```sql
28+
-- GIN 인덱스 생성
29+
CREATE INDEX idx_users_metadata ON users USING GIN (metadata);
30+
31+
-- @> 연산자로 검색 (GIN 인덱스 사용)
32+
SELECT * FROM users
33+
WHERE metadata @> '{"role": "admin"}';
34+
```
35+
36+
특정 키만 자주 검색한다면 Expression 인덱스가 더 효율적이다.
37+
38+
```sql
39+
-- 특정 경로에 B-tree 인덱스
40+
CREATE INDEX idx_users_role ON users ((metadata->>'role'));
41+
42+
-- 이제 이 쿼리가 인덱스를 탄다
43+
SELECT * FROM users
44+
WHERE metadata->>'role' = 'admin';
45+
```
46+
47+
중첩된 JSON도 경로 연산자로 접근 가능하다.
48+
49+
```sql
50+
-- 중첩 키 접근
51+
SELECT * FROM users
52+
WHERE metadata #>> '{address,city}' = 'Seoul';
53+
54+
-- jsonpath도 사용 가능 (PostgreSQL 12+)
55+
SELECT * FROM users
56+
WHERE metadata @? '$.tags[*] ? (@ == "vip")';
57+
```
58+
59+
## 핵심 포인트
60+
61+
- `@>` 포함 연산자를 써야 GIN 인덱스를 탄다. `->>` 연산자는 GIN이 아니라 Expression 인덱스가 필요하다
62+
- GIN 인덱스는 쓰기가 느려지는 트레이드오프가 있다. 읽기 위주 테이블에 적합하다
63+
- JSONB는 바이너리 저장이라 JSON보다 검색이 빠르다. 컬럼 타입을 JSON이 아닌 JSONB로 쓰자

0 commit comments

Comments
 (0)