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 1A08B52977 for ; Mon, 11 Jul 2005 22:52:33 -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 00888-03 for ; Tue, 12 Jul 2005 01:52:28 +0000 (GMT) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by svr1.postgresql.org (Postfix) with ESMTP id 4082C52994 for ; Mon, 11 Jul 2005 22:52:27 -0300 (ADT) Received: from juju.arbash-meinel.com ([12.214.18.81]) by sccmmhc91.asp.att.net (sccmmhc91) with ESMTP id <20050712015231m9100cftf2e>; Tue, 12 Jul 2005 01:52:32 +0000 Received: by juju.arbash-meinel.com (Postfix, from userid 505) id 87E3755FEC; Mon, 11 Jul 2005 20:52:31 -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 C03F155F98; Mon, 11 Jul 2005 20:52:27 -0500 (CDT) Message-ID: <42D32259.2000705@arbash-meinel.com> Date: Mon, 11 Jul 2005 20:52:25 -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="------------enigBEFD86D74D4F6EC79AD16D69" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.04 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/118 X-Sequence-Number: 13359 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBEFD86D74D4F6EC79AD16D69 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 I also thought of another possibility. Are there a lot of similar entries in X? Meaning that the same value is repeated over and over? It is possible that the sort code has a weakness when sorting equal values. For instance, if it was doing a Hash aggregation, you would have the same hash repeated. (It isn't I'm just mentioning a case where it might affect something). If it is creating a tree representation, it might cause some sort of pathological worst-case behavior, where all entries keep adding to the same side of the tree, rather than being more balanced. I don't know the internals of postgresql sorting, but just some ideas. John =:-> --------------enigBEFD86D74D4F6EC79AD16D69 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 iD8DBQFC0yJZJdeBCYSNAAMRAqNvAJ9ISh6cVjxogvmOiwRfIl4qATHrEgCfetFN P5ittkgSVxFUPpcfR+AztqU= =MbUn -----END PGP SIGNATURE----- --------------enigBEFD86D74D4F6EC79AD16D69--