PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > advice on rewriting a query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
advice on rewriting a query

Réponse
 
LinkBack Outils de la discussion
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
Vieux 05/10/2007, 17h38   #2
Dwight Fowler
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: 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,
mysql>>
> -> 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.
>


Greg,

I think that you might be able to solve this with a simple sorted select
on the x,y,and z coordinates. A star in the first database that is the same
or close to a star in the second database will be sorted close to each other
in a sorted select statement. Put this list in a table.

I'm kinda new to MySQL, so I don't know if it has cursors. What I'm thinking
is that you could use a stored procedure to go through the sorted list of
stars with a cursor and compute the dot product of each row with the next.
Then put any dot product >= MyLimit into a new table.

I hope that s.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13782 seconds with 10 queries