Is there a performance penalty (or improvement) for using STRING(MAX)
instead of some fixed limit like STRING(256)
?
Asked
Active
Viewed 2,820 times
5

Maxim
- 4,075
- 1
- 14
- 23

Mike Curtiss
- 1,838
- 2
- 17
- 33
1 Answers
7
Nope. STRING(MAX)
is treated exactly the same as strings of limited length under-the-hood. Same applies for BYTES(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 using STRING(2)
.
Note that, according to the docs, you can always change the length limit for a string, except with one caveat:
- Supported Schema Updates: Increase or decrease the length limit for a
STRING
orBYTES
type (including toMAX
), unless it is a primary key column inherited by one or more child tables.

Mike Curtiss
- 1,838
- 2
- 17
- 33
-
Do you know what that MAX is? – danthegoodman Sep 21 '20 at 16:21
-
1I believe the answer is 10MiB (~10M bytes). Per: https://cloud.google.com/spanner/docs/data-types#string_type "The maximum size of a column value is 10MiB, which applies to scalar and array types." – Mike Curtiss Sep 22 '20 at 17:19
-
Duh, I was looking everywhere for that! Assumed it would be lower on the docs haha – danthegoodman Sep 22 '20 at 20:04