Re: design question: status table+log table, indexes, triggers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: gry(at)ll(dot)mit(dot)edu
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: design question: status table+log table, indexes, triggers
Date: 2003-02-05 19:07:01
Message-ID: 28577.1044472021@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

george young <gry(at)ll(dot)mit(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Neal Lindsay 2003-02-05 19:33:29 Re: automatic time/user stamp - rule or trigger?
Previous Message Jan Wieck 2003-02-05 19:01:43 Re: automatic time/user stamp - rule or trigger?