Good one-to-many relation practice in MySQL -


this question has answer here:

i developing structure of mysql database , i've faced small decisional problem structure.

i have 2 tables:

  1. all messages published on site.
  2. all comments published on site.

every message can have more 1 comment associated it. better way make connection between message , comments related it?

  1. have field comments contains id of related message.
  2. have field messages contains array of ids of related comments in json format.

i think first method used , mysql query used find comments have message_id of corresponding message. how efficient when there hundreds of thousands of comments?

will in case decoding json string , accessing comments exact unique id more efficient , fast?

i using python back-end if matters.

the first option way go. you'll have:

comment_id | message_id | comment_text | timestamp etc.

for mysql table can specify build index on first 2 columns performance.
10mio comments should work ok, test in advance test scenario yourself.

if want plan more, after 100,000 comments can following:

  • determine how many comments there on average per message
  • determine how many messages required 5mio comments
  • let's takes 50,000 messages 5mio comments
  • add comment_table1 [..] comment_table9 database
  • switch within python: if message_id > 50,000 -> @ comment_table2 etc.
  • of course, you'll have save comments accordingly

this should performant large number of entries.

you can adapt numbers individual hosting (performance) environment...


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -