Ad Widget

Collapse

Request with min aggregate in Postgres

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gwenaelle
    Junior Member
    • Feb 2008
    • 7

    #1

    Request with min aggregate in Postgres

    It's me again with my Postgres 7.4 database and my quest to speed up graph and screen display for long periods.
    I saw requests like this many times :
    Code:
    select min(clock) from history where itemid=18356
    and the same from table trends or history_uint, etc.

    This request takes a bit too much time (more than a second).
    I read Postgres 7.4 documentation and it says that Postgres don't use indexes for aggregates functions because users can create there own aggregates.

    It says that to have best results it is recommended to replace a request like :
    Code:
    SELECT min(col) FROM sometable;
    with :
    Code:
    SELECT col FROM sometable ORDER BY col ASC LIMIT 1;
    I don't know if it's the same for latest 8.3 version, documentation is not as precise on this point.


    Thanks for your lights.
Working...