Afficher un message
Vieux 03/10/2007, 19h58   #1
Greg Hennessy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut advice on rewriting a query

I'm an astronomer who is basically self taught on mysql.
I'm trying to use mysql to match star lists.
I have each star list in a table, and part of the information
is the position of each star both as a RA/Dec pair (think lat/long),
as well as a unit vector x,y,z triplet.
Ideally I'd just code up a match of one star list verses the other,
but with one list being 2.5 million stars, and the list being 36
million stars, that takes a while. Since star matching is a N^2
algorithm, I'm trying to cut the run time by having an indexed value
obtained from NASA "Healpix", which can be described as an integer
value that depends on the star's position, stars near the north pole
have numbers near 0, stars near the south pole have a large value.

My ideal query would be

select h.prikey,t.pts_key,h.rad,h.ded,
h.btmag,h.vtmag,t.rad,t.decd,t.j,t.h,t.k
from hiptyc as h join twomass_b as t
where
h.x*t.x+h.y*t.y+h.z*t.z >= @DIST
and h.nest4 = t.nest4
;

which explains as:

mysql> explain select h.prikey,t.pts_key,h.rad,h.ded,
-> h.btmag,h.vtmag,t.rad,t.decd,t.j,t.h,t.k
-> from hiptyc as h join twomass_b as t
-> where
-> h.x*t.x+h.y*t.y+h.z*t.z >= @DIST
-> and h.nest4 = t.nest4
-> ;
+----+-------------+-------+------+---------------+-------+---------+---------------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len |
ref | rows | Extra |
+----+-------------+-------+------+---------------+-------+---------+---------------+---------+-------------+
| 1 | SIMPLE | h | ALL | nest4 | NULL | NULL |
NULL | 2563737 | |
| 1 | SIMPLE | t | ref | nest4 | nest4 | 5 |
ucac3.h.nest4 | 11904 | Using where |
+----+-------------+-------+------+---------------+-------+---------+---------------+---------+-------------+
2 rows in set (0.00 sec)


I can get reasonable subsamples by adding a

nest4 between X and Y

to the query, and then repeating the query with
new values for X and Y untill I get full coverage.

If I were writing this in Fortran or C, I'd obviously set up a loop
to cover all I need, but is there a way in SQL to do the equivalent
loop?

Does anyone have any other idea on how to get mysql to do what I want?

Thanks for any sugguestions.

  Réponse avec citation
 
Page generated in 0,05749 seconds with 9 queries