在 MySql BLOB 列上创建空间索引时出错

发布于 2024-08-01 22:18:55 字数 1028 浏览 3 评论 0原文

我正在尝试将空间索引添加到名为 Location 的 BLOB 类型的表列。 如果我尝试这个:

ALTER TABLE route ADD SPATIAL INDEX(Location); 

我得到:

错误:BLOB/TEXT 列“位置” 用于关键规范,无需 密钥长度

但是在 MySql 5.1 的官方文档 (我正在使用的版本),它在提到空间索引时清楚地说:

“在 MySQL 5.1 中,列前缀长度 被禁止。 每个的全宽 列已编入索引。”

这肯定表明我不需要提供前缀。我尝试添加前缀,如下所示:

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

我得到:

错误:前缀键不正确; 使用过的 关键部分不是字符串,使用的 长度比关键部分长,或者 存储引擎不支持 唯一的前缀键

那么到底发生了什么? 有关信息,我正在使用 MySQL 5.1.37 社区,我的表是 MyISAM,这是创建语句:

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 我也尝试过将 Location 设置为 NOT NULL,这没有什么区别。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意犹 2024-08-08 22:18:55

应在 GEOMETRY 类型上创建空间索引。

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;

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;
音盲 2024-08-08 22:18:55

我相信您尝试添加空间索引的列应声明为不为空。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文