Re: [PERFORM] seqscan instead of index scan

2004-09-01 Thread Merlin Moncure
> On Mon, 30 Aug 2004, Martin Sarsale wrote: > > "Multicolumn indexes can only be used if the clauses involving the > > indexed columns are joined with AND. For instance, > > > > SELECT name FROM test2 WHERE major = constant OR minor = constant; > > You can use DeMorgan's Theorem to transform an O

Re: [PERFORM] seqscan instead of index scan

2004-09-01 Thread Chester Kustarz
On Mon, 30 Aug 2004, Martin Sarsale wrote: > "Multicolumn indexes can only be used if the clauses involving the > indexed columns are joined with AND. For instance, > > SELECT name FROM test2 WHERE major = constant OR minor = constant; You can use DeMorgan's Theorem to transform an OR clause to an

Re: [PERFORM] seqscan instead of index scan

2004-08-31 Thread Martin Sarsale
> Using a functional index you can define an index around the way you > access the data. There is no faster or better way to do it...this is a > mathematical truth, not a problem with the planner. Why not use the > right tool for the job? A boolean index is super-efficient both in disk > space

Re: [PERFORM] seqscan instead of index scan

2004-08-30 Thread Tom Lane
Martin Sarsale <[EMAIL PROTECTED]> writes: > I indexed columns c and d (separately) but this query used the slow > seqscan instead of the index scan: > select * from t where c<>0 or d<>0; > After playing some time, I noticed that if I change the "or" for an > "and", pg used the fast index scan (b

Re: [PERFORM] seqscan instead of index scan

2004-08-30 Thread Greg Stark
Another option here is to use a partial index. You can index on some other column -- perhaps the column you want the results ordered by where the where clause is true. Something like: create index t_idx on t (name) where c>0 and d>0; then any select with a matching where clause can use the inde

Re: [PERFORM] seqscan instead of index scan

2004-08-30 Thread Stephan Szabo
On Mon, 30 Aug 2004, Martin Sarsale wrote: > On Mon, 2004-08-30 at 15:06, Merlin Moncure wrote: > > create function is_somethingable (ctype, dtype) returns boolean as > > Thanks, but I would prefer a simpler solution. > > I would like to know why this uses a seqscan instead of an index scan: > > c

Re: [PERFORM] seqscan instead of index scan

2004-08-30 Thread Pierre-Frédéric Caillaud
create index t_idx on t((c+d)); select * from t where c+d > 0; Why not : select ((select * from t where c<>0::bigint) UNION (select * from t where d<>0::bigint)) group by whatever; or someting ? ---(end of broadcast)--- TIP 3: if pos