got this:
However, it doesn't use the index. I've tried all sorts of things, grouping indexes, splitting to individual indexes and nothing works. Can anyone advise? Thanks
--BB
Code:
CREATE TABLE `dat_question` (
`q` int(11) NOT NULL auto_increment,
`category_id` int(11) NOT NULL default '0',
`user_id` int(11) default '0',
`datetime` int(11) NOT NULL default '0',
`x` int(11) NOT NULL default '0',
`y` int(11) NOT NULL default '0',
`x1` int(11) NOT NULL default '0',
`x2` int(11) NOT NULL default '0',
`y1` int(11) NOT NULL default '0',
`y2` int(11) NOT NULL default '0',
`r` int(11) NOT NULL default '0',
`views` int(11) NOT NULL default '0',
`host` varchar(128) NOT NULL default '',
`name` varchar(64) NOT NULL default '',
`text` text NOT NULL,
`lines` int(11) NOT NULL default '0',
`active` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`q`),
KEY `x` (`x`),
KEY `y` (`y`),
KEY `category_id` (`category_id`),
KEY `user_id` (`user_id`),
KEY `datetime` (`datetime`),
KEY `active` (`active`),
KEY `xs` (`x1`,`x2`),
KEY `ys` (`y1`,`y2`)
) TYPE=MyISAM AUTO_INCREMENT=1;
SELECT *, SQRT(POW(x-$x,2)+POW(y-$y,2)) as distance
FROM `dat_question`
WHERE x1 <= $x <= x2
AND y1 <= $y <= y2
AND SQRT(POW(x-$x,2)+POW(y-$y,2)) <= r
EXPLAIN:
table type possible_keys key key_len ref rows Extra
dat_question ALL NULL NULL NULL NULL 439400 Using where
--BB