[pgsql-jp: 26130] Re: コンカレントバキュームについて

Jun Kitamura kitamura @ zoozee.jp
2002年 5月 25日 (土) 01:31:03 JST


北村@zoozee です。

> 石井です.
> 
> > というのも、5レコードくらいで試したところ、begin-commit で囲まれた 1行1行
> > の update では、xmax の値が変化していたためです(その他 xmin,cmax,cmin も
> 
> 本当ですか? xminが変化するならわかりますが.
> 
> 再現テストをしたいので,具体的なSQL文を教えてもらえますか?

ごめんなさい。xmax,xmin,cmax,cmin の意味を知らずに値が変化することだけに
注目していたので、とんだ誤解を・・。
xmax が変化するのは、for update した直後です。
その後、1行1行 update をすると、xmax の値が xmin に移っていくだけでした。
でもって、for update をせずに 1行1行 update すると、結局 xmin には同じ値
が入りました。つまり、杉田さんからご教示いただいた

> ;;; 22億ループを begin,commit で囲んでも、「22億(+1)トランザクション」ですよ
> ;;; ね?(+1)は begin,commit分です。
> 
>   begin〜commit で 1 です。

のとおりである、ということです。

私が知りたかったのは、1回のトランザクションで更新可能なレコード数の上限だっ
たのです。begin-commit 中の update は暗黙のトランザクションがネストされて
いると思っていたので、トランザクション IDの食いつくしが発生してしまうので
は、と思ったのです(つまり上限は (2^31)-1 レコードだと思っていた)。


以下、実行結果(全然意味の無いものですみません)
test=# \d t1
          Table "t1"
 Column |   Type   | Modifiers
--------+----------+-----------
 a      | smallint | not null
 b      | smallint |
Primary key: t1_pkey

test=# insert into t1 values (1,1);
INSERT 475440 1
test=# insert into t1 values (2,2);
INSERT 475441 1
test=# insert into t1 values (3,3);
INSERT 475442 1
test=# insert into t1 values (4,4);
INSERT 475443 1
test=# insert into t1 values (5,5);
INSERT 475444 1
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a | b
------+------+------+------+---+---
    0 | 5246 |    0 |    0 | 1 | 1
    0 | 5247 |    0 |    0 | 2 | 2
    0 | 5248 |    0 |    0 | 3 | 3
    0 | 5249 |    0 |    0 | 4 | 4
    0 | 5250 |    0 |    0 | 5 | 5
(5 rows)

test=# begin;
BEGIN
test=# select * from t1 for update;
 a | b
---+---
 1 | 1
 2 | 2
 3 | 3
 4 | 4
 5 | 5
(5 rows)

test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a | b
------+------+------+------+---+---
 5252 | 5246 |    1 |    0 | 1 | 1
 5252 | 5247 |    1 |    0 | 2 | 2
 5252 | 5248 |    1 |    0 | 3 | 3
 5252 | 5249 |    1 |    0 | 4 | 4
 5252 | 5250 |    1 |    0 | 5 | 5
(5 rows)

test=# update t1 set b = 10 where a = 1;
UPDATE 1
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a | b
------+------+------+------+---+----
 5252 | 5247 |    1 |    0 | 2 |  2
 5252 | 5248 |    1 |    0 | 3 |  3
 5252 | 5249 |    1 |    0 | 4 |  4
 5252 | 5250 |    1 |    0 | 5 |  5
    0 | 5252 |    0 |    5 | 1 | 10
(5 rows)

test=# update t1 set b = 20 where a = 2;
UPDATE 1
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a | b
------+------+------+------+---+----
 5252 | 5248 |    1 |    0 | 3 |  3
 5252 | 5249 |    1 |    0 | 4 |  4
 5252 | 5250 |    1 |    0 | 5 |  5
    0 | 5252 |    0 |    5 | 1 | 10
    0 | 5252 |    0 |    9 | 2 | 20
(5 rows)

test=# commit;
COMMIT
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a | b
------+------+------+------+---+----
 5252 | 5248 |    1 |    0 | 3 |  3
 5252 | 5249 |    1 |    0 | 4 |  4
 5252 | 5250 |    1 |    0 | 5 |  5
    0 | 5252 |    0 |    5 | 1 | 10
    0 | 5252 |    0 |    9 | 2 | 20
(5 rows)

test=# update t1 set b = 100;
UPDATE 5
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a |  b
------+------+------+------+---+-----
    0 | 5254 |    0 |    0 | 3 | 100
    0 | 5254 |    0 |    0 | 4 | 100
    0 | 5254 |    0 |    0 | 5 | 100
    0 | 5254 |    0 |    0 | 1 | 100
    0 | 5254 |    0 |    0 | 2 | 100
(5 rows)

test=# vacuum freeze;
VACUUM
test=# select xmax,xmin,cmax,cmin,* from t1;
 xmax | xmin | cmax | cmin | a |  b
------+------+------+------+---+-----
    0 |    2 |    0 |    0 | 3 | 100
    0 |    2 |    0 |    0 | 4 | 100
    0 |    2 |    0 |    0 | 5 | 100
    0 |    2 |    0 |    0 | 1 | 100
    0 |    2 |    0 |    0 | 2 | 100
(5 rows)




pgsql-jp メーリングリストの案内