Re: Database tuning

From: Antonio Fiol Bonnín <fiol(at)w3ping(dot)com>
To: Nevermind <never(at)nevermind(dot)kiev(dot)ua>, PostgreSQL General Mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Database tuning
Date: 2001-12-21 20:11:41
Message-ID: 3C23977D.6000109@w3ping.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
>
>>XXX is a random value ranking from 0 (or 1) to the maximum id value. You
>>generate it outside the database.
>>
>Maximum id is not good solution, beacuse some of ids between 0 (or 1)
>could be missing for some reasons. You should:
>
>select id from table;
>
SEQ SCAN. Avoid for big tables.

>Then chose random one outside SQL, and then:
>
>select * from table where table.id = '$random_id';
>
>This would be slower but will work for sure.
>
Probably even slower than original. Not sure, though.

>Another approach -- select random id outside SQL from 0 (or 1) to
>maximum_id and then trying to select with 'where table.id =
>'$random_id'' until you've got > 0 rows in result.
>
The only drawback that I see to this approach is that it may not find a
result in a finite time.

Better: "Compress" your table so that it holds all continuous IDs. This
may be painful and long, but it will pay off in the end, if your table
is not updated often, so this operation only needs to be done once.

I guess The Bible is not updated very often. ;-)

Antonio

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nevermind 2001-12-21 20:17:47 Re: Database tuning
Previous Message Helge Bahmann 2001-12-21 20:09:24 udp port