<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015年8月11日 20:42 Kouhei Sutou <span dir="ltr"><<a href="mailto:kou****@clear*****" target="_blank">kou****@clear*****</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">須藤です。<br>
<br>
In <CAN-DUMTjMec-WM9Fmo4k7f=<a href="mailto:o45udj1FLk9FNqOH6oByCBJ%2B4Yw****@mail*****" target="_blank">o45ud****@mail*****</a>><br>
"[groonga-dev,03397] PostgreSQLとgroongaのレコードの紐付けにctidを使うのは大丈夫なのでしょうか?" on Tue, 11 Aug 2015 11:41:54 +0900,<br>
<span> Hiroaki Nakamura <<a href="mailto:hnaka****@gmail*****" target="_blank">hnaka****@gmail*****</a>> wrote:<br></span></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> この説明を読む限り、ctidをgroongaのテーブルに保存しておいてPostgreSQL<br>
> のレコードとの紐付けに<br>
> 使うのは良くないような気がします。<br>
<br>
</span>このドキュメントを読むとそう思いますよねぇ。<br>
<br>
ですが、これで大丈夫なんです。<br>
これはSQLで使う場合の話で、拡張機能としてインデックスを実装<br>
する場合はそんなことはないんです。<br>
<br>
というか、インデックスはctidを返すことを求められるので、ctid<br>
を保存しておかないと適切な結果を返すことはできません。<br></blockquote><div><br></div><div>なるほど、そうなんですか。</div><div><br></div><div>確かに</div><div><a href="http://www.postgresql.org/docs/current/static/index-functions.html" target="_blank">http://www.postgresql.org/docs/current/static/index-functions.html</a><br></div><div>を見るとamgettupleやamgetbitmapのところにtuple IDを返すような記述がありますね。</div><div><br></div><div>PGroongaのコードだとこの辺りでctidを返しているんですね。</div><div><a href="https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2425" target="_blank">https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2425</a><br></div><div><a href="https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2455" target="_blank">https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2455</a><br></div><div><a href="https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2468" target="_blank">https://github.com/pgroonga/pgroonga/blob/4658a7b26eb2db17f655c4c805902a94c12651d2/pgroonga.c#L2468</a><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">VACUUM FULLしたときも大丈夫なのかは試さないとわからないんで<br>
すが、GINもctidを格納しているように見えるので大丈夫じゃない<br>
かなぁと思っています。<br>
<br>
念のため試してみるか!という気持ちになったら結果を教えてもら<br>
えるとうれしいです。<br></blockquote><div><br><a href="https://github.com/pgroonga/pgroonga/blob/6d3600c12c5abda068facebacc44751eecd48eb9/README.md" target="_blank">https://github.com/pgroonga/pgroonga/blob/6d3600c12c5abda068facebacc44751eecd48eb9/README.md</a><br></div><div>memosのテーブルでinsertしたあと一部のレコードをdeleteして再度insertした状態でvacuum fullを試してみました。</div><div><br></div><div><a href="https://github.com/hnakamur/pgroonga/commit/c3c133e40773062de47600b581bd848435cf6732" target="_blank">https://github.com/hnakamur/pgroonga/commit/c3c133e40773062de47600b581bd848435cf6732</a><br></div><div>で自作したpgroonga.ctid()という関数で</div><div>select id, pgroonga.ctid(memos) from memos;<br>で確認するとctidはvacuum full前後で変更され、とびとびの番号だったのが1からの連番になっていました。</div><div><br></div><div>一方</div><div>select pgroonga.table_name('pgroonga_content_index');<br></div><div>を実行するとGroongaのテーブル名も変更されていました。</div><div>select oid from pg_catalog.pg_database where datname = 'データベース名';<br>でDBのoidを調べ、</div><div>groonga ${PostgreSQLのDBディレクトリ}/base/${DBのoid}/pgrn</div><div>でGroongaのDBを開いて<br>select Groongaのテーブル名 --output_columns _id,ctid<br></div></div><div>で確認すると、</div><div class="gmail_extra">select id, pgroonga.ctid(memos) from memos;<br>で確認したctidと対応はとれているようでした。</div><div class="gmail_extra"><br></div><div class="gmail_extra">またPostgreSQL側のテーブルをtruncateしたときも</div><div class="gmail_extra"><div>select pgroonga.table_name('pgroonga_content_index');<br></div><div>で確認するとGroongaのテーブル名は変更されていました。</div></div><div class="gmail_extra"><br></div><div class="gmail_extra">ということで、現状の実装としてはvacuum fullやtruncateすると</div><div class="gmail_extra">Groongaのテーブルは新しく作りなおされ、ctidの対応はとれているようです。</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">ctidで紐付けするので実装上は問題無いとのことで安心しました。</div><div class="gmail_extra">解説ありがとうございました。</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">本題と外れるのですが、元記事は新規スレッドで投稿するつもりだったのですが、</div><div class="gmail_extra">gmail上での宛先コピペ操作ミスなのか、無関係の別スレッドに繋げてしまってすみませんでした。</div><div class="gmail_extra"><br></div><div class="gmail_extra">-- </div><div class="gmail_extra">中村 弘輝 )Hiroaki Nakamura)</div>
</div></div>