Re: How to accurately determine when a relation should use local buffers? - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Re: How to accurately determine when a relation should use local buffers?
Date
Msg-id CAJ7c6TOVSupn0tvLzwxCUfjPqPUy8L0L4xKAws62r8rQiMVrHA@mail.gmail.com
Whole thread Raw
In response to Re: How to accurately determine when a relation should use local buffers?  (Vitaly Davydov <vitprof@gmail.com>)
Responses Re: How to accurately determine when a relation should use local buffers?
List pgsql-hackers
Hi,

> Furthermore, there is some possible inconsistency in the code show below (REL_16_STABLE) in bufmgr.c file:
>
> FlushRelationBuffers, PrefetchBuffer uses RelationUsesLocalBuffers(rel).
> ExtendBufferedRel_common finally use BufferManagerRelation.relpersistence which is actually rd_rel->relpersistence,
workslike RelationUsesLocalBuffers. 
> ReadBuffer_common uses isLocalBuf = SmgrIsTemp(smgr), that checks rlocator.backend for InvalidBackendId.

I didn't do a deep investigation of the code in this particular aspect
but that could be a fair point. Would you like to propose a
refactoring that unifies the way we check if the relation is
temporary?

> I would like to clarify, do we completely refuse the use of temporary tables in other contexts than in backends or
thereis some work-in-progress to allow some other usage contexts? If so, the check of rd_rel->relpersistence is enough.
Notsure why we use SmgrIsTemp instead of RelationUsesLocalBuffers in ReadBuffer_common. 

According to the comments in relfilelocator.h:

```
/*
 * Augmenting a relfilelocator with the backend ID provides all the information
 * we need to locate the physical storage.  The backend ID is InvalidBackendId
 * for regular relations (those accessible to more than one backend), or the
 * owning backend's ID for backend-local relations.  Backend-local relations
 * are always transient and removed in case of a database crash; they are
 * never WAL-logged or fsync'd.
 */
typedef struct RelFileLocatorBackend
{
    RelFileLocator locator;
    BackendId    backend;
} RelFileLocatorBackend;

#define RelFileLocatorBackendIsTemp(rlocator) \
    ((rlocator).backend != InvalidBackendId)
```

And this is what ReadBuffer_common() and other callers of SmgrIsTemp()
are using. So no, you can't have a temporary table without an assigned
RelFileLocatorBackend.backend.

It is my understanding that SmgrIsTemp() and
RelationUsesLocalBuffers() are equivalent except the fact that the
first macro works with SMgrRelation objects and the second one - with
Relation objects.

--
Best regards,
Aleksander Alekseev



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Annoying build warnings from latest Apple toolchain
Next
From: Eric Ridge
Date:
Subject: Re: Hide exposed impl detail of wchar.c