2

I am trying to add a spatial index to a table column named Location of type BLOB. If I try this:

ALTER TABLE route ADD SPATIAL INDEX(Location); 

I get:

Error: BLOB/TEXT column 'Location' used in key specification without a key length

But in the official docs for MySql 5.1 (the version I am using), it clearly says when referring to spatial indexes:

"In MySQL 5.1, column prefix lengths are prohibited. The full width of each column is indexed."

This surely says that I don't need to provide a prefix. I tried adding a prefix anyway like this:

ALTER TABLE route ADD SPATIAL INDEX(Location(256)); 

And I get:

Error: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys

So what the heck is going on?? For info, I am using MySQL 5.1.37 community, and my table is MyISAM, this is the create statement:

CREATE TABLE `climb`.`route` ( 
`Id` int(11) NOT NULL, 
`Name` varchar(255) NOT NULL, 
`Location` blob, 
PRIMARY KEY (`Id`), 
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

PS I have also tried making Location NOT NULL, this made no difference.

2 Answers 2

1

Spatial indexes should be created on GEOMETRY types.

CREATE TABLE `route` (
        `Id` int(11) NOT NULL, 
        `Name` varchar(255) NOT NULL, 
        `Location` GEOMETRY NOT NULL,
        PRIMARY KEY (`Id`),
        SPATIAL KEY (`Location`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1
  • Correct, although MySql supports using BLOBs for geometry columns (dev.mysql.com/doc/refman/5.1/en/gis-wkb-format.html) in the Well-Known Binary (WKB) Format, it seems you can't have a spatial index. The trick was getting Fluent NHibernate to do this, I had to force the SQL type with .CustomSqlTypeIs("GEOMETRY"). Thanks! Aug 17, 2009 at 20:33
0

I believe the column you try to add spatial index to should be declared not null.

1
  • Thanks for the idea, but unfortunatley this has made no difference :( I have made Location NOT NULL (have updated my post to show this), and still get the same error when I try to apply a spatial index. Aug 17, 2009 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.