database - How to store data in mysql, to get the fastest performance? -


I'm thinking about it, which of the following two query types would give me the fastest performance for a user messaging module My site:

I thought that there is a multi-table setup first, which has a connection table, and a main table. The connection is between the accounts and the messaging table in the table.

In this case, a question will appear below, to get some data from the author, and the message he sent:

  Select M. *, Leave the message A.username as M. Connect_table ON (message_id = m.id) LEFT JOIN account as a current (account_id = a.id) WHERE m.id = '32341'  < / Pre> 

Putting it in is a bit more "complex".

My second idea is, and in my opinion, the better solution to this problem is that I store the data I will use in the same table in a connection table where the data of the mail is stored. Looks like I'll get many duplicate entries, but no, because I have an area in which there is a text type and there is a user ID like this: * 24 * 32 * 24 9 * If I want to ask them, then I would like mysql I'm using a method like this. Removal is another problem, but for this I have another area where I have removed the post. It is sad that I do not know how to get involved.

So what would you recommend? Are there any other ways?

Looks like you're using a n: m connection .. If yes, then a Do not list the IDs in the column, but create two column mapping tables - the primary key of Table 1 and the primary key of Table 2, then selecting, inserting and deleting will be all easy and still cheaper.


Comments