| From: | Lee Harr <missive(at)frontiernet(dot)net> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: using LIMIT only on primary table |
| Date: | 2002-07-28 18:13:39 |
| Message-ID: | ai1c8j$1htm$1@news.hub.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
In article <3D42D7AA(dot)27447(dot)3EE190A0(at)localhost>, "Dan Langille" wrote:
> This is an extension of the problem solved by
> http://archives.postgresql.org/pgsql-sql/2002-03/msg00020.php but
> with a slightly different complication.
>
> I want to get the last 100 port commits from the database. Commits
> are stored in
> commit_log and commit_log_ports relates commits to ports. A given
> commit may
> affect more than one port (i.e. there is a 1-N relationship between
> commit_log and
> commit_log_ports).
>
> So a starting point for the last 100 port commits is:
>
> explain analyze
> SELECT distinct commit_log.*
> FROM commit_log_ports, commit_log
> WHERE commit_log.id = commit_log_ports.commit_log_id
> ORDER BY commit_log.commit_date DESC, commit_log_ports.commit_log_id
> LIMIT 100;
>
I am not sure if this will help, but how about a subselect?
SELECT DISTINCT commit_log.*
FROM commit_log_ports,
(SELECT commit_log.id
FROM commit_log
ORDER BY commit_log.commit_date DESC
LIMIT 100) AS commit_log
WHERE commit_log.id = commit_log_ports.commit_log_id
ORDER BY commit_log.commit_date DESC, commit_log.id
LIMIT 100;
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Josh Berkus | 2002-07-28 23:53:07 | Abbr. for TIMESTAMP WITHOUT TIME ZONE? |
| Previous Message | Tom Lane | 2002-07-28 17:02:49 | Re: performance difference in count(1) vs. count(*)? |