[SQL] Fwd: Help required on query performance

2010-01-31 Thread Dave Clements
Hello, I have this query in my system which takes around 2.5 seconds to run. I have diagnosed that the problem is actually a hashjoin on perm and s_ast_role tables. Is there a way I can avoid that join? I just want to change the query and no environment change. SELECT  ai.aid,  SUM(ai.score) as

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Scott Marlowe
On Sun, Jan 31, 2010 at 5:50 PM, Dave Clements dclement...@gmail.com wrote: Hello, I have this query in my system which takes around 2.5 seconds to run. I have diagnosed that the problem is actually a hashjoin on perm and s_ast_role tables. Is there a way I can avoid that join? I just want to

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Dave Clements
Hi, following the output from explain analyze.

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Scott Marlowe
On Sun, Jan 31, 2010 at 6:02 PM, Dave Clements dclement...@gmail.com wrote: Hi, following the output from explain analyze. Without doing any heavy analysis, it looks like your row estimates are way off. Have you cranked up stats target and re-analyzed yet? -- Sent via pgsql-sql mailing list

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Dave Clements
I did the re-analyze serveral times, using the command: ANALYZE tablename; Is there any other command as well or another way to do that? On Mon, Feb 1, 2010 at 12:04 PM, Scott Marlowe scott.marl...@gmail.com wrote: On Sun, Jan 31, 2010 at 6:02 PM, Dave Clements dclement...@gmail.com wrote:

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Scott Marlowe
On Sun, Jan 31, 2010 at 6:09 PM, Dave Clements dclement...@gmail.com wrote: I did the re-analyze serveral times, using the command: ANALYZE tablename; Is there any other command as well or another way to do that? It's important that the stats target get increased as well, it looks like

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Dave Clements
After doing an analyze on the database, it improved a lot :) On Mon, Feb 1, 2010 at 12:13 PM, Scott Marlowe scott.marl...@gmail.com wrote: On Sun, Jan 31, 2010 at 6:09 PM, Dave Clements dclement...@gmail.com wrote: I did the re-analyze serveral times, using the command: ANALYZE tablename;

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Tom Lane
Dave Clements dclement...@gmail.com writes: Hello, I have this query in my system which takes around 2.5 seconds to run. I have diagnosed that the problem is actually a hashjoin on perm and s_ast_role tables. Is there a way I can avoid that join? BTW, just for the record, that diagnosis was

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Dave Clements
After the analyze I am getting the time 3.20 ms but there is not HashJoin there. Still all of them are NestLoops. But that is fine. Now the only problem is the sequence scan on sq_sch_idx table. I have a query like this: explain analyze select count(*) from sq_sch_idx where value = '%download%';

Re: [SQL] Fwd: Help required on query performance

2010-01-31 Thread Scott Marlowe
On Sun, Jan 31, 2010 at 9:25 PM, Dave Clements dclement...@gmail.com wrote: After the analyze I am getting the time 3.20 ms but there is not HashJoin there. Still all of them are NestLoops. But that is fine. Now the only problem is the sequence scan on sq_sch_idx table. I have a query like