641

SQL Query

Salut prieteni.Am MySQL 4.0.XSi 2 tabele:mysql> desc stats3_redirects;+-------+------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+------------------+------+-----+---------+----------------+| id | int(15) unsigned | | PRI | NULL | auto_increment || url | varchar(255) | YES | | NULL | || date | varchar(10) | YES | | NULL | || time | varchar(8) | YES | | NULL | || ip | varchar(15) | YES | | NULL | |+-------+------------------+------+-----+---------+----------------+5 rows in set (0.02 sec)Simysql> desc stats3_catch;+-------+------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+------------------+------+-----+---------+----------------+| id | int(15) unsigned | | PRI | NULL | auto_increment || date | varchar(10) | YES | | NULL | || time | varchar(8) | YES | | NULL | || ip | varchar(15) | YES | | NULL | || url | varchar(255) | YES | | NULL | |+-------+------------------+------+-----+---------+----------------+5 rows in set (0.00 sec)Din cate ati observat 2 tabele care au aceeasi structura. Fiecare are undeva cate 10.000 de inregistrari.Am un query:SELECT COUNT(DISTINCT stats3_redirects.ip) as num FROM stats3_catch, stats3_redirects WHERE stats3_catch.ip=stats3_redirects.ip AND stats3_catch.date=stats3_redirects.date AND stats3_redirects.url LIKE '%www.site.com%';Cam de-aceeasi teapa:Select count(distinct stats3_redirects.ip) as num FROM stats3_redirects LEFT JOIN stats3_catch ON stat3_redirects.ip=stats3_catch.ip AND BLALALALALAProblema este сa FRANREAZA EXTRAORDINAR!!! Sunt sigur ca problema este in querz-ul meu si ca se poate de facut mai optim.Ce se cere: De selectat numarul de IP-uri la care coincid data si unde url-ul este o anumita valoare.Please advise.Thanks!Deci...... am observat ceva urat, la mine precis ceva nu-i in regula. Daca facmysql> SELECT COUNT(DISTINCT stats3_redirects.ip) as num FROM stats3_catch, stats3_redirects WHERE stats3_catch.ip=stats3_redirects.ip AND stats3_catch.date=stats3_redirects.date AND stats3_redirects.url LIKE 'www.site.com%' LIMIT 1;+------+| num |+------+| 3829 |+------+1 row in set (22.91 sec)Se executa in 22 de secunde cu rezultatul necesar, doar la adaugarea limitei adica LIMIT 1Adica ceva face recursiv prea mult.
0