This is a discussion on BETWEEN, IN, >, < .... not using index with floats within the MySQL General forum forums, part of the MySQL category; --> Hi, im working with google maps and im and trying to do this, but i cant make a good ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, im working with google maps and im and trying to do this, but i cant make a good query of it. I want to select elements between a given latitude and longitude from this table: *CREATE TABLE `images` (* *`id_img` bigint(20) unsigned NOT NULL auto_increment,** **`filename` char(50) NOT NULL,** **`extension` enum('jpg','jpeg','gif','png') NOT NULL,** **`lat` float(10,6) NOT NULL,** **`lng` float(10,6) NOT NULL,* *PRIMARY KEY (`id_img`),** **KEY `lat` (`lat`,`lng`) **) ENGINE=InnoDB DEFAULT CHARSET=utf8* ** ** ** im trying with this query and some similars but all of them scans all the table, and i dont know why SELECT * FROM `images` WHERE lat BETWEEN 29.993002 AND 49.410973 AND lng BETWEEN -40.209960 AND 32.871093 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE images ALL lat NULL NULL NULL 108 Using where thanks in advance |
| ||||
| Nacho Garcia wrote: > Hi, im working with google maps and im and trying to do this, but i cant > make a good query of it. > > I want to select elements between a given latitude and longitude from this > table: > > *CREATE TABLE `images` (* > > *`id_img` bigint(20) unsigned NOT NULL auto_increment,** > **`filename` char(50) NOT NULL,** > **`extension` enum('jpg','jpeg','gif','png') NOT NULL,** > **`lat` float(10,6) NOT NULL,** > **`lng` float(10,6) NOT NULL,* > > *PRIMARY KEY (`id_img`),** > **KEY `lat` (`lat`,`lng`) > **) ENGINE=InnoDB DEFAULT CHARSET=utf8* > > ** > > ** > > ** > > > im trying with this query and some similars but all of them scans all the > table, and i dont know why > > > SELECT * > FROM `images` > WHERE lat BETWEEN 29.993002 AND 49.410973 > AND lng BETWEEN -40.209960 AND 32.871093 > > > id select_type table type possible_keys key > key_len ref rows Extra > 1 SIMPLE images ALL lat NULL > NULL NULL 108 Using where > > > thanks in advance > What's your data look like? If a high percentage of the table falls within your ranges, MySQL may determine it's faster to do a table scan than try to use an index. What do you get if you try: SELECT COUNT(*) FROM images; SELECT COUNT(*) FROM images WHERE lat BETWEEN 29.993002 AND 49.410973; SELECT COUNT(*) FROM images; WHERE lng BETWEEN -40.209960 AND 32.871093; -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |