Re: Database tuning - Mailing list pgsql-general

From Antonio Fiol Bonnín
Subject Re: Database tuning
Date
Msg-id 3C23977D.6000109@w3ping.com
Whole thread Raw
In response to Database tuning  ("K Old" <kevsurf4@hotmail.com>)
Responses Re: Database tuning
Re: Database tuning
List 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




pgsql-general by date:

Previous
From: Helge Bahmann
Date:
Subject: udp port
Next
From: Nevermind
Date:
Subject: Re: Database tuning