Unix Technical Forum

Questions on extending a relation

This is a discussion on Questions on extending a relation within the pgsql Hackers forums, part of the PostgreSQL category; --> Hi Hackers, Here I have two questions related to extending a relation: 1. When we want a new page, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:36 AM
Qingqing Zhou
 
Posts: n/a
Default Questions on extending a relation

Hi Hackers,

Here I have two questions related to extending a relation:

1. When we want a new page, we will do something like this:

LockPage(relation, 0, ExclusiveLock);
blockNum = smgrnblocks(reln->rd_smgr);
/* Try to locate this blockNum in buffer pool, but definitely can't? */
smgrextend(blockNum);
LockPage(relation, 0, ExclusiveLock);

So if I have concurrently 10 backends reach here, we will have 10 new pages?
Suppose they all insert one new tuple, commit, then quit. Next time when
they connected again, they only reuse the last page, so we almost lost 9
pages?

2. Suppose an insert on a relation with index is performed in this sequence:

begin transation;
extend relation for a new page A;
insert a heap tuple T on page A;
insert an index tuple I on another page B;
page B get written out by bgwriter;
System crashed.
System recovered.

At this time, page A is empty since we won't replay xlog. Now we insert a
heap tuple on page A again, which will use the same slot of the tuple T. So
now the index tuple I points to T?

Thanks a lot,
Qingqing



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:36 AM
Tom Lane
 
Posts: n/a
Default Re: Questions on extending a relation

"Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> 1. When we want a new page, we will do something like this:


> LockPage(relation, 0, ExclusiveLock);
> blockNum = smgrnblocks(reln->rd_smgr);
> /* Try to locate this blockNum in buffer pool, but definitely can't? */
> smgrextend(blockNum);
> LockPage(relation, 0, ExclusiveLock);


You should be using ReadBuffer with P_NEW, not calling smgr yourself.

> So if I have concurrently 10 backends reach here, we will have 10 new pages?


Yes. That's intentional --- otherwise they'd all block each other.

> 2. Suppose an insert on a relation with index is performed in this sequence:


> begin transation;
> extend relation for a new page A;
> insert a heap tuple T on page A;
> insert an index tuple I on another page B;
> page B get written out by bgwriter;
> System crashed.
> System recovered.


> At this time, page A is empty since we won't replay xlog.


Why wouldn't we replay xlog? Note in particular that the bgwriter is
not allowed to push page B to disk until the xlog entry describing the
index change has been flushed to disk. Since that will come after the
xlog entry about the heap change, both changes are necessarily on-disk
in the xlog, and both will be remade during replay.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 05:36 AM
Qingqing Zhou
 
Posts: n/a
Default Re: Questions on extending a relation


"Tom Lane" <tgl@sss.pgh.pa.us> writes
>
> Yes. That's intentional --- otherwise they'd all block each other.
>


So if I saw the last two pages on a disk relation are half full, that's
nothing wrong?

>
> Why wouldn't we replay xlog? Note in particular that the bgwriter is
> not allowed to push page B to disk until the xlog entry describing the
> index change has been flushed to disk. Since that will come after the
> xlog entry about the heap change, both changes are necessarily on-disk
> in the xlog, and both will be remade during replay.
>


Yes, I made a mistake. We reply xlog in any ways (no matter the transaction
commits or not).


Thanks,
Qingqing


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com