Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CFF4F632FB3 for ; Thu, 18 Mar 2010 12:06:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 22882-03 for ; Thu, 18 Mar 2010 15:05:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ww0-f46.google.com (mail-ww0-f46.google.com [74.125.82.46]) by mail.postgresql.org (Postfix) with ESMTP id EBE086328D9 for ; Thu, 18 Mar 2010 12:05:57 -0300 (ADT) Received: by wwe15 with SMTP id 15so1159583wwe.19 for ; Thu, 18 Mar 2010 08:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type; bh=pMOlqk1A7kcWxL2Sl7alJ7it8XeZNVs4kNq7f4C1QBw=; b=rvzZtorneMoval/kaiQ9RNDnm/iKenA/RJIHOrfxCESlOknbR9f3qzxWMVQVMCs8PG dt7val5QoIll+5TKvQ82B7m7m7kPN+cEVHdCQqX1GnUuCxsMUhhVqOXiB0nQvaP9+MkU nlwr/CGeDbfSBgWVpbOUi/YfMLasBp8AGjiYY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=Yt65CxT5UMx6ZhAa5sDHOstf/eUC6pHjFQX1EDAWkmwbLKLvK9XyGkMXRNTH32AMNK X47Fjt/+Pyj4nSE+dSG0fzMj+6qPypcmWSgyytNB0s3DwR1xas1VuH3zUMI/ausdXwDl xBq5pdYOwWGv9Srm/3GXy9JR23LRM0obtq0Aw= MIME-Version: 1.0 Received: by 10.216.90.142 with SMTP id e14mr1530639wef.85.1268924756514; Thu, 18 Mar 2010 08:05:56 -0700 (PDT) In-Reply-To: <4BA23936.2030507@gmail.com> References: <4BA23936.2030507@gmail.com> From: Thom Brown Date: Thu, 18 Mar 2010 15:05:36 +0000 Message-ID: Subject: Re: mysql to postgresql, performance questions To: Corin Cc: pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=0016e6daaff95bf4a404821491bd X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201003/224 X-Sequence-Number: 38049 --0016e6daaff95bf4a404821491bd Content-Type: text/plain; charset=ISO-8859-1 On 18 March 2010 14:31, Corin wrote: > Hi all, > > I'm running quite a large social community website (250k users, 16gb > database). We are currently preparing a complete relaunch and thinking about > switching from mysql 5.1.37 innodb to postgresql 8.4.2. The database server > is a dual dualcore operton 2216 with 12gb ram running on debian amd64. > > For a first impression I ran a simple query on our users table (snapshot > with only ~ 45.000 records). The table has an index on birthday_age > [integer]. The test executes 10 times the same query and simply discards the > results. I ran the tests using a php and a ruby script, the results are > almost the same. > > Unluckily mysql seems to be around 3x as fast as postgresql for this simple > query. There's no swapping, disc reading involved...everything is in ram. > > query > select * from users where birthday_age between 12 and 13 or birthday_age > between 20 and 22 limit 1000 > > mysql > {"select_type"=>"SIMPLE", "key_len"=>"1", "id"=>"1", "table"=>"users", > "type"=>"range", "possible_keys"=>"birthday_age", "rows"=>"7572", > "Extra"=>"Using where", "ref"=>nil, "key"=>"birthday_age"} > 15.104055404663 > 14.209032058716 > 18.857002258301 > 15.714883804321 > 14.73593711853 > 15.048027038574 > 14.589071273804 > 14.847040176392 > 15.192985534668 > 15.115976333618 > > postgresql > {"QUERY PLAN"=>"Limit (cost=125.97..899.11 rows=1000 width=448) (actual > time=0.927..4.990 rows=1000 loops=1)"} > {"QUERY PLAN"=>" -> Bitmap Heap Scan on users (cost=125.97..3118.00 > rows=3870 width=448) (actual time=0.925..3.420 rows=1000 loops=1)"} > {"QUERY PLAN"=>" Recheck Cond: (((birthday_age >= 12) AND (birthday_age <= > 13)) OR ((birthday_age >= 20) AND (birthday_age <= 22)))"} > {"QUERY PLAN"=>" -> BitmapOr (cost=125.97..125.97 rows=3952 width=0) > (actual time=0.634..0.634 rows=0 loops=1)"} > {"QUERY PLAN"=>" -> Bitmap Index Scan on birthday_age (cost=0.00..41.67 > rows=1341 width=0) (actual time=0.260..0.260 rows=1327 loops=1)"} > {"QUERY PLAN"=>" Index Cond: ((birthday_age >= 12) AND (birthday_age <= > 13))"} > {"QUERY PLAN"=>" -> Bitmap Index Scan on birthday_age (cost=0.00..82.37 > rows=2611 width=0) (actual time=0.370..0.370 rows=2628 loops=1)"} > {"QUERY PLAN"=>" Index Cond: ((birthday_age >= 20) AND (birthday_age <= > 22))"} > {"QUERY PLAN"=>"Total runtime: 5.847 ms"} > 44.173002243042 > 41.156768798828 > 39.988040924072 > 40.470123291016 > 40.035963058472 > 40.077924728394 > 40.94386100769 > 40.183067321777 > 39.83211517334 > 40.256977081299 > > I also wonder why the reported runtime of 5.847 ms is so much different to > the runtime reported of my scripts (both php and ruby are almost the same). > What's the best tool to time queries in postgresql? Can this be done from > pgadmin? > > pgAdmin will return the query time in the status bar of a query window. Similarly, you can use psql and activate query times by using "\timing". Regards Thom --0016e6daaff95bf4a404821491bd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 18 March 2010 14:31, Corin = <wakathane@gmail.com> wrote:
Hi all,

I'm running quite a large social community website (250k users, 16gb da= tabase). We are currently preparing a complete relaunch and thinking about = switching from mysql 5.1.37 innodb to postgresql 8.4.2. The database server= is a dual dualcore operton 2216 with 12gb ram running on debian amd64.

For a first impression I ran a simple query on our users table (snapshot wi= th only ~ 45.000 records). The table has an index on birthday_age [integer]= . The test executes 10 times the same query and simply discards the results= . I ran the tests using a php and a ruby script, the results are almost the= same.

Unluckily mysql seems to be around 3x as fast as postgresql for this simple= query. There's no swapping, disc reading involved...everything is in r= am.

query
select * from users where birthday_age between 12 and 13 or birthday_age be= tween 20 and 22 limit 1000

mysql
{"select_type"=3D>"SIMPLE", "key_len"=3D&g= t;"1", "id"=3D>"1", "table"=3D&g= t;"users", "type"=3D>"range", "possib= le_keys"=3D>"birthday_age", "rows"=3D>"= 7572", "Extra"=3D>"Using where", "ref"= ;=3D>nil, "key"=3D>"birthday_age"}
15.104055404663
14.209032058716
18.857002258301
15.714883804321
14.73593711853
15.048027038574
14.589071273804
14.847040176392
15.192985534668
15.115976333618

postgresql
{"QUERY PLAN"=3D>"Limit (cost=3D125.97..899.11 rows=3D100= 0 width=3D448) (actual time=3D0.927..4.990 rows=3D1000 loops=3D1)"} {"QUERY PLAN"=3D>" -> Bitmap Heap Scan on users (cost= =3D125.97..3118.00 rows=3D3870 width=3D448) (actual time=3D0.925..3.420 row= s=3D1000 loops=3D1)"}
{"QUERY PLAN"=3D>" Recheck Cond: (((birthday_age >=3D = 12) AND (birthday_age <=3D 13)) OR ((birthday_age >=3D 20) AND (birth= day_age <=3D 22)))"}
{"QUERY PLAN"=3D>" -> BitmapOr (cost=3D125.97..125.97 = rows=3D3952 width=3D0) (actual time=3D0.634..0.634 rows=3D0 loops=3D1)"= ;}
{"QUERY PLAN"=3D>" -> Bitmap Index Scan on birthday_ag= e (cost=3D0.00..41.67 rows=3D1341 width=3D0) (actual time=3D0.260..0.260 ro= ws=3D1327 loops=3D1)"}
{"QUERY PLAN"=3D>" Index Cond: ((birthday_age >=3D 12)= AND (birthday_age <=3D 13))"}
{"QUERY PLAN"=3D>" -> Bitmap Index Scan on birthday_ag= e (cost=3D0.00..82.37 rows=3D2611 width=3D0) (actual time=3D0.370..0.370 ro= ws=3D2628 loops=3D1)"}
{"QUERY PLAN"=3D>" Index Cond: ((birthday_age >=3D 20)= AND (birthday_age <=3D 22))"}
{"QUERY PLAN"=3D>"Total runtime: 5.847 ms"}
44.173002243042
41.156768798828
39.988040924072
40.470123291016
40.035963058472
40.077924728394
40.94386100769
40.183067321777
39.83211517334
40.256977081299

I also wonder why the reported runtime of 5.847 ms is so much different to = the runtime reported of my scripts (both php and ruby are almost the same).= What's the best tool to time queries in postgresql? Can this be done f= rom pgadmin?


pgAdmin will return the query time in the status= bar of a query window.=A0 Similarly, you can use psql and activate query t= imes by using "\timing".

Regards

Thom
--0016e6daaff95bf4a404821491bd--