Long query times, How can i get this down :(
Hi Guys,
I have a problem with one of my queries.
It takes far to long to execute and uses too much CPU.
Does anyone know how to make it cleaner?
I have a table of IP addresses with some details in them like country, lat long etc.
My query will simply get the last 30 hits based on IP address and Time for Xsiteid( last 30 IP's )
heres the DB structure..
+-----------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+-------------------+----------------+
| id | int(15) | NO | PRI | NULL | auto_increment |
| ip | varchar(26) | NO | | NULL | |
| time | timestamp | NO | | CURRENT_TIMESTAMP | |
| siteid | varchar(30) | NO | | NULL | |
| country | varchar(2) | NO | | NULL | |
| town | varchar(40) | NO | | Unknown | |
| lat | varchar(8) | NO | | Unknown | |
| lon | varchar(8) | NO | | Unknown | |
| extra | varchar(100) | NO | | NULL | |
| requested | int(1) | NO | | 0 | |
| ref | tinytext | NO | | NULL | |
| browser | varchar(100) | NO | | Unknown | |
+-----------+--------------+------+-----+-------------------+----------------+
heres the query:
SELECT DISTINCT * from visitorips where siteid LIKE '372010' order by id desc limit 30;
Ive tried:
SELECT DISTINCT * from visitorips where siteid = '372010' order by id desc limit 30;
SELECT DISTINCT id,ip,ref,etc,etc,etc from visitorips where siteid LIKE '372010' order by id desc limit 30;
But these take just as long ( if longer )
5 rows in set (0.69 sec)
Uses like 150% cpu.
How can i get this down?
Im sure theres a better way to query the table?
It currently has 200k rows. ( last 62 days is all thats kept. )
I have a primary key on ID and nothing else.
However i did try putting an index on other columns and didnt gain any performance increase.
Thanks
G
Edited 1 time(s). Last edit at 02/09/2011 06:56AM by graham smart.
Subject
Views
Written By
Posted
Long query times, How can i get this down :(
2814
February 09, 2011 06:54AM
795
February 09, 2011 06:57AM
925
February 09, 2011 07:01AM
919
February 09, 2011 11:41AM
855
February 09, 2011 10:55AM
892
February 09, 2011 11:03AM
710
February 09, 2011 11:09AM
778
February 10, 2011 02:51AM
832
February 10, 2011 10:42AM
816
February 10, 2011 06:25PM
951
February 11, 2011 02:48AM
1046
February 11, 2011 09:01AM
788
February 10, 2011 09:30PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.