In this scenarion I have some managers(around 150 in numbers). One of their daily job is to generate 50(constant) authorisation code (6-8 digit numbers) which are stored in db with their Id. If any authorisation code is used that code is marked as used and triggers delete them when they are 15 days old and have been used.
In my table i have set authorisation code as unique key. i generate a random number then query the db if it exists i generate another or i else save it.
Every thing is fine except my logic of checking the existence of number in db.This round trip + checking is causing significant delay as of now there are over 1090083 pending authorisation code. Since these authorisation code are in circulation we cant revoke it and with current load it is taking sometime to find new numbers.
I need to implement it in a different logic for which execution speed should be low regardles of number of random number that has been used.
My table is designed as follows
slno(auth increment) || auth_code (random code) || auth_by (created by) || used (1=used/0=unused)