UPDATE slow

Started by John Smithabout 23 years ago25 messagesgeneral
Jump to latest
#1John Smith
john_smith_45678@yahoo.com

I have about 11000 rows and this query is much slower than I expected:

update stats set clicks = 123;

stats is basically just: id, clicks; with indexes on each. Right now, the query takes about 10 seconds to execute. It's also on windows 2000/cygwin (if that contributes to slowness). Is it normal for updates like this on that many rows to take a while?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#2John Smith
john_smith_45678@yahoo.com
In reply to: John Smith (#1)
Re: UPDATE slow

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips? Also tried it on MySQL and the update is nearly instantaneous :(.
John
I have about 11000 rows and this query is much slower than I expected:

update stats set clicks = 123;

stats is basically just: id, clicks; with indexes on each. Right now, the query takes about 10 seconds to execute. It's also on windows 2000/cygwin (if that contributes to slowness). Is it normal for updates like this on that many rows to take a while?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#3John Smith
john_smith_45678@yahoo.com
In reply to: John Smith (#2)
Re: UPDATE slow

If this helps :)

db=# explain analyze update stats set clicks = 3344 where link_id=1;
QUERY PLAN
---------------------------------------------------------------------------------------
Index Scan using idx_link_id on stats
(cost=0.00..149.42 rows=50 width=30) (actual time=0.58..727.45 rows=9994 loops=1)
Index Cond: (link_id = 1)
Total runtime: 8361.93 msec
(3 rows)

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips? Also tried it on MySQL and the update is nearly instantaneous :(.
John
I have about 11000 rows and this query is much slower than I expected:

update stats set clicks = 123;

stats is basically just: id, clicks; with indexes on each. Right now, the query takes about 10 seconds to execute. It's also on windows 2000/cygwin (if that contributes to slowness). Is it normal for updates like this on that many rows to take a while?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#4Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: John Smith (#2)
Re: UPDATE slow

On Tue, 4 Feb 2003, John Smith wrote:

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips?
Also tried it on MySQL and the update is nearly instantaneous :(.

Hmm, does stats reference another table or is it referenced by another
table?

#5John Smith
john_smith_45678@yahoo.com
In reply to: Stephan Szabo (#4)
Re: UPDATE slow

It has two foreign key references to two other tables. No other tables reference stats though.
John
Stephan Szabo <sszabo@megazone23.bigpanda.com> wrote:
On Tue, 4 Feb 2003, John Smith wrote:

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips?
Also tried it on MySQL and the update is nearly instantaneous :(.

Hmm, does stats reference another table or is it referenced by another
table?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#6John Smith
john_smith_45678@yahoo.com
In reply to: John Smith (#5)
Re: UPDATE slow

I should also probably note that neither of the foreign key columns is being updated.
John
It has two foreign key references to two other tables. No other tables reference stats though.
John
Stephan Szabo <sszabo@megazone23.bigpanda.com> wrote:
On Tue, 4 Feb 2003, John Smith wrote:

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips?
Also tried it on MySQL and the update is nearly instantaneous :(.

Hmm, does stats reference another table or is it referenced by another
table?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#7Patric Bechtel
bechtel@ipcon.de
In reply to: John Smith (#3)
Re: UPDATE slow [Viruschecked]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 4 Feb 2003 14:37:48 -0800 (PST), John Smith wrote:

Hello John

try:

update stats set clicks=3344 where link_id=1::int8;

I suppose that link_id is an int8 datatype? This bug is already known and will hopefully be fixed in 7.4.

Patric

If this helps :)

db=# explain analyze update stats set clicks = 3344 where link_id=1;
QUERY PLAN
---------------------------------------------------------------------------------------
Index Scan using idx_link_id on stats
(cost=0.00..149.42 rows=50 width=30) (actual time=0.58..727.45 rows=9994 loops=1)
Index Cond: (link_id = 1)
Total runtime: 8361.93 msec
(3 rows)

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips? Also tried it on MySQL and the update is nearly instantaneous :(.
John
I have about 11000 rows and this query is much slower than I expected:

update stats set clicks = 123;

stats is basically just: id, clicks; with indexes on each. Right now, the query takes about 10 seconds to execute. It's also on windows 2000/cygwin (if that

contributes to slowness). Is it normal for updates like this on that many rows to take a while?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

PGP Public Key Fingerprint: 2636 F26E F523 7D62 4377 D206 7C68 06BB

-----BEGIN PGP SIGNATURE-----
Version: PGPsdk version 1.7.1 (C) 1997-1999 Network Associates, Inc. and its affiliated companies.

iQA+AwUBPkA2DXxoBrvMu8qQEQKJcwCY7c1OjuvS/RIQeN+q0Z4dWIHp/gCdFEAR
VRTPdgIp8C0PM6Tv3a2NqgA=
=4QYn
-----END PGP SIGNATURE-----

#8Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: John Smith (#6)
Re: UPDATE slow

On Tue, 4 Feb 2003, John Smith wrote:

I should also probably note that neither of the foreign key columns is being updated.

It doesn't matter, unfortunately. It currently checks even in that case
due to ON * SET DEFAULT having a failure case if you don't check when no
keys are changed (if you remove the default - and you can't necessarily
check this beforehand either if the defaults are not stable). Among the
various changes I've been working with is making it only do the check if
one of the set default cases is given or if the key changed.

#9John Smith
john_smith_45678@yahoo.com
In reply to: Stephan Szabo (#8)
Re: UPDATE slow [Viruschecked]

No difference speed-wise:(. link_id is int4 (as is clicks). I also tried:
update stats set clicks=3344::int4;
and it still takes about the same amount of time (5-10 secs).
John
Patric Bechtel <bechtel@ipcon.de> wrote:-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 4 Feb 2003 14:37:48 -0800 (PST), John Smith wrote:

Hello John

try:

update stats set clicks=3344 where link_id=1::int8;

I suppose that link_id is an int8 datatype? This bug is already known and will hopefully be fixed in 7.4.

Patric

If this helps :)

db=# explain analyze update stats set clicks = 3344 where link_id=1;
QUERY PLAN
---------------------------------------------------------------------------------------
Index Scan using idx_link_id on stats
(cost=0.00..149.42 rows=50 width=30) (actual time=0.58..727.45 rows=9994 loops=1)
Index Cond: (link_id = 1)
Total runtime: 8361.93 msec
(3 rows)

Just tried it on Linux - still takes 5-10 seconds. Any speed-up tips? Also tried it on MySQL and the update is nearly instantaneous :(.
John
I have about 11000 rows and this query is much slower than I expected:

update stats set clicks = 123;

stats is basically just: id, clicks; with indexes on each. Right now, the query takes about 10 seconds to execute. It's also on windows 2000/cygwin (if that

contributes to slowness). Is it normal for updates like this on that many rows to take a while?

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

PGP Public Key Fingerprint: 2636 F26E F523 7D62 4377 D206 7C68 06BB

-----BEGIN PGP SIGNATURE-----
Version: PGPsdk version 1.7.1 (C) 1997-1999 Network Associates, Inc. and its affiliated companies.

iQA+AwUBPkA2DXxoBrvMu8qQEQKJcwCY7c1OjuvS/RIQeN+q0Z4dWIHp/gCdFEAR
VRTPdgIp8C0PM6Tv3a2NqgA=
=4QYn
-----END PGP SIGNATURE-----

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#10Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Stephan Szabo (#8)
Re: UPDATE slow

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

I should also probably note that neither of the foreign key columns is being updated.

It doesn't matter, unfortunately. It currently checks even in that case
due to ON * SET DEFAULT having a failure case if you don't check when no
keys are changed (if you remove the default - and you can't necessarily
check this beforehand either if the defaults are not stable). Among the
various changes I've been working with is making it only do the check if
one of the set default cases is given or if the key changed.

I've actually got most of that done as part of the other patches I've been
working on. I could probably try to do the same to 7.3 (as opposed to
7.4 devel) and make a separate patch out of it.

#11John Smith
john_smith_45678@yahoo.com
In reply to: Stephan Szabo (#10)
Re: UPDATE slow

Think that makes sense ;). However, I just dropped all the foreign key constraints on stats and there wasn't any speed increase in the query. I've also tried dropping the index on clicks (no speed-up there either).
John
Stephan Szabo <sszabo@megazone23.bigpanda.com> wrote:
On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

I should also probably note that neither of the foreign key columns is being updated.

It doesn't matter, unfortunately. It currently checks even in that case
due to ON * SET DEFAULT having a failure case if you don't check when no
keys are changed (if you remove the default - and you can't necessarily
check this beforehand either if the defaults are not stable). Among the
various changes I've been working with is making it only do the check if
one of the set default cases is given or if the key changed.

I've actually got most of that done as part of the other patches I've been
working on. I could probably try to do the same to 7.3 (as opposed to
7.4 devel) and make a separate patch out of it.

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#12Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: John Smith (#11)
Re: UPDATE slow

On Tue, 4 Feb 2003, John Smith wrote:

Think that makes sense ;). However, I just dropped all the foreign key
constraints on stats and there wasn't any speed increase in the query.
I've also tried dropping the index on clicks (no speed-up there
either).

Can you duplicate it with a new table?

Something like:

create table foo as select * from stats;
update foo set clicks=3344;

#13scott.marlowe
scott.marlowe@ihs.com
In reply to: John Smith (#9)
Re: UPDATE slow [Viruschecked]

Might we see your table schema? This and the table(s) with the foreign
keys as well?

On Tue, 4 Feb 2003, John Smith wrote:

Show quoted text

No difference speed-wise:(. link_id is int4 (as is clicks). I also tried:
update stats set clicks=3344::int4;
and it still takes about the same amount of time (5-10 secs).
John

#14John Smith
john_smith_45678@yahoo.com
In reply to: Stephan Szabo (#12)
Re: UPDATE slow

That works - updates on foo take about 1.4 seconds. I dropped all the indexes and fk's on stats and updates there take about 2.8 seconds. These are on the cygwin machine.
Looking at the tables, foo doesn't have any modifiers for the columns (stats does - not null default 0).
John
Stephan Szabo <sszabo@megazone23.bigpanda.com> wrote:On Tue, 4 Feb 2003, John Smith wrote:

Think that makes sense ;). However, I just dropped all the foreign key
constraints on stats and there wasn't any speed increase in the query.
I've also tried dropping the index on clicks (no speed-up there
either).

Can you duplicate it with a new table?

Something like:

create table foo as select * from stats;
update foo set clicks=3344;

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#15scott.marlowe
scott.marlowe@ihs.com
In reply to: John Smith (#14)
Re: UPDATE slow

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the indexes and fk's on stats and updates there take about 2.8 seconds. These are on the cygwin machine.
Looking at the tables, foo doesn't have any modifiers for the columns (stats does - not null default 0).
John
Stephan Szabo <sszabo@megazone23.bigpanda.com> wrote:On Tue, 4 Feb 2003, John Smith wrote:

Think that makes sense ;). However, I just dropped all the foreign key
constraints on stats and there wasn't any speed increase in the query.
I've also tried dropping the index on clicks (no speed-up there
either).

Can you duplicate it with a new table?

Something like:

create table foo as select * from stats;
update foo set clicks=3344;

Is this a table that got a lot of updates en masse? If it was regularly
vacuumed but you still had a problem, it might be index bloat. Keep an
eye on it, and if the table starts to get slow, try reindexing the indexes
on that table and see if that happens.

The "fix" for this problem is to crank up max fsm settings, and run vacuum
more often, but that doesn't always actually fix things.

#16Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: John Smith (#14)
Re: UPDATE slow

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the
indexes and fk's on stats and updates there take about 2.8 seconds.
These are on the cygwin machine.

The 2.8 seconds is on stats after dropping the fks and indexes? But
it didn't help on the linux box?

Have you done a vacuum/reindex recently?

#17Nigel J. Andrews
nandrews@investsystems.co.uk
In reply to: Stephan Szabo (#16)
Re: UPDATE slow

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the
indexes and fk's on stats and updates there take about 2.8 seconds.
These are on the cygwin machine.

The 2.8 seconds is on stats after dropping the fks and indexes? But
it didn't help on the linux box?

I tried this earlier on just a plain:

create table testme ( id integer unique, clicks integer unique );

This is my explain:

desticorp=> explain analyze select count(1) from testme;
NOTICE: QUERY PLAN:

Aggregate (cost=22.50..22.50 rows=1 width=0) (actual time=78.52..78.52 rows=1 loops=1)
-> Seq Scan on testme (cost=0.00..20.00 rows=1000 width=0) (actual time=0.11..51.74 rows=11999 loops=1)
Total runtime: 78.67 msec

EXPLAIN

desticorp=> explain analyze update testme set clicks = clicks + 123;
NOTICE: QUERY PLAN:
Seq Scan on testme (cost=0.00..20.00 rows=1000 width=14) (actual time=0.03..256.21 rows=11999 loops=1)
Total runtime: 2060.41 msec

EXPLAIN

As you can see this took 2 seconds after already been given the chance to cache
the table. It's also possible to see that I used 12000 rows in my table and
that the sequential scan part of the operation is a helluva lot slower when
writing.

This is on a dual P-III 550MHz system. Memory settings probably aren't tuned
too much though I don't think that would impact too much on this quick
test. Although loaded and usually noticable delays in window refresh when
flicking through my screens this system seems to have a very low CPU
utilisation and plenty of memory usable (for a change). Although I am wondering
what I've run in the last couple of weeks that's pushed me to use 150MB of swap
(768MB physical so not an insignificant amount).

Therefore John's 2.8s seems a reasonable time to me.

--
Nigel J. Andrews

#18Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Nigel J. Andrews (#17)
Re: UPDATE slow

On Wed, 5 Feb 2003, Nigel J. Andrews wrote:

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the
indexes and fk's on stats and updates there take about 2.8 seconds.
These are on the cygwin machine.

The 2.8 seconds is on stats after dropping the fks and indexes? But
it didn't help on the linux box?

desticorp=> explain analyze update testme set clicks = clicks + 123;
NOTICE: QUERY PLAN:
Seq Scan on testme (cost=0.00..20.00 rows=1000 width=14) (actual time=0.03..256.21 rows=11999 loops=1)
Total runtime: 2060.41 msec

EXPLAIN

As you can see this took 2 seconds after already been given the chance to cache
the table. It's also possible to see that I used 12000 rows in my table and
that the sequential scan part of the operation is a helluva lot slower when
writing.

This is on a dual P-III 550MHz system. Memory settings probably aren't tuned
too much though I don't think that would impact too much on this quick
test. Although loaded and usually noticable delays in window refresh when
flicking through my screens this system seems to have a very low CPU
utilisation and plenty of memory usable (for a change). Although I am wondering
what I've run in the last couple of weeks that's pushed me to use 150MB of swap
(768MB physical so not an insignificant amount).

Therefore John's 2.8s seems a reasonable time to me.

Yeah, but I thought he'd said that on the linux box, even after dropping
indexes and fks it was taking 5-10 seconds.

I'm also a bit confused because I'm not sure he's getting 2.8 seconds to
update all the records or just a single record.

#19Nigel J. Andrews
nandrews@investsystems.co.uk
In reply to: Stephan Szabo (#18)
Re: UPDATE slow

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Wed, 5 Feb 2003, Nigel J. Andrews wrote:

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the
indexes and fk's on stats and updates there take about 2.8 seconds.
These are on the cygwin machine.

The 2.8 seconds is on stats after dropping the fks and indexes? But
it didn't help on the linux box?

...

Yeah, but I thought he'd said that on the linux box, even after dropping
indexes and fks it was taking 5-10 seconds.

You miss remembered :)

I'm also a bit confused because I'm not sure he's getting 2.8 seconds to
update all the records or just a single record.

I'm pretty sure the command originally quoted was an unconstrained update
setting a constant value, i.e. all the rows. I had to change my test because
I'd setup unique indexes so couldn't do the constant value bit.

--
Nigel Andrews

#20Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Nigel J. Andrews (#19)
Re: UPDATE slow

On Wed, 5 Feb 2003, Nigel J. Andrews wrote:

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Wed, 5 Feb 2003, Nigel J. Andrews wrote:

On Tue, 4 Feb 2003, Stephan Szabo wrote:

On Tue, 4 Feb 2003, John Smith wrote:

That works - updates on foo take about 1.4 seconds. I dropped all the
indexes and fk's on stats and updates there take about 2.8 seconds.
These are on the cygwin machine.

The 2.8 seconds is on stats after dropping the fks and indexes? But
it didn't help on the linux box?

...

Yeah, but I thought he'd said that on the linux box, even after dropping
indexes and fks it was taking 5-10 seconds.

You miss remembered :)

In any case that's 3x slower than my development box which is not terribly
powerful and not set up as a database server for real using pretty much
all default configuration settings with the database on the same partition
as / (/usr, etc...).

I'm also a bit confused because I'm not sure he's getting 2.8 seconds to
update all the records or just a single record.

I'm pretty sure the command originally quoted was an unconstrained update
setting a constant value, i.e. all the rows. I had to change my test because
I'd setup unique indexes so couldn't do the constant value bit.

That's what the first message was, but his first followup with an explain
analyze output used:

explain analyze update stats set clicks = 3344 where link_id=1;

#21John Smith
john_smith_45678@yahoo.com
In reply to: scott.marlowe (#13)
#22John Smith
john_smith_45678@yahoo.com
In reply to: scott.marlowe (#15)
#23John Smith
john_smith_45678@yahoo.com
In reply to: Stephan Szabo (#16)
#24John Smith
john_smith_45678@yahoo.com
In reply to: John Smith (#23)
#25Tom Lane
tgl@sss.pgh.pa.us
In reply to: John Smith (#22)