Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which mysql method is fast?

I am saving some text in database say 1000 characters. But I display only first 200 characters.

Method 1
I could save first 200 characters in one column and the remaining in second column of sql table

Method 2
I can save everything in one column and while displaying I can query for 200 characters

like image 994
madhu131313 Avatar asked Sep 03 '12 12:09

madhu131313


2 Answers

It would be "cleaner" to store everything in 1 column. and you can select only the first 200 characters like this

select substring(your_column, 1, 200) as your_column from your_table
like image 193
juergen d Avatar answered Oct 19 '22 11:10

juergen d


It really is irrelevant, but if you try to optimize, then method 1 is better, as long as you limit your query to that column (or you only query these columns you really need), because doing any substring on server side takes time and resources (times number of requests...). Method 2 is cleaner, but you are optimize for time so method 1.

like image 34
Marcin Orlowski Avatar answered Oct 19 '22 09:10

Marcin Orlowski