tags:

views:

71

answers:

3

I've been using varchar(300),but I've also noticed longer urls.

+2  A: 

Use TEXT, it's enough for every URL.

Note that with long URLs, you won't be able to create an index that covers the whole URL. If you need a UNIQUE index, you should calculate the URL hash, store the hash separately and index the hash instead.

Quassnoi
Is it proper/standard way?
What do you mean by "it"? `TEXT` is a standard and supported feature, `MD5` hashing is too (and `MySQL` contains a function for calculating the hash).
Quassnoi
That's how I do it, as well. Also, it's worth considering benchmarking various hash functions, I chose MD5, since it's slightly faster than all the others, but MD4.
Nikola Kotur
Seems there is no `MD4` in PHP.
@Nikola: `MySQL` lacks `MD4` supports, but if it did, it would certainly be a preferred hash function.
Quassnoi
Does this solution require a separate table to link hashes and urls ? These columns will obviously depend on each other.
eugene y
@Quassnoi, yes, you're right, but I don't hash in MySQL (it showed slower), YMMV.@eugene y, hash is one of the columns in the table.
Nikola Kotur
@unknown googler, yes it does, via Hash cryptography extension, do print_r(hash_algos()).
Nikola Kotur
A: 

As you can see here, browsers can handle different URL lengths (and very long). So you should consider using text as data type.

Felix Kling
+1  A: 

Technically HTTP does not put a limit on the max length of a URL. Read this SO post.

So varchar will not be of help, You'll have to use TEXT

codaddict