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:
- all messages published on site.
- all comments published on site.
every message can have more 1 comment associated it. better way make connection between message , comments related it?
- have field comments contains id of related message.
- 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
Post a Comment