Re: Query only slow on first run

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: cluster
> 
> If I disable the nested loops, the query becomes *much* slower.
> 
> A thing that strikes me is the following. As you can see I have the
> constraint: q.status = 1. Only a small subset of the data set 
> has this status. I have an index on q.status but for some 
> reason this is not used. Instead the constraint are ensured 
> with a "Filter: (q.status = 1)" 
> in an index scan for the primary key in the "q" table. If the 
> small subset having q.status = 1 could be isolated quickly 
> using an index, I would expect the query to perform better. I 
> just don't know why the planner doesn't use the index on q.status.
> 

What version of Postgres are you using?  Do you know what your
join_collapse_limit is set to?

You might be able to force it to scan for questions with a status of 1 first
to see if it helps by changing the FROM clause to: 

FROM posts p, question_tags qt, (SELECT * FROM questions WHERE status = 1
OFFSET 0) q

Dave



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux