zoukankan      html  css  js  c++  java
  • PostgreSQL在何处处理 sql查询之二十

    看代码:

    /*
     *    mdopen() -- Open the specified relation.
     *
     * Note we only open the first segment, when there are multiple segments.
     *
     * If first segment is not present, either ereport or return NULL according
     * to "behavior".  We treat EXTENSION_CREATE the same as EXTENSION_FAIL;
     * EXTENSION_CREATE means it's OK to extend an existing relation, not to
     * invent one out of whole cloth.
     */
    static MdfdVec *
    mdopen(SMgrRelation reln, ForkNumber forknum, ExtensionBehavior behavior)
    {
        MdfdVec    *mdfd;
        char       *path;
        File        fd;
    
        /* No work if already open */
        if (reln->md_fd[forknum])
            return reln->md_fd[forknum];
    
        path = relpath(reln->smgr_rnode, forknum);
    
        fd = PathNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
    
        if (fd < 0)
        {
            /*
             * During bootstrap, there are cases where a system relation will be
             * accessed (by internal backend processes) before the bootstrap
             * script nominally creates it.  Therefore, accept mdopen() as a
             * substitute for mdcreate() in bootstrap mode only. (See mdcreate)
             */
            if (IsBootstrapProcessingMode())
                fd = PathNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 
    0600);
    if (fd < 0) { if (behavior == EXTENSION_RETURN_NULL && FILE_POSSIBLY_DELETED(errno)) { pfree(path); return NULL; } ereport(ERROR, (errcode_for_file_access(), errmsg("could not open file \"%s\": %m", path))); } } pfree(path); reln->md_fd[forknum] = mdfd = _fdvec_alloc(); mdfd->mdfd_vfd = fd; mdfd->mdfd_segno = 0; mdfd->mdfd_chain = NULL; Assert(_mdnblocks(reln, forknum, mdfd) <= ((BlockNumber) RELSEG_SIZE)); return mdfd; }

    看这一段:

        /* No work if already open */
        if (reln->md_fd[forknum])
            return reln->md_fd[forknum];

    可以知道,如果文件已经打开过,就不需要再次调用  PathNameOpenFile 了。

    不过,这应该是限定于一个特定的  SMgrRelation 对象而言。

  • 相关阅读:
    突然想到一个问题:有关 cqrs 分离
    Oracle 12C 数据库安装与配置
    Android 绑定服务的作用 (参考,不确定他说的是不是对的)
    SSM框架整合(一)
    常见数据库优化方案(九)
    大量文件存储
    MyBatis 参数传递小知识(划重点)|划掉 MyBatis 常见小debug
    MyBatis 自动代码生成器
    常见数据库优化方案(八)
    常用数据库优化方案(五)
  • 原文地址:https://www.cnblogs.com/gaojian/p/3102067.html
Copyright © 2011-2022 走看看