Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 3BB1C632F17 for ; Sun, 12 Sep 2010 21:03:23 -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 56397-09 for ; Mon, 13 Sep 2010 00:03:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.23]) by mail.postgresql.org (Postfix) with SMTP id 207A4632F12 for ; Sun, 12 Sep 2010 21:03:11 -0300 (ADT) Received: (qmail 1869 invoked by uid 0); 13 Sep 2010 00:03:09 -0000 Received: from 193.247.250.57 by www027.gmx.net with HTTP; Mon, 13 Sep 2010 02:03:06 +0200 (CEST) Content-Type: text/plain; charset="utf-8" Date: Mon, 13 Sep 2010 02:03:06 +0200 From: "Steve" In-Reply-To: Message-ID: <20100913000306.202150@gmx.net> MIME-Version: 1.0 References: <20100911122923.75010@gmx.net> Subject: Re: Question regarding indices To: pgsql-sql@postgresql.org X-Authenticated: #26630975 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX19U3wEX4dpUf1Qt4BdhKdkhaKb/ENnTLDekVRo9ty NnkL4hy7CAAMFTVGXEj1gVMs1p31hiJPLvhQ== Content-Transfer-Encoding: 8bit X-GMX-UID: DF+/dMB9Pjl+BwpvoDQ2Zzo7MTE2Ncnq X-FuHaFi: 0.52000000000000002 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.208 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HK_RANDOM_ENVFROM=0.001, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SORBS_WEB=0.77, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/33 X-Sequence-Number: 34564 -------- 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. > > I can imagine that just querying a bunch of bigint would not make a > > big difference but what about several thousand of values? Would sorting > > them and sending the SQL query with ordered data influence the speed of > the query? > > Send the query from where to where? > Sending the query from my application to the PostgreSQL server. > Are you referring to a sort of the items in the IN subselect? > Yes. > My guess is > that sorting that won't matter but it's only a WAG. > What is "WAG"? > -- > Lew > SteveB -- Achtung Sicherheitswarnung: GMX warnt vor Phishing-Attacken! http://portal.gmx.net/de/go/sicherheitspaket