X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7C6885287D for ; Mon, 11 Jul 2005 20:42:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74943-05 for ; Mon, 11 Jul 2005 23:42:13 +0000 (GMT) Received: from sccmmhc92.asp.att.net (sccmmhc92.asp.att.net [204.127.203.212]) by svr1.postgresql.org (Postfix) with ESMTP id 57D0952998 for ; Mon, 11 Jul 2005 20:42:12 -0300 (ADT) Received: from juju.arbash-meinel.com ([12.214.18.81]) by sccmmhc92.asp.att.net (sccmmhc92) with ESMTP id <20050711234215m920060tite>; Mon, 11 Jul 2005 23:42:15 +0000 Received: by juju.arbash-meinel.com (Postfix, from userid 505) id CB24C55FEC; Mon, 11 Jul 2005 18:42:14 -0500 (CDT) Received: from [192.168.1.102] (209-181-211-15.cdrr.qwest.net [209.181.211.15]) by juju.arbash-meinel.com (Postfix) with ESMTP id 3715E55F98; Mon, 11 Jul 2005 18:42:07 -0500 (CDT) Message-ID: <42D303CA.2020808@arbash-meinel.com> Date: Mon, 11 Jul 2005 18:42:02 -0500 From: John A Meinel User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: jobapply Cc: pgsql-performance@postgresql.org Subject: Re: Sorting on longer key is faster ? References: <20050709183842.2EABF52820@svr1.postgresql.org> In-Reply-To: <20050709183842.2EABF52820@svr1.postgresql.org> X-Enigmail-Version: 0.91.0.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigB810D5620F6C038341525139" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.038 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/115 X-Sequence-Number: 13356 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB810D5620F6C038341525139 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit jobapply wrote: > The 2 queries are almost same, but ORDER BY x||t is FASTER than ORDER BY x.. > > How can that be possible? > > Btw: x and x||t are same ordered > > phoeniks=> explain analyze SELECT * FROM test WHERE i<20 ORDER BY x || t; > QUERY PLAN > What types are x and t, I have the feeling "x || t" is actually a boolean, so it is only a True/False sort, while ORDER BY x has to do some sort of string comparison (which might actually be a locale depended comparison, and strcoll can be very slow on some locales) John =:-> > ---------------------------------------------------------------------------- > ---------------------------------------------- > Sort (cost=2282.65..2284.92 rows=907 width=946) (actual > time=74.982..79.114 rows=950 loops=1) > Sort Key: (x || t) > -> Index Scan using i_i on test (cost=0.00..2238.09 rows=907 width=946) > (actual time=0.077..51.015 rows=950 loops=1) > Index Cond: (i < 20) > Total runtime: 85.944 ms > (5 rows) > > phoeniks=> explain analyze SELECT * FROM test WHERE i<20 ORDER BY x; > QUERY PLAN > ---------------------------------------------------------------------------- > --------------------------------------------- > Sort (cost=2280.38..2282.65 rows=907 width=946) (actual > time=175.431..179.239 rows=950 loops=1) > Sort Key: x > -> Index Scan using i_i on test (cost=0.00..2235.82 rows=907 width=946) > (actual time=0.024..5.378 rows=950 loops=1) > Index Cond: (i < 20) > Total runtime: 183.317 ms > (5 rows) > > > > > > phoeniks=> \d+ test > Table "public.test" > Column | Type | Modifiers | Description > --------+---------+-----------+------------- > i | integer | | > t | text | | > x | text | | > Indexes: > "i_i" btree (i) > "x_i" btree (xpath_string(x, 'data'::text)) > "x_ii" btree (xpath_string(x, 'movie/characters/character'::text)) > Has OIDs: no > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > --------------enigB810D5620F6C038341525139 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD4DBQFC0wPKJdeBCYSNAAMRAk14AJdsYOPYY3PHuBNilislLLiqOX11AKCC4Cki S4ZzdD/Y9WtZEsc0LA+xwA== =GwKr -----END PGP SIGNATURE----- --------------enigB810D5620F6C038341525139--