Home » Performance » MySQL » Query Speed Help
Query Speed Help [message #577] Wed, 10 January 2007 16:44 Go to next message
Steele  is currently offline Steele
Messages: 1
Registered: January 2007
Junior Member
Hi all,

I've been breaking my head with this for a while now. I have a query, which is very slow and I'm trying to find a way to speed it up. It takes several seconds (usually between 3 and 10) to run the query.

----------------------------------------------------

TABLE STRUCTURE:

CREATE TABLE `ipcountry` (
`ipFROM` double unsigned NOT NULL default '0',
`ipTO` double unsigned NOT NULL default '0',
`countrySHORT` char(2) NOT NULL default '',
`countryLONG` varchar(255) NOT NULL default '',
`REGION` varchar(128) default NULL,
`CITY` varchar(128) default NULL,
`ISP_NAME` text,
PRIMARY KEY (`ipFROM`,`ipTO`),
KEY `ipFROM` (`ipFROM`),
KEY `ipTO` (`ipTO`)
) TYPE=MyISAM;


Number of records: 4,970,567

Index is on ipFROM and ipTO fields.

ipFROM and ipTO are integer numbers between 8 and 10 digits long.

----------------------------------------------------

QUERY:

SELECT countryLONG from ipcountry WHERE ipFROM <= 3521274926 AND ipTO >= 3521274926

This query basically looks up a value which is located in a range between 2 values in one record.

----------------------------------------------------

Any ideas how to speed it up?

Thanks!

[Updated on: Thu, 11 January 2007 09:55]

Re: Query Speed Help [message #578 is a reply to message #577 ] Wed, 10 January 2007 16:54 Go to previous message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
8 sec)

I have tried this on several machines with different architectures and different configurations the result is the same .... please help me with this problem?

/TedThe index is secondary in this case what is important is join order, which you can force with STRAIGHT_JOIN hint by the way.

Note the order of tables becomes different and this is why.

Scanning large table and doing single row lookups in tiny tables is faster than other way around. Quite expected. Thanks for your answer!

With straight_join the question takes 7 s, but if you always use straigh


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Previous Topic:Simple LEFT JOIN still uses file sort
Next Topic:Your professional standpoint: high cpu-load...
Goto Forum:
  


Current Time: Fri Jul 10 02:12:13 EDT 2009

Total time taken to generate the page: 0.03548 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.