Is there a performance penalty (or improvement) for using STRING(MAX)
instead of some fixed limit like STRING(256)
?
Performance difference for STRING(MAX)?
3.5k views Asked by Mike Curtiss At
1
Is there a performance penalty (or improvement) for using STRING(MAX)
instead of some fixed limit like STRING(256)
?
Nope.
STRING(MAX)
is treated exactly the same as strings of limited length under-the-hood. Same applies forBYTES(MAX)
. So there is no performance difference.The main reason to use a fixed limit is if there are logical constraints you want to enforce in your schema. For example: if you are using a
STRING
to store 2-letter country codes, then you might want to usingSTRING(2)
.Note that, according to the docs, you can always change the length limit for a string, except with one caveat:
STRING
orBYTES
type (including toMAX
), unless it is a primary key column inherited by one or more child tables.