Unix Technical Forum

select count(*) and limit

This is a discussion on select count(*) and limit within the pgsql Novice forums, part of the PostgreSQL category; --> Oscar Rodriguez Fonseca schrieb: > TABLE IN DB: > > > number_times | user_name | last_login > ---------------------------------------- > ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 04-17-2008, 10:53 PM
Verena Ruff
 
Posts: n/a
Default Re: select count(*) and limit

Oscar Rodriguez Fonseca schrieb:
> TABLE IN DB:
>
>
> number_times | user_name | last_login
> ----------------------------------------
> 1 | Paul | 11-12-2005
> 4 | Mary | 08-11-2005
> 5 | Charles | 01-02-2005
>
> [...]
>
> SELECT count(*) AS number_times,NULL AS user_name,NULL as last_login \
> FROM table UNION ALL SELECT * FROM table LIMIT 2;
>
> This has the practical drawback that you need an integer column in your
> table to get the query working as expected and the design drawback that
> it is a little bit weird and somewhat non-standard way of querying.
>

I think this is a little bit to weired. It should be possible for
another person what I am doing without explaing such a lot.

> BTW, I had a similar problem and solved it storing the full result list
> in a temporal variable on the server but "session-wise" (when the user
> opens another unrelated page, the application frees the variable). This
> is possible in my case because my app won't have more than 10 clients
> at once and therefore it don't represent much memory overhead

This is possible if there are only little users and only a few hundred
records. I have only few users, too, but some tenthousonds records and I
don't think it would be a good idea storing them completly in the
servers memory.

Regards,
Verena

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-17-2008, 10:53 PM
Verena Ruff
 
Posts: n/a
Default Re: select count(*) and limit

Hi,

Sean Davis schrieb:
> It should still work just fine, again with the caveat that it is an
> approximation and depends on the statistics available. Try comparing the
> output a few times for your count(*) and using EXPLAIN.
>

sometimes the difference is to much to go this way. EXPLAIN extimates
71000 rows but there are 95000. 10% would have been accaptle. I did
these tests on a freshly vacuumed database.

regards,
Verena

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-17-2008, 10:53 PM
Sean Davis
 
Posts: n/a
Default Re: select count(*) and limit




On 5/18/06 12:28 PM, "Verena Ruff" <lists@triosolutions.at> wrote:

> Hi,
>
> Sean Davis schrieb:
>> It should still work just fine, again with the caveat that it is an
>> approximation and depends on the statistics available. Try comparing the
>> output a few times for your count(*) and using EXPLAIN.
>>

> sometimes the difference is to much to go this way. EXPLAIN extimates
> 71000 rows but there are 95000. 10% would have been accaptle. I did
> these tests on a freshly vacuumed database.


You can change the statistics that are collected, if you like. Again, there
is stuff in the docs about doing that.

Sean


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-17-2008, 10:53 PM
Verena Ruff
 
Posts: n/a
Default Re: select count(*) and limit

Hi,

Sean Davis schrieb:
> You can change the statistics that are collected, if you like. Again, there
> is stuff in the docs about doing that
>

I didn't know that. Thanks for this hint, I'll read about it.

Regards,
Verena

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:44 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com