For querying purpose, any drawbacks for using string as a foreign key?

#1

I have an app which allows business to have its own workspace. And all activities, triggered by user, will be stored as audit log. Each audit log will have business_id and action_name_id.

In this app, user can view all audit logs and filter by action name. So user pass busines_id and action_name_id to get all action that user wants to see.

Currently, type of foreign key (action_name_id) is integer. However, in order to improve code readability, I would like to use string as a foreign key. My question here is that are there any drawbacks using foreign key as string when user try to query?

Thank you in advance.

(Ron Arévalo) #2

Hey @poerqw,

Changing from an int to a string shouldn’t have any drawbacks when you try to query. The only thing I can see is the size of the data would change.

Thanks,

Ron

#3

Thank you for your reply.

As you mentioned, only difference will be size of data. Which means that since string takes bigger size than integer, querying with integer will be quicker than querying with string. So if string key is not much bigger size than integer key, there shouldn’t be significant performance differences. Is my understanding correct?

Thank you in advance.

(Ron Arévalo) #4

Hey @poerqw,

That would be correct, the size of a STRING value is variable, but it’s recommended to keep values under 64 kilobytes to ensure performance.

Let us know if you have any more questions.

Thanks,

Ron

1 Like