Re: [PERFORM] Subquery WHERE IN or WHERE EXISTS faster?

2008-06-28 Thread Gregory Stark
"Ulrich" <[EMAIL PROTECTED]> writes: > EXPLAIN ANALYZE SELECT speed FROM processors WHERE id IN (SELECT processorid > FROM users_processors WHERE userid=4040) ORDER BY speed ASC LIMIT 10 OFFSET 1; > > Limit (cost=113.73..113.75 rows=7 width=5) (actual time=0.335..0.340 rows=10 > loops=1) > ->

Re: [PERFORM] Subquery WHERE IN or WHERE EXISTS faster?

2008-06-28 Thread Ulrich
Hi, I have added a bit of dummy Data, 10 processors, 1 users, each user got around 12 processors. I have tested both queries. First of all, I was surprised that it is that fast :) Here are the results: EXPLAIN ANALYZE SELECT speed FROM processors WHERE id IN (SELECT processorid FRO

Re: [PERFORM] Planner should use index on a LIKE 'foo%' query

2008-06-28 Thread Steinar H. Gunderson
On Sat, Jun 28, 2008 at 06:24:42PM +0200, Moritz Onken wrote: > SELECT distinct url from item where url like 'http://www.micro%' limit > 10; Here, the planner knows the pattern beforehand, and can see that it's a simple prefix. > select * > from result > where exists >(select * from item w

[PERFORM] Planner should use index on a LIKE 'foo%' query

2008-06-28 Thread Moritz Onken
Hi, I have a query select count(*) from result where exists (select * from item where item.url LIKE result.url || '%' limit 1); which basically returns the number of items which exist in table result and match a URL in table item by its prefix. I read all about idexes (http://www.postgre

Re: [PERFORM] Subquery WHERE IN or WHERE EXISTS faster?

2008-06-28 Thread Tom Lane
Ulrich <[EMAIL PROTECTED]> writes: > People say that [EXISTS is faster] People who say that are not reliable authorities, at least as far as Postgres is concerned. But it is always a bad idea to extrapolate results on toy tables to large tables --- quite aside from measurement noise and caching i

[PERFORM] Subquery WHERE IN or WHERE EXISTS faster?

2008-06-28 Thread Ulrich
Hi, I am new to SQL and have two tables..., "processor" and "users_processors". The first table contains Processors: CREATE TABLE processor ( id SERIAL, speed varchar(50) NOT NULL, type int2 NOT NULL, PRIMARY KEY (id) ); CREATE UNIQUE INDEX processor_speed_index ON processors(lower(speed)); E