一次更新许多行的最好方法是:
- 创建临时表
- 与(主键,新的值)有一个大的INSERT
- 更新表JOIN不是Temptable使用强制它(主键)SET table.oldvalue = temptable.newvalue
更新:
create table test (id integer primary key, p point not null);
insert into test (id,p) select id, POINT(id%100, floor(id/100)) from serie limit 10000;
alter table test add spatial index spi (p);
select id, AsText(p) from test;
+----+-------------+
| id | AsText(p) |
+----+-------------+
| 1 | POINT(1 0) |
| 2 | POINT(2 0) |
| 3 | POINT(3 0) |
...
| 98 | POINT(98 0) |
| 99 | POINT(99 0) |
| 100 | POINT(0 1) |
| 101 | POINT(1 1) |
...
| 9999 | POINT(99 99) |
| 10000 | POINT(0 100) |
+-------+--------------+
EXPLAIN SELECT id,AsText(p) from test where Contains(GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))'), p);
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | test | range | spi | spi | 34 | NULL | 112 | Using where |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
create temporary table test2 (id integer primary key, p point not null);
insert into test2 (id,p) select id, POINT(1+(id%100), 1+floor(id/100)) from serie limit 10000;
update test, test2 set test.p=test2.p where test.id=test2.id;
EXPLAIN SELECT id,AsText(p) from test where Contains(GeomFromText('POLYGON((0 0,0 10,10 10,10 0,0 0))'), p);
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | test | range | spi | spi | 34 | NULL | 102 | Using where |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
这里没问题(MySQL 5.1.41)
为什么你要“移动”对象?这是什么?你能举一个真实的例子,而不是你的标注版本,因为某些原因删除了所有多汁的东西? –
我同意...移动似乎是错误的,而是更新某个地方的状态。并显示实际帮助的实际努力。 – Randy
我有iphone游戏Floonr,人们可以在其中启动虚拟气球并在实际地图上进行跟踪。 im模拟风的变化每次更新取决于经纬度,lon – RolandasR