Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Performance > mysterious diff...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 4014 of 4156
Post > Topic >>

mysterious difference in speed when combining two queries with OR

by hans.ekbrand@[EMAIL PROTECTED] (Hans Ekbrand) Apr 23, 2008 at 09:23 AM

--k+G3HLlWI7eRTl+h
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I cannot understand why the following two queries differ so much in
executi=
on time (almost ten times)

Query A (two queries)

select distinct moment.mid from moment,timecard where parent =3D 45 and
(pi=
d=3D17 and timecard.mid =3D moment.mid) order by moment.mid;
select distinct moment.mid from moment,timecard where parent =3D 45 and
(pb=
ar =3D 0) order by moment.mid;

Query B (combining the two with OR)

select distinct moment.mid from moment,timecard where parent =3D 45 and
((p=
id=3D17 and timecard.mid =3D moment.mid) or (pbar =3D 0)) order by
moment.m=
id;

$ time psql -o /dev/null -f query-a.sql fektest

real    0m2.016s
user    0m1.532s
sys     0m0.140s

$ time psql -o /dev/null -f query-b.sql fektest

real    0m28.534s
user    0m1.516s
sys     0m0.156s

I have tested this in two different computers with different amount of
RAM, fast or slow CPU, and the difference is persistent, almost ten
times.

I should say that this is on postgresql 7.4.16 (debian stable).

Can query B be rewritten so that it would execute faster?

TIA

--=20
Hans Ekbrand (http://sociologi.cjb.net)
<hans@[EMAIL PROTECTED]
>
GPG Fingerprint: 1408 C8D5 1E7D 4C9C C27E 014F 7C2C 872A 7050 614E

--k+G3HLlWI7eRTl+h
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIDuPWfCyHKnBQYU4RAiEoAJsEfl1x+GwH4V7MN4rfinOqJDoHLwCg5ALL
04PQ1ci0mAeM1/OS14tfIqQ=
=b/ug
-----END PGP SIGNATURE-----

--k+G3HLlWI7eRTl+h--
 




 8 Posts in Topic:
mysterious difference in speed when combining two queries with O
hans.ekbrand@[EMAIL PROTE  2008-04-23 09:23:07 
Re: mysterious difference in speed when combining two queries wi
andreas.kretschmer@[EMAIL  2008-04-23 09:58:10 
Re: mysterious difference in speed when combining two queries wi
andreas.kretschmer@[EMAIL  2008-04-23 10:57:04 
Re: mysterious difference in speed when combining two queries wi
hans.ekbrand@[EMAIL PROTE  2008-04-23 11:22:09 
Re: mysterious difference in speed when combining two
hans.ekbrand@[EMAIL PROTE  2008-04-23 11:06:08 
Re: mysterious difference in speed when combining two queries wi
theo@[EMAIL PROTECTED] (  2008-04-23 13:00:07 
Re: mysterious difference in speed when combining two queries wi
lists@[EMAIL PROTECTED]   2008-04-23 14:56:56 
Re: mysterious difference in speed when combining two queries wi
stark@[EMAIL PROTECTED]   2008-04-23 09:31:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Sun Jul 6 19:59:30 CDT 2008.