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 > ---------------------------------------- > ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |
| Thread Tools | |
| Display Modes | |
|
|