An extension on my last thought.

You could divide up the serial numbers. Sort of index them

e.g.

table 1

10001234
10001235
10001236
--------

table 2

11001234
11001235
--------

table 3

12001234


In your program you store the range of each table as a constant. Then when you need to check for a serial number you check a much reduced table.

And when you add one, you make sure you insert it in the correct table.

Just a thought.