Re: [SQL] Question regarding indices

2010-09-12 Thread Lew

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 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?

Are you referring to a sort of the items in the IN subselect?  My guess is 
that sorting that won't matter but it's only a WAG.


--
Lew

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Question regarding indices

2010-09-12 Thread Steve
 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

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql