Re: [GENERAL] Index usage on OR queries

2011-08-31 Thread Tomas Vondra
On 31 Srpen 2011, 16:49, Andy Colson wrote: > On 8/31/2011 9:35 AM, Tore Halvorsen wrote: >> Hi, >> >> I'm trying to optimize a query where I have two tables that both have a >> timestamp column. I want the result where either of the timestamps is >> after a specified time. In a reduced form, like

Re: [GENERAL] Index usage on OR queries

2011-08-31 Thread Andy Colson
On 8/31/2011 9:53 AM, Tore Halvorsen wrote: On Wed, Aug 31, 2011 at 4:49 PM, Andy Colson mailto:a...@squeakycode.net>> wrote: On PG 9, after I ANALYZED the tables, it used indexes: QUERY PLAN --__--__-

Re: [GENERAL] Index usage on OR queries

2011-08-31 Thread Tore Halvorsen
On Wed, Aug 31, 2011 at 4:49 PM, Andy Colson wrote: > On PG 9, after I ANALYZED the tables, it used indexes: > > > QUERY PLAN > --**--** > --**- > Merge Join (cost=1.59..82778.35 rows=13171 w

Re: [GENERAL] Index usage on OR queries

2011-08-31 Thread Andy Colson
On 8/31/2011 9:35 AM, Tore Halvorsen wrote: Hi, I'm trying to optimize a query where I have two tables that both have a timestamp column. I want the result where either of the timestamps is after a specified time. In a reduced form, like this: CREATE TABLE a ( id serial NOT NULL PRIMARY KEY

Re: [GENERAL] Index usage on OR queries

2011-08-31 Thread Tore Halvorsen
> > -- This can be optimized by using CTEs > with am as ( > select * from a where time >= '2011-08-15' > ) > , bm as ( > select * from b where time >= '2011-08-15' > ) > select * from am join bm using(id) > Disregard this, it doesn't to the same at all. Now I'm more confused as to how I can o