Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
what to choose VARCHAR or TEXT?
Old 03-27-2007, 11:32 PM what to choose VARCHAR or TEXT?
crush123's Avatar
Webmaster Talker

Posts: 526
Trades: 0
hello,

at first, I have declared the fields in my table like this:

...
title varchar(200) default NULL,
description text,
keywords text,
details text
....

But I have limited 'description' and 'keywords' to 300 characters each and 'details' to 1000 characters in my php script.

Now, shall I change it like this:
...
title varchar(200),
description varchar(300),
keywords varchar(300),
details varchar(1000),
....

I have a fulltext index on these fields and I wish to optimize my table for good performance.

please inform me how should I declare my fields.
thank you.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
crush123 is offline
Reply With Quote
View Public Profile Visit crush123's homepage!
 
 
Register now for full access!
Old 03-28-2007, 12:37 AM Re: what to choose VARCHAR or TEXT?
WebSavvy's Avatar
Extreme Talker

Posts: 166
Name: Deb
Trades: 0
If you've set a character limit in the PHP fields within your script, then maxlength of characters inserted into your db will be ONLY what you have set in your php form fields as maxlength.

Example, if I have a field called `tomorrow` and set the maxlength in my form at 200 characters but I have defined the `tomorrow` field in my db as varchar(255) then the MAX data length that will be inserted into the field via my form will be *only* 200 characters (taken from my form maxlength) regardless of the amount of characters I have defined for field length in the db.

Generally, things like title, keywords, descriptions would all be varchar(255) and some field that would contain more information (larger amounts) like `details` would be set as text.

The maxlength of an index is 255.
You can add as many fields to an index as you want, as long as the length of field given to each (for the index only) doesn't equal more than 255.

Divide it up between the number of fields that you have and set each one to that number length.

Example, 5 fields in index using 255 maxlength on index means each field in the index can use a maxlength character set of 51 characters.

As long as the length of field is greater than 15 for each field added to the index, your index should be fine.

Are you using MyISAM?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
WebSavvy is offline
Reply With Quote
View Public Profile Visit WebSavvy's homepage!
 
Old 03-28-2007, 04:33 AM Re: what to choose VARCHAR or TEXT?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
In MYSQL prior to Ver 5 VARCHAR columns with a length greater than 255 are converted to the smallest text column type that will hold the data.
So VARCHAR(300) may well be converted to a TEXT type anyway.

For the "keywords" data, it would be a better idea to use a "normalised" structure to avoid massive duplication and wasted storage.

using an inverted index data storage as the model, you would have one table holding all the keywords and an ID number and a table holding the document IDs and the keyword IDs that go with the document.
You would then have a JOIN query to pull up the keywords for any given document.

It also makes it simple to do the reverse, and pull up all documents that are linked to a particular keyword.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to what to choose VARCHAR or TEXT?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12450 seconds with 12 queries