Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best way to UPDATE many rows at once is :</p> <ul> <li>CREATE TEMP TABLE</li> <li>Fill it with (primary key, new values) with a big INSERT</li> <li>UPDATE table JOIN temptable USING (primary key) SET table.oldvalue=temptable.newvalue</li> </ul> <p>Update :</p> <pre><code>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 | +----+-------------+-------+-------+---------------+------+---------+------+------+-------------+ </code></pre> <p>No problem here (MySQL 5.1.41)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload