finding reusable ids

From: Kenji Morishige <kenjim(at)juniper(dot)net>
To: pgsql-general(at)postgresql(dot)org
Cc: kenjim(at)juniper(dot)net
Subject: finding reusable ids
Date: 2007-08-06 22:25:35
Message-ID: 20070806222535.GB1071@juniper.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table that creates "check-out" records that stores information when
a particular resource is being utilized. I want to maintain a friendly
shortened ID so people can reference these check outs.

At any given time, there should not be more than 999999 or so check-outs, so
as the check-outs get checked in, the old IDs would become available. What
is the best method to query for these resusable IDs that would not be
assigned to checked out items? It seems that it would be quite inefficient
to look at the entire table to see which ids exist, then increment
accordingly. For some reason, I feel that there would be something already
available to solve this.

example set:

uid co-id checked-in?
1 1 n
2 2 n
3 3 y
4 4 n
5 3 n

obviously, this is a small sample set, but the id 3 can be reused, so I'd
like to reuse it without using a external tracking mechansm. My table has
1,000,000+ records.

Kenji

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rodrigo Faccioli 2007-08-07 02:27:21 Intelligent Database in postgreSQL
Previous Message Tom Lane 2007-08-06 22:23:34 Re: [PERFORM] Planner making wrong decisions 8.2.4. Insane cost calculations.