[PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread Hans Ekbrand
I cannot understand why the following two queries differ so much in execution time (almost ten times) Query A (two queries) select distinct moment.mid from moment,timecard where parent = 45 and (pid=17 and timecard.mid = moment.mid) order by moment.mid; select distinct moment.mid from

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread A. Kretschmer
am Wed, dem 23.04.2008, um 9:23:07 +0200 mailte Hans Ekbrand folgendes: I cannot understand why the following two queries differ so much in execution time (almost ten times) wild guess: different execution plans. Can you show us the plans? (EXPLAIN ANALYSE SELECT ...) Query A (two

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread A. Kretschmer
am Wed, dem 23.04.2008, um 9:58:10 +0200 mailte A. Kretschmer folgendes: Query A (two queries) select distinct moment.mid from moment,timecard where parent = 45 and (pid=17 and timecard.mid = moment.mid) order by moment.mid; select distinct moment.mid from moment,timecard where

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread hans
On Wed, Apr 23, 2008 at 09:58:10AM +0200, A. Kretschmer wrote: am Wed, dem 23.04.2008, um 9:23:07 +0200 mailte Hans Ekbrand folgendes: I cannot understand why the following two queries differ so much in execution time (almost ten times) wild guess: different execution plans. Can

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread Hans Ekbrand
On Wed, Apr 23, 2008 at 10:57:04AM +0200, A. Kretschmer wrote: am Wed, dem 23.04.2008, um 9:58:10 +0200 mailte A. Kretschmer folgendes: Query A (two queries) select distinct moment.mid from moment,timecard where parent = 45 and (pid=17 and timecard.mid = moment.mid) order by

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread Theo Kramer
On 23 Apr 2008, at 9:23AM, Hans Ekbrand wrote: I cannot understand why the following two queries differ so much in execution time (almost ten times) Query A (two queries) select distinct moment.mid from moment,timecard where parent = 45 and (pid=17 and timecard.mid = moment.mid) order by

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread PFC
I should say that this is on postgresql 7.4.16 (debian stable). Whoa. I cannot understand why the following two queries differ so much in execution time (almost ten times) Post EXPLAIN ANALYZE for both, and also post table definitions (with indexes), use \d table. This will

Re: [PERFORM] mysterious difference in speed when combining two queries with OR

2008-04-23 Thread Gregory Stark
Hans Ekbrand [EMAIL PROTECTED] writes: No, I just wanted to show the time differences, I haven't used join before. Now that you have adviced me to, I have tried your suggestion to rewrite B as a union and it works good! Just as fast as the A Query! You can even do better. If you know the two