Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd

Поиск
Список
Период
Сортировка
От Andy Fan
Тема Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd
Дата
Msg-id CAKU4AWqo0nvtV7E99sS3hbufEJA7Wn1+Rz=oDgPrsxTYsipJoA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers

If the relation is open,
the relcache entry can't be destroyed altogether, but it can be
rebuilt: see RelationClearRelation().

Thanks! This is a new amazing knowledge for me!
 
They are in fact stable in a certain sense - if we have the relation open
we hold a reference count on it, and so the Relation pointer itself will 
remain valid.

This sounds amazing as well. 
 
But
the data it points to can change in various ways, and different
members of the RelationData struct are handled differently. Separately
from the reference count, the heavyweight lock that we also hold on
the relation as a condition of opening it prevents certain kinds of
changes, so that even if the relation cache entry is rebuilt, certain
particular fields will be unaffected. Which fields are protected in
this way will depend on what kind of lock is held. It's hard to speak
in general terms.

Amazing++; 
 
The best advice I can give you is (1) look exactly
what RelationClearRelation() is going to do to the fields you care
about if a rebuild happens, (2) err on the side of assuming that
things can change under you, and (3) try running your code under
debug_discard_caches = 1. It will be slow that way, but it's pretty
effective in finding places where you've made unsafe assumptions.


Thanks! I clearly understand what's wrong in my previous knowledge. 
That is, after a relation is open with some lock, then the content of the relation
will never change until the RelationClose.  It would take time to fill the
gap, but I'd like to say "thank you!" first. 

--
Best Regards
Andy Fan

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Justin Pryzby
Дата:
Сообщение: Re: GUC flags
Следующее
От: "houzj.fnst@fujitsu.com"
Дата:
Сообщение: RE: row filtering for logical replication