Received: from exchange.hq.openratings.com (adsl-141-154-210-2.ba-dsg.net [141.154.210.2]) by postgresql.org (Postfix) with ESMTP id 04ED9479A7F for ; Mon, 15 Apr 2002 15:58:47 -0400 (EDT) Received: from openratings.com (cancun.hq.openratings.com [10.0.0.225]) by exchange.hq.openratings.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 2TBPVKH1; Mon, 15 Apr 2002 15:59:07 -0400 Message-ID: <3CBB4554.90701@openratings.com> Date: Mon, 15 Apr 2002 17:25:40 -0400 From: Dmitry Tkach User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.7+) Gecko/20020123 X-Accept-Language: en-us MIME-Version: 1.0 To: Neil Conway Cc: pgsql-general@postgresql.org Subject: Re: Alter/update large tables - VERRRY annoying behaviour! References: <3CBB08C8.7000705@openratings.com> <20020415142451.1d8a21d0.nconway@klamath.dyndns.org> Content-Type: text/html; charset=KOI8-R Content-Transfer-Encoding: quoted-printable X-Archive-Number: 200204/649 X-Sequence-Number: 23364 Neil Conway wrote:
On Mon, 15 Apr 2002 13:07:20 -0400
"Dmitry Tkach" <dm= itry@openratings.com> wrote:
Hi, everybody!

Hi Dmitry! Don't cross-post! It's annoying!
What do you mean by 'cross-post'?
Are you saying that posting to several lists at a time is annoying?
I just thought, that this problem might be interesting to people, who read those (and not necessarily ALL
of them)... What's annoying about it?

This took me awfully long, but worked (I guess).
= I say 'I guess', because I wasn't able so far to verify that - when I triue= d to do

select * from a limit 1;

It just hungs on me ... at l= east, it looks like it does.

This didn't hang, it just requires a sequ= ential scan of the whole table.
I know it does (as I said below). The point is that it SHOULD NOT, and espe= cially, that I can't imagine anyone, not familiar with postgres internals to expect that it would - all it needs to do is to grab the first row and return imme= diately.
That's what it would do, if you just create a new table and populate it with data.


As you observe below, it will also need to sca= n through dead tuples,
Not 'also' - JUST the dead ones! That's what's especially annoying about it - as soon as it finds the first tuple, that's not dead, it returns.

but that is just a product of MVCC and there= 's no real way around
it.
My whole point is that I don't believe it (that there is no way around) :-)=
For one thing, I have never seen ANY database engine (Oracle, Informix, DB2) that would take more than a second to get the first row from a table, regar= dless of what has been done to that table before.
That (and my common sense too) tells me that there MUST be a 'way around it'.
I can see, that it's not currently implemented in postgres, but do believe (and that's the whole point of me posting that message in the first place) that it is a huge usability issue and really needs to be fixed.
 Once you VACUUM the dead tuples will be remov=
ed and sequential
scans should be fast once more.

Yeah... I hope so. I am running vacuum on that table. It's been running for 6 hours now and still has not finished.
Doesn't it look to you like a little too much trouble to go through just to take a look at the first row of a table ? :-)

And, once again, I am not done modifying that schema - this is just an inte= rmediate step, which means, I will have to do the vacuum all over when I am finished= ...

This seems like WAY too much trouble to me :-(


And before assuming that something has h= ung, it's a good idea to
look at the output of EXPLAIN for that query, a= s well as monitoring
system performance (through top, vmstat, etc) to se= e what the
system is doing.
Yeah, right...

explain select * from a limit 1;
NOTICE:=9A QUERY PLAN:

Limit=9A (cost=3D0.00..1.01 rows=3D1 width=3D46)
=9A ->=9A Seq Scan on a=9A (cost=3D0.00..32529003.00 rows=3D32243660 wid= th=3D46)

EXPLAIN

There is absolutely nothing in this plan, that would suggest it will go on executing for ages...
Look at the 'cost' value for example...
In any event, there is nothing different in this plan from what I was getti= ng before I modified the table (when the query would take just a few milliseco= nds to be executed).

As for monitoring system performance... Well, I could see it maxing out on CPU usage and disk IO at times... How exactly does it help me to realize it did not hung?

(Let me clarify that - by 'hung' I mean 'not going to return the results in any reasonable time', not necessarily 'not doing anything at all')



Lucky me, I have compiled the backend fr=
om sources with full debug info, because if I hadn't done that,
(as most= users), I would certainly had thought, that my database is hopelessly corr= upted, and would have to
recreate it from scratch :-(

That's a ludicrous conclusion= .

Why is it?

First of all, a question for you - i=
s ANY update to a table equivalent (in this respect) to a delete+insert?

Yes, AFAIK -- MVCC requir= es this.

What's MVCC?

- Vacuum, isn't the speediest th=
ing in the world too (it's been running for a hour now, and still has not f=
inished).

Is this 7.2? If not, = VACUUM should be substantially faster in 7.2.
Yes, it is 7.2

In any case, you'll always= want to VACUUM or VACUUM FULL (and
ANALYZE) when you change your tables= in such a dramatic fashion.


I know... Once again, I was hoping to be able to complete my changes before doing the vacuum :-(

Thanks for your reply!

Dima