Re: design question: status table+log table, indexes, triggers - Mailing list pgsql-sql

From Tom Lane
Subject Re: design question: status table+log table, indexes, triggers
Date
Msg-id 28577.1044472021@sss.pgh.pa.us
Whole thread Raw
In response to design question: status table+log table, indexes, triggers  (george young <gry@ll.mit.edu>)
List pgsql-sql
george young <gry@ll.mit.edu> writes:
> This schema seemed logical at the outset, but the most common query is:

> select m.machine_name, m.text, ml.status, ml.date 
>    from machine m, machine_log ml 
>    where m.machine_name=ml.machine_name and ml.date=(select max(date)from
> machine_log where machine_name=ml.machine_name);

You can do this a lot better with SELECT DISTINCT ON --- see the "weather
report" example in the SELECT reference page.  Given a suitable index
it should even be pretty quick.
        regards, tom lane


pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: Re: automatic time/user stamp - rule or trigger?
Next
From: Neal Lindsay
Date:
Subject: Re: automatic time/user stamp - rule or trigger?