Unix Technical Forum

BETWEEN, IN, >, < .... not using index with floats

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-18-2008, 10:02 PM
Nacho Garcia
 
Posts: n/a
Default BETWEEN, IN, >, < .... not using index with floats

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-18-2008, 10:02 PM
Jerry Stuckle
 
Posts: n/a
Default Re: BETWEEN, IN, >, < .... not using index with floats

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
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:55 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com