[code notes] storage of a temporary table

One sentence summary

A temporary table could reside within a temporary tablespace, utilizing a temporary name in a temporary schema or namespace.

More

create

  • 在一个会话第一次执行 create temp table 命令时,内核会执行 InitTempTableNamespace, 创建
    临时 schema/namespace.
    image

    临时 namespace 的命名为 pg_temp_<MyBackendId>, 如 pg_temp_4.

  • 可以通过 temp_tablespaces GUC 参数配置临时表存放在哪个表空间,默认 pg_default
    code path

    DefineRelation
    GetDefaultTablespace
      PrepareTempTablespaces -- step over
      GetNextTempTableSpace
    

    image

  • 临时表对应的物理文件的名字通过函数 GetNewRelFileNode 获得, 命名格式为 t<MyBackendId>_<oid>. 最终通过 RelationCreateStorage 创建对应从存储,目前内核唯一支持的存储为磁盘文件。可以通过 SQL 函数 pg_relation_filepath 查看存储路径。

drop

when does temp table get dropped?
image

posted on 2024-06-28 16:39  winter-loo  阅读(5)  评论(0编辑  收藏  举报

导航