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

Posted by Oden on Stack Overflow See other posts from Stack Overflow or by Oden
Published on 2010-05-17T06:11:09Z Indexed on 2010/05/17 6:20 UTC
Read the original article Hit count: 276

Filed under:
|
|
|

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

The first one i thought about is a multi table setup, witch has a connection table, and a main table. The connection table holds the connection between accounts, and the messaging table.

In this case a query would look like following, to get some data of the author, and the messages he has sent:

SELECT m.*, a.username FROM messages AS m LEFT JOIN connection_table ON (message_id = m.id) LEFT JOIN accounts AS a ON (account_id = a.id) WHERE m.id = '32341'

Inserting into it is a little bit more "complicated".

My other idea, and in my thought the better solution of this problem is that i store the data i would use in a connection table in the same table where is store the data of the mail. Sounds like i would get lots of duplicated entries, but no, because i have a field witch has text type and holds user ids like this: *24*32*249* If I want to query them, i use the mysql LIKE method. Deleting is an other problem, but for this i have one more field where i store who has deleted the post. Sad about that i don't know how to join this.

So what would you recommend? Are there other ways?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query