Re: Why is query selecting sequential? - Mailing list pgsql-performance

From Josh Berkus
Subject Re: Why is query selecting sequential?
Date
Msg-id 200402061436.57903.josh@agliodbs.com
Whole thread Raw
In response to Re: Why is query selecting sequential?  (Karl Denninger <karl@denninger.net>)
Responses Re: Why is query selecting sequential?  (Karl Denninger <karl@denninger.net>)
List pgsql-performance
Karl,

Well, still with only 5 rows in the forumlog table you're not going get
realistic results compared to a loaded database.  However, you are making
things difficult for the parser with awkward query syntax; what you currently
have encourages a sequential loop.

If there are potentially several rows in forumlog for each row in post, then
your query won't work either.

> akcs=> explain analyze select forum, (replied > (select lastview from
forumlog where forumlog.login='genesis' and forumlog.forum='General' and
number=post.number)) as newflag, * from post where forum = 'General' and
toppost = 1 order by pinned desc, replied desc;

Instead:

if only one row in forumlog per row in post:

SELECT (replied > lastview) AS newflag, post.*
FROM post, forumlog
WHERE post.forum = 'General' and toppost = 1 and forumlog.login = 'genesis'
and forumlog.forum='General' and forumlog.number=post.number;

--
-Josh Berkus
 Aglio Database Solutions
 San Francisco


pgsql-performance by date:

Previous
From: Karl Denninger
Date:
Subject: Re: Why is query selecting sequential?
Next
From: Orion Henry
Date:
Subject: Re: 7.3 vs 7.4 performance