Reputation: 37
I would like to store the APNS device token and FCM registrationID in a MySQL database. I would like an index on the column that contains the token because I will be performing lookups using it and I expect the table to be considerably large (millions of rows).
As I understand it, there are no real limitations on the size of the device token that APNS or FCM uses. The documentation for APNS explicitly states to not make assumptions regarding the size (although it appears to be 64 characters). Due to this, I was planning on storing it as a longtext field in a MySQL database. However, MySQL prevents the creation of indexes that are greater than 767 characters.
Here are the options I am considering:
Which of these options seems like the better way to go about this? Can you think of any alternative options?
Upvotes: 1
Views: 1199
Reputation: 108776
Please don't use a CLOB (xxxTEXT) data type for this. They're grossly inefficient to store and index. This is a device token, so even if its length is not specified, it won't be dozens of kilobytes (MEDIUMTEXT) let alone many megabytes (LONGTEXT).
It looks like these are presently 64 characters of hex digits (0123456789abcdef). So, to be future proof you can use
token VARCHAR(256) COLLATE latin1_bin NOT NULL
as the column definition. 256, four times the present size, should be enough for a while (that's a lot of mobile devices; the IPV6 address space will fill up first). And, the latin1 character set and bin collation will make for efficient index lookups.
Upvotes: 2