Repository navigation
一時テーブルと MaterializePlan を入れる - #33
Merged
Merged
Conversation
…and read it back from ソートやグループ化が入力を一度書き出して読み直すための一時テーブル。 名前は字句解析器が識別子にしない '#' で始め、ユーザーのテーブルと衝突しないようにする。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…database is opened 一時テーブルはクエリの間しか使わないため、起動時に残っているものは停止前に消せなかった残骸。 接頭辞を file_manager に置き、materialize からも同じ定義を参照する。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng them from there ソートやグループ化が入力を何度も読み直すとき、元のプランを毎回計算し直さずに済むようにする。 コストは一時テーブルを読む分だけとし、書き出しは Open 時の一度きりなので含めない。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
ソート・グループ化・マージ結合(materialization)の土台として、演算子が入力を書き出して読み直すための一時テーブルと、プランの行を一時テーブルに書き出して読む
MaterializePlanを追加した。SimpleDB のTempTable/MaterializePlanに相当する。この PR ではまだ planner からは使わない。ソート(
SortPlan)、グループ化(GroupByPlan)、マージ結合(MergeJoinPlan)を次以降の PR で、この上に作る。materialize(新しいパッケージ)TempTable:カタログに載らない一時テーブル。他のテーブルと重ならない名前を付け、Openでquery.UpdateScanを返すfile_managerTempFilePrefix:一時テーブルのファイル名の接頭辞(#temp)NewFileManager:起動時に、この接頭辞で始まるファイルを消すplanMaterializePlan:Openで下のプランを最後まで読んで一時テーブルに写し、一時テーブルのスキャンを返す設計上の判断
#temp+ 連番。 SimpleDB はtemp+ 連番で、起動時にtempで始まるファイルを消すが、それだとユーザーが作ったtemp_xのようなテーブルも消える。_は識別子の先頭に使えるので、_tempでも同じことが起きる。#は字句解析器が識別子の一部にしないので、SQL からこの名前のテーブルは作れず、ユーザーのテーブルと重ならない。file_managerに置く。 起動時に消すのはFileManagerで、file_managerはmaterializeを import できない(循環する)ため。materializeはこの定数を参照する。atomic.Int64)。 一時テーブルはすべて同じディレクトリに置くため。MaterializePlan.BlocksAccessedは一時テーブルを読むブロック数だけ(SimpleDB と同じ)。 書き出しはOpenの 1 回だけで、BlocksAccessedは上の演算子が何度も読み直すときのコストを表すため。他の数値は下のプランのものを返す。Openは下のプランを読み終えたら閉じる。 返すスキャンは一時テーブルだけを持つ。途中で失敗したら、開いたスキャンを閉じてからエラーを返す。既知の制限
MaterializePlanはまだどの planner からも使われない。テスト
TempTable:2 つ作ると名前が違うこと、名前が SQL でテーブル名として書けないこと(select id from <名前>がパースエラーになる)、作ったときのスキーマのレイアウトを持つこと、書いた行を別のスキャンで読み戻せること_tempにして落ちることを確かめたNewFileManager/IsNew:一時ファイルを消して他のファイルを残すこと、一時ファイルしかないディレクトリを新しい DB と報告することMaterializePlan:Openで全行を id と name とも読めること、開いた後に元のテーブルを全件消しても読めること(一時テーブルに写していることの確認)、BlocksAccessed(0 行・1 ブロックちょうど・1 行あふれる場合)、RecordsOutput/DistinctValues/SchemaBlocksAccessedの 0 行のケースはスタブでも通っていたので、Green の後に式をrecords/rpb + 1に壊して落ちることを確かめた🤖 Generated with Claude Code