I've built a URL shortener using the Bijective Function algorithm as stated in Stack Overflow. My database table has two columns; ID and URL. For every input URL, the ID is automatically incremented its value is converted to base62. This value forms the slug for the shortened link.
Example: If ID is 42 then its base62 form is g (may differ according to the alphabet set). So the shortened URL is https://example.com/g.
Now I'd like to add custom URL support where the user chooses a custom URL slug. I could create another table to store custom URLs and then check both tables for a matching slug. But this seems rather inefficient.
Can anyone provide an efficient solution?
P.S. I'm using PHP and MySQL.