On 4/22/07, Gilles Roy <[EMAIL PROTECTED]> wrote:
On Sun, Apr 22, 2007 at 05:33:43PM -0500, P Kishor wrote:
>On 4/22/07, Gilles Roy <[EMAIL PROTECTED]> wrote:
>>Given a arbitrary statement, I need to find out which row a specific
>>result is in, as efficiently as possible. The arbitrary statement can
>>order the results any way it wants.

>what do you mean by "which row"? Do you want to know the position of
>the required row within your result set, sort of like

>i = 0
>foreach row
> if currentrow's memberid == 4567373
>   print i
>   get out of the loop
> else
>   i++

That is what I want to do. I want to know where the memberid is in the
list (imagine the list was a waiting list or something). Is there not a
way to just get the row number back? Is seems inefficient to have to
allocate all of the memory to hold all of the results and then iterate
through them.


yeah well, but it is an inefficient task that you are asking to do.
From your query, I am assuming that memberid 4567373 is not row number
4567373 in you dataset. And, even if it is, you have chosen a smaller
set out of your entire dataset... say, 13 rows out of your 2 million
rows. Somewhere in there you have a row whose memberid is 4567373,
say, the 11th row. You want your answer to be "11."

Well, there is no magic here... in the worst case you have to check
all the rows. The best you can do is to order the rows by memberid,
and then stop checking  each row's memberid as soon as you find what
you are looking for (like indicated in the pseudocode above).

The problem you have to deal with is that the position of the row in
your result set is an entirely artificial artifact, totally of your
making. If you order the rows by memberid, maybe your row is 11th.
But, if you order your rows by last name then your row might be the
first one. You have to impose the order, and then check what that
order did to your row.

All that said, why are you worried about the above being
"inefficient"? Is your dataset very big? Are working on a 286 with
640k of ram and a 1 Mb flashdisk for storage? Are your results coming
in very slow? You have to give more info when establishing the
parameters.

--
Puneet Kishor http://punkish.eidesis.org/
Nelson Inst. for Env. Studies, UW-Madison http://www.nelson.wisc.edu/
Open Source Geospatial Foundation http://www.osgeo.org/education/
---------------------------------------------------------------------
collaborate, communicate, compete
=====================================================================

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to