944,198 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1845
  • MySQL RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 8th, 2009
0
Re: How to store a big database
Hey.

If you have a table with a VARCHAR field, you can often improve search performance on it by changing the field to the CHAR type. It has a static length, which allows MySQL to calculate a static row size for all the rows, rather then having to calculate a row size for each row. This allows it to scan the rows faster.

You won't notice any difference tho. If you provide to sort a string, MySQL will automatically pad it with spaces, and then trim them when you fetch it. The only difference is that it will increase the storage space required.

Click to Expand / Collapse  Quote originally posted by mwasif ...
Then you must use TEXT type if the length is more than 255.
That's not true anymore. VARCHAR used to be maximum 255 chars before 5.0, but now it can be a lot bigger.

Quote originally posted by http://dev.mysql.com/doc/refman/5.0/en/char.html ...
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Nov 8th, 2009
0
Re: How to store a big database
Quote ...
If you have a table with a VARCHAR field, you can often improve search performance on it by changing the field to the CHAR type.
So is the char field type faster than text field type? Because that's what I really need to know although it's a bugga it will consume more space for faster performance.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Nov 9th, 2009
0
Re: How to store a big database
Click to Expand / Collapse  Quote originally posted by cwarn23 ...
So is the char field type faster than text field type? Because that's what I really need to know although it's a bugga it will consume more space for faster performance.
Not really, no. The field itself isn't faster.

What makes it faster is that it will always have the same size for every row. If you create a CHAR(50) column and only put 20 characters into one of the fields, MySQL will still use 50 characters to store that field. It would append 30 spaces to the original 20 and store that. (And then remove the 30 spaces when you fetch the data, so no worries there.)

TEXT and VARCHAR (and VARBINARY) are variable-length fields, which shrink to fit the data each field stores. This means that when MySQL searches the table, it has to calculate the position of the data within the data-file on a per-row basis, whereas when you only use fixed-length fields, it can assume all the rows are the same size and calculate where the data is for the entire table before it starts searching.

So in short, yes, CHAR is faster than VARCHAR, but only if ALL the fields in the table are fixed-size. If you have 3 VARCHAR, TEXT or VARBINARY fields in a table, swapping one out won't change anything. It's all or nothing.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Nov 9th, 2009
0
Re: How to store a big database
Please note tho, that the performance gain from using this method is usually very minor when compared to other optimization methods, such as properly indexing the fields.

A well placed index can be the difference between counting query speeds in minutes and milliseconds. (True story!)
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Nov 9th, 2009
0
Re: How to store a big database
Did you know that with todays cpu speeds the average computer can calculate the reverse lookup of any hash that contains up to two digits. So if there are >=2 digits being stored in a hash then the computer can calculate the original two digit string within less than a second. Just a thing I learnt when creating a dehasher in Java.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Nov 11th, 2009
0
Re: How to store a big database
Click to Expand / Collapse  Quote originally posted by cwarn23 ...
Did you know that with todays cpu speeds the average computer can calculate the reverse lookup of any hash that contains up to two digits. So if there are >=2 digits being stored in a hash then the computer can calculate the original two digit string within less than a second. Just a thing I learnt when creating a dehasher in Java.
Oops... Wrong thread for this post...
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Nov 11th, 2009
0
Re: How to store a big database
Click to Expand / Collapse  Quote originally posted by cwarn23 ...
Did you know that with todays cpu speeds the average computer can calculate the reverse lookup of any hash that contains up to two digits. So if there are >=2 digits being stored in a hash then the computer can calculate the original two digit string within less than a second.
Just a thing I learnt when replying to a MySQL thread
Reputation Points: 29
Solved Threads: 47
Posting Whiz
mwasif is offline Offline
312 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Get ID from table
Next Thread in MySQL Forum Timeline: About a SELECT command to execute in my MysQL Database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC