Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Tom Lane
"Tomas Vondra" writes: > Could the planner do this reasoning, i.e. see if there's a NOT NULL > constraint on the column and change the plan accordingly? Possibly. I'm not sure how expensive it would be. Right now, a structural change of that sort would have to be done pretty early in planning,

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Tomas Vondra
On 15 Září 2011, 16:26, Tom Lane wrote: > Yang Zhang writes: >> On Thu, Sep 15, 2011 at 1:22 AM, Tomas Vondra wrote: >>> [ use a left join instead of NOT IN ] > >> This worked great, thank you. Too bad the planner isn't smart enough >> to do this yet! > > It never will be, because they're not eq

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Tom Lane
Yang Zhang writes: > On Thu, Sep 15, 2011 at 1:22 AM, Tomas Vondra wrote: >> [ use a left join instead of NOT IN ] > This worked great, thank you. Too bad the planner isn't smart enough > to do this yet! It never will be, because they're not equivalent queries. NOT IN has different (and very

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Tomas Vondra
On 15 Září 2011, 11:07, Yang Zhang wrote: > On Thu, Sep 15, 2011 at 1:22 AM, Tomas Vondra wrote: >> On 15 Září 2011, 9:53, Yang Zhang wrote: >>> I have a simple query that's been running for a while, which is fine, >>> but it seems to be running very slowly, which is a problem: >>> >>> mydb=# expl

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Yang Zhang
On Thu, Sep 15, 2011 at 1:22 AM, Tomas Vondra wrote: > On 15 Září 2011, 9:53, Yang Zhang wrote: >> I have a simple query that's been running for a while, which is fine, >> but it seems to be running very slowly, which is a problem: >> >> mydb=# explain select user_id from den where user_id not in

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Toby Corkindale
On 15/09/11 17:53, Yang Zhang wrote: I have a simple query that's been running for a while, which is fine, but it seems to be running very slowly, which is a problem: mydb=# explain select user_id from den where user_id not in (select duid from user_mappings) and timestamp between '2009-04-01' a

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Tomas Vondra
On 15 Září 2011, 9:53, Yang Zhang wrote: > I have a simple query that's been running for a while, which is fine, > but it seems to be running very slowly, which is a problem: > > mydb=# explain select user_id from den where user_id not in (select > duid from user_mappings) and timestamp between '20

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread John R Pierce
On 09/15/11 12:53 AM, Yang Zhang wrote: mydb=# explain select user_id from den where user_id not in (select duid from user_mappings) and timestamp between '2009-04-01' and '2010-04-01'; QUERY PLAN ---

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Yang Zhang
Should also add that while the client is under no load (CPU<1%, load ~0.1, mem ~20%), the server looks pretty busy (CPU 90-100% of 1 core, load ~1.5, mem ~70-80%), but PG is the only thing using resources. On Thu, Sep 15, 2011 at 12:58 AM, Yang Zhang wrote: > If it matters, the client is a JDBC a

Re: [GENERAL] Why is this query running slowly?

2011-09-15 Thread Yang Zhang
If it matters, the client is a JDBC app doing: con = DriverManager.getConnection("jdbc:postgresql://localhost:5434/mydb", "yang", password) con.setAutoCommit(false) val st = con.prepareStatement(""" select user_id from den where user_id not in (select duid from user_mappings)

[GENERAL] Why is this query running slowly?

2011-09-15 Thread Yang Zhang
I have a simple query that's been running for a while, which is fine, but it seems to be running very slowly, which is a problem: mydb=# explain select user_id from den where user_id not in (select duid from user_mappings) and timestamp between '2009-04-01' and '2010-04-01'; QUERY PLAN