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 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 this: > > explain a

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Tom Lane
Andreas writes: > Tom Lane schrieb: >> Well, it is that --- it just doesn't provide access to all the features >> that CREATE INDEX does. >> > So as it is a shortcut for "create index" then why would the function > call of upper not be accepted when the sql parser maps the > uniqe-constraint in

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Andreas
Tom Lane schrieb: Andreas writes: So I had the missconception that UNIQUE (...) within CREATE TABLE (...) was actually just an shorter way to define a unique index which it is not. Well, it is that --- it just doesn't provide access to all the features that CREATE INDEX does. So as

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 Tom Lane
Dave Clements 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 completely off. The

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 wrote: > On Sun, Jan 31, 2010 at 6:09 PM, Dave Clements wrote: >> I did the re-analyze serveral times, using the command: >> >> ANALYZE tablename; >> >> Is there any other command as wel

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 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 you're not getting eno

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 wrote: > On Sun, Jan 31, 2010 at 6:02 PM, Dave Clements wrote: >> Hi, following the output from explain ana

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 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 (pgsql-sql@postgresql.

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 5:50 PM, Dave Clements 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 change the > query

[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 se

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Tom Lane
Andreas writes: > So I had the missconception that UNIQUE (...) within CREATE TABLE (...) > was actually just an shorter way to define a unique index which it is not. Well, it is that --- it just doesn't provide access to all the features that CREATE INDEX does. regards,

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread Andreas
Joshua Tolley schrieb: On Sun, Jan 31, 2010 at 03:26:14AM +0100, Andreas wrote: Hi, is there a way to define a unique restraint on UPPER (textfield)? E.g. mytable ( name_id serial PRIMARY KEY, name varchar(255), UNIQUE ( upper (name) ) ) psql throws a syntax error because of the

Re: [SQL] Howto have a unique restraint on UPPER (textfield)

2010-01-31 Thread msi77
Hi, I think you need CS collation and UNIQUE(name). > Hi, > is there a way to define a unique restraint on UPPER (textfield)? > E.g. > mytable ( > name_id serial PRIMARY KEY, > name varchar(255), > UNIQUE ( upper (name) ) > ) > psql throws a syntax error because of the upper() function.