-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 27.11 데이터베이스 인덱싱 #238 #263
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 이거 신기해서 찾아보고 질문드립니다!
index 데코레이터 사용할 때
@Index(['user_id', 'stock_code'])
같은 형태로 안써도 되나용??지금 위에 즐겨찾기같은 것도 그렇고..! user_id랑 stock_code는 둘이 조합했을 때 unique한거지. 각각 단일로 사용하면 절대 unique한 값이 아니잖아요.
이런 unique 하지 않는 값을 index로 하면 index를 사용해도 성능 향상에서는 큰 이점을 얻지 못하는 거 아닌가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 전문이 기억나지 않아서.. 부정확할 순 있습니다.
즐겨찾기의 경우에는 마이페이지 등에서 사용할 때 전체 목록을 조회할 때는
user_id
에 대해서만 많이 일어날 것만 같고, 그거 외에는user_id, stock_code
컬럼의 조합으로 많이 일어날 것 같긴하네요. 가장 많이 일어나는 게 이렇게 단일/복합 두개라면 둘 다 인덱스로 사용해도 좋을 것 같습니다!!!stock_code
단독으로 일어나는 경우가 없다면 그 인덱스는 지워도 될 거 같구요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마이페이지에서는 user_id를 조건으로 빈번하게 탐색하고, 체결 가능한 주문을 찾을 때에는 stock_code를 조건으로 빈번하게 탐색할 것 같다고 생각해서 인덱싱을 따로 진행했습니다! 그리고 orders 테이블에서는 user_id + stock_code 조합이 유니크하지 않아서ㅠㅠ 따로 유니크 조건은 걸어주지 않았어요.
생각해보니 자산 업데이트할 때 등등 user_id + stock_code 조합으로도 조회가 많이 발생하긴 하네요! 이따 생각해보고 추가하겠습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹ㅎㅎㅎ!! 덕분에 첨 알아가는 것도 알아가요!! 항상 감사합니다