一次更新許多行的最好方法是:
- 創建臨時表
- 與(主鍵,新的值)有一個大的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