Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Posible planner improvement?



A Dimecres 21 Maig 2008, Richard Huxton va escriure:
Albert Cervera Areny wrote:
I've got a query similar to this:

select * from t1, t2 where t1.id > 158507 and t1.id = t2.id;

That took > 84 minutes (the query was a bit longer but this is the part
that made the difference) after a little change the query took ~1 second:

select * from t1, t2 where t1.id > 158507 and t2.id > 158507 and t1.id =
t2.id;
Try posting EXPLAIN ANALYSE SELECT ... for both of those queries and
we'll see why it's better at the second one.

Even if the estimates were off (they look a bit off for the first table), the above two queries are logically identical, and I would expect the planner to make the same decision for both.

I am curious - what is the result of:

   select * from t1, t2 where t2.id > 158507 and t1.id = t2.id;

Is it the same speed as the first or second, or is a third speed entirely?

If t1.id = t2.id, I would expect the planner to substitute them freely in terms of identities?

Cheers,
mark

--
Mark Mielke <mark(at)mielke(dot)cc>




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group