Skip to content
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

[IDLE-322] 도서 저자, 번역가 반정규화 이후 추천 피드 쿼리 수정 #20

Merged
merged 3 commits into from
Mar 31, 2024

Conversation

minnseong
Copy link
Member

@minnseong minnseong commented Mar 26, 2024

🧑‍💻 작업 사항

도서 엔티티 내 저자, 번역가 반정규화

(as-is)

  • BookAuthors 와 BookTranslators 로 일대다 - 다대다 - 다대일 관계로 Authors와 Translators가 Book 과 연관관계가 있었음.
  • Authors와 Translators를 조회할 때, 두번의 Join이 발생함.
  • 해당 데이터는 잘 변화하지 않는 데이터이기 때문에 반정규화로 저장, 도서 저장시 Authors와 Translators를 , 로 이어서 저장.
  • BookAuthors 와 BookTranslators 도 유지. 추후에 저자, 번역가로 도서를 조회하기 위해서

(to-be)

  • 저자, 번역가를 반정규화 하여 도서 저장시 Authors와 Translators를 , 로 이어서 저장
  • 저자, 번역가를 조회시, 조인없이 도서 조회시 칼럼으로 조회
  • 디비 보정 필요

보정 쿼리

— 도서 저자 , 로 concat
SELECT A.book_id, GROUP_CONCAT(B.name SEPARATOR ', ') AS ‘’authors”
FROM books_authors A RIGHT OUTER JOIN authors B
ON A.author_id = B.id
GROUP BY A.book_id;

— 도서 번역가 , 로 concat
SELECT A.book_id, GROUP_CONCAT(B.name SEPARATOR ', ') AS ‘’translators”
FROM books_translators A RIGHT OUTER JOIN translators B
ON A.translator_id = B.id
GROUP BY A.book_id;

— authors 디비 보정
Update books C, (SELECT A.book_id as book_id, GROUP_CONCAT(B.name SEPARATOR ', ') AS authors
FROM books_authors A RIGHT OUTER JOIN authors B
ON A.author_id = B.id
GROUP BY A.book_id) D
SET C.authors = D.authors
WHERE [C.id](http://c.id/) = D.book_id;

— translators 디비 보정
Update books C, (SELECT A.book_id as book_id, GROUP_CONCAT(B.name SEPARATOR ', ') AS translators
FROM books_translators A RIGHT OUTER JOIN translators B
ON A.translator_id = B.id
GROUP BY A.book_id) D
SET C.translators = D.translators
WHERE [C.id](http://c.id/) = D.book_id;

보정 결과

image



🔗 링크



🐰 시급한 정도



📖 참고 사항

Copy link

@minnseong minnseong merged commit 3d0b37a into develop Mar 31, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant