I wonder if it would be beneficial to add an additional where clause which
can prefilter the data so you only need to perform the full calculation on a
subset of records. 

I haven't done the math, but let's supposed that point_x is 10 and that for
any result of your long calculation to be true, then x must be between 5 and
15, then you can use the where clause

WHERE
        X BETWEEN 5 AND 15
AND     (point_x - x)^2 + (point_y -y)^2 < R^2;


If you can make this type of pre-calculation and get a proper range for X
then it can reduce the number of records that need to be checked.  I'm
assuming SQLite will use an index on X for BETWEEN (I don't know for sure).
Also you should do testing to be sure this query really is faster in
practice--I'm only theorizing here.  :-)

HTH,

Sam


-------------------------------------------
We're Hiring! Seeking a passionate developer to join our team building
products. Position is in the Washington D.C. metro area. If interested
contact [EMAIL PROTECTED]
 
-----Original Message-----
From: bash [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 09, 2007 10:33 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] perfomance degradation for expr "foo = X or bar =X"

On Wed, 9 May 2007 18:13:07 +0400
Tomash Brechko <[EMAIL PROTECTED]> wrote:

Im currently thinking about this table:

CREATE TABLE map (
        x int,
        y int,
        name char
);
CREATE INDEX map_x ON map(x);
CREATE INDEX map_y ON map(y);

And query for it will be something like this (circle):
SELECT name
  FROM map
  WHERE (point_x - x)^2 + (point_y -y)^2 < R^2;

How SQLite will works? Is there any benefit in indexes?



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

Reply via email to