Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2231D1337B78 for ; Tue, 14 Sep 2010 08:31:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 09016-02 for ; Tue, 14 Sep 2010 11:31:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from blu0-omc2-s2.blu0.hotmail.com (blu0-omc2-s2.blu0.hotmail.com [65.55.111.77]) by mail.postgresql.org (Postfix) with ESMTP id DCD231337B76 for ; Tue, 14 Sep 2010 08:31:35 -0300 (ADT) Received: from BLU0-SMTP82 ([65.55.111.72]) by blu0-omc2-s2.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 14 Sep 2010 04:31:35 -0700 X-Originating-IP: [174.91.0.92] X-Originating-Email: [fbax@sympatico.ca] Message-ID: Received: from t60p.bax.ca ([174.91.0.92]) by BLU0-SMTP82.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 14 Sep 2010 04:31:35 -0700 Date: Tue, 14 Sep 2010 07:31:33 -0400 From: Frank Bax User-Agent: Thunderbird 2.0.0.23 (X11/20100309) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Question regarding indices References: <20100911122923.75010@gmx.net> <20100913000306.202150@gmx.net> In-Reply-To: <20100913000306.202150@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 14 Sep 2010 11:31:35.0349 (UTC) FILETIME=[6355C650:01CB5400] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201009/35 X-Sequence-Number: 34566 Steve wrote: > -------- Original-Nachricht -------- >> Datum: Sat, 11 Sep 2010 11:08:00 -0400 >> Von: Lew >> An: pgsql-sql@postgresql.org >> Betreff: Re: [SQL] Question regarding indices > >> On 09/11/2010 08:29 AM, Steve wrote: >>> I have a small question about the order of values in a query. >>> Assume I have a table with the following fields: >>> uid INT, >>> data BIGINT, >>> hits INT >>> And an unique index on (uid, data). I use libpq C API to query >>> data from the table. The query is something like this: >>> SELECT uid,data,hits FROM mytable WHERE uid=2 >>> AND data IN (2033,2499,590,19,201,659) >>> >>> Would the speed of the query be influenced if I would sort the data? >> What do you mean by "sort the data"? Which data? >> > I mean sorting the values in the brackets. Instead of: > SELECT uid,data,hits FROM mytable WHERE uid=2 AND data IN (2033,2499,590,19,201,659) > > I would then send this here: > SELECT uid,data,hits FROM mytable WHERE uid=2 AND data IN (19,201,590,659,2033,2499) > > Off course this is a small dataset but the query usually has thousands of elements and not only the above 6 elements. If there will be thousands; why not create a temp table containing these values then join to table - might that be faster?