Re: Question regarding indices

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Question regarding indices
Date: 2010-09-14 11:31:33
Message-ID: BLU0-SMTP822F4EE03686BA05451C63AC780@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Steve wrote:
> -------- Original-Nachricht --------
>> Datum: Sat, 11 Sep 2010 11:08:00 -0400
>> Von: Lew <noone(at)lewscanon(dot)com>
>> An: pgsql-sql(at)postgresql(dot)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?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Nathan Grange 2010-09-14 16:56:44 Re: 9.0rc1 - query of view produces unexpected results
Previous Message Alvaro Herrera 2010-09-14 03:58:51 Re: 9.0rc1 - query of view produces unexpected results