Does varchar and Text affect the database size?
Also, do they differ in speed?
I have a Database that will have at least 4000 to 8000 new rows per day.
I'm quite worried about how it performs. This is my first time setting up an Enterprise-grade system and database though.
Best Answer
Use what you need and don't worry about performance. But use only what you need. There are minor inefficiencies in saying
TEXT
whenVARCHAR(255)
will suffice. Ditto forVARCHAR(255)
whenVARCHAR(20)
will suffice.Here's why: If a
SELECT
needs build a tmp table (eg, forORDER BY
), it first tries to use aMEMORY
tmp table (better), but may have to fall back on aMyISAM
table (slower). Any kind ofTEXT
orBLOB
forcesMyISAM
.VARCHAR
turns intoCHAR
(for the tmp table); if the tmp table gets too big forMEMORY
, it converts toMyISAM
.TINYTEXT
is probably never a good idea.A related issue:
CHAR(...)
is useful only if the field is (1) constant length, and (2) declared with the appropriateCHARACTER SET
. A common mistake is putting a fixed-length hex string in a utf8 CHAR field.VARCHAR
andTEXT
(all sizes) have a small length field prefixing them. This is relatively insignificant.