Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 710CD6344D0 for ; Sat, 11 Sep 2010 12:04:27 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 24876-07 for ; Sat, 11 Sep 2010 15:04:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 9728662E452 for ; Sat, 11 Sep 2010 12:04:19 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o8BF4GZw017449; Sat, 11 Sep 2010 11:04:17 -0400 (EDT) To: "Steve" cc: pgsql-sql@postgresql.org Subject: Re: Question regarding indices In-reply-to: <20100911122923.75010@gmx.net> References: <20100911122923.75010@gmx.net> Comments: In-reply-to "Steve" message dated "Sat, 11 Sep 2010 14:29:23 +0200" Date: Sat, 11 Sep 2010 11:04:16 -0400 Message-ID: <17448.1284217456@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/26 X-Sequence-Number: 34557 "Steve" writes: > 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? 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? It's unlikely to make enough difference to be worth the trouble. regards, tom lane