I want to do something similair to what imgur and most other websites do: I want to use a random string in the URL to identify whatever post a user is looking for.
Using a random string like that as a primary key would probably not be a very good idea, and making sure the randomly generated string isn't taken already, while the user is sending a submission, would slow down a table over time, as it would need to check more and more records to make sure there are no duplicates. How would one go about implementing random strings like that for identification?
My idea, and please tell me if it's a really bad idea, is to have a table that is filled with these random strings. The table would look like this:
| submissionId | stringId
+--------------+----------
| 1 | rbMZV
+--------------+----------
| 2 | MQyPi
+--------------+----------
| NULL | hfXL7
When these strings are generated, they don't have a submissionId assigned, like "hfXL7" in my example table. When a submission is made by a user, my script will take the first randomly generated string that doesn't have a submissionId assigned yet and adds the submissionId generated when the submission was made to that record. I have a process somewhere that regularly generates more strings that can be used as people make more submissions, so when someone makes a submission, there is always at least one randomly generated string without a submissionId yet.