Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Cultural Sublimation
Hi, > If you have no index on comments.comment_author, then a seqscan will be > required for your join between comments and users. Similarly, if you > have no index on comments.comment_story, then any query against comments > that uses that column as part of a predicate will require a seqscan o

Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Rodrigo De León
On Jul 30, 12:01 pm, [EMAIL PROTECTED] (Cultural Sublimation) wrote: > Hash Join (cost=28.50..21889.09 rows=988 width=14) (actual > time=3.674..1144.779 rows=1000 loops=1) >Hash Cond: ((comments.comment_author)::integer = (users.user_id)::integer) >-> Seq Scan on comments (cost=0.00..218

Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Jon Sime
Cultural Sublimation wrote: SELECT comments.comment_id, users.user_name FROM comments, users WHERE comments.comment_story = 100 AND comments.comment_author = users.user_id; The problem is that this query takes a *very* long time. With the said 1,000,000 comments, it needs at least 1100ms on my

Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Nis Jørgensen
Cultural Sublimation skrev: > Hi, > > I'm fairly new with Postgresql, so I am not sure if the performance > problems I'm having are due to poorly constructed queries/indices, > or if I bumped into more fundamental problems requiring a design of > my database structure. That's why I'm requesting y

Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Richard Huxton
Cultural Sublimation wrote: CREATE TABLE users ( user_id int UNIQUE NOT NULL, user_name text, PRIMARY KEY (user_id) ); CREATE TABLE stories ( story_idint UNIQUE NOT NULL, story_title

Re: [GENERAL] Optimising SELECT on a table with one million rows

2007-07-30 Thread Bryan Murphy
First question... did you create the appropriate indexes on the appropriate columns for these tables? Foreign keys do not implicitly create indexes in postgres. Bryan On 7/30/07, Cultural Sublimation <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm fairly new with Postgresql, so I am not sure if the p