![]() | |
#1
| |||
| |||
|
|
Consider this table (Person) with example row: pKey | name | city | county | coordX | coordY 4321 | Tom | Peel | Ville | 123654 | 987123 And this self join: SELECT * FROM Person AS P1 LEFT JOIN Person AS P2 ON sqrt(pow(P1.coordX - P2.coordX, 2) + pow(P1.coordY - P2.coordY, 2)) < 666 GROUP BY P1.pKey So each resulting row will represent a group of Persons that are located within 666 of each other. However joining on this pythag expression requires the calculation on every row for every row, cartesian join style. I have 2000 rows in this table, it takes along time by adding an addition join condition like p1.county = p2.county I can perform the query in a fraction of a second, but this is a hack, what about boundary conditions where a person is located between two cities? Anyone have any solution to this? |
#2
| |||
| |||
|
|
Consider this table (Person) with example row: pKey | name | city | county | coordX | coordY ---------------------------------------- 4321 | Tom | Peel | Ville | 123654 | 987123 And this self join: SELECT * FROM Person AS P1 LEFT JOIN Person AS P2 ON sqrt(pow(P1.coordX - P2.coordX, 2) + pow(P1.coordY - P2.coordY, 2)) < 666 GROUP BY P1.pKey |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
"VisionSet" <spam (AT) ntlworld (DOT) com> wrote in message news IjKa.357$%a.5664 (AT) newsfep4-glfd (DOT) server.ntli.net...Not sure if this would work, but assuming your coordinate fields are indexed, you could restrict first on (ABS(P1.X - P2.X) < 666) AND (ABS(P1.Y - P2.Y) < 666)) which is implicit as long as your coordinates are real numbers (no imaginary part). These should compute faster and, as long as MySQL does not perform a complete boolean evaluation, speed up the query. |
![]() |
| Thread Tools | |
| Display Modes | |
| |