Re: Faster "SET search_path"
От | Jeff Davis |
---|---|
Тема | Re: Faster "SET search_path" |
Дата | |
Msg-id | fec7f3bea50112323d9b6e700b5e2762a14af809.camel@j-davis.com обсуждение исходный текст |
Ответ на | Re: Faster "SET search_path" (Isaac Morland <isaac.morland@gmail.com>) |
Ответы |
Re: Faster "SET search_path"
|
Список | pgsql-hackers |
On Wed, 2023-08-02 at 01:14 -0400, Isaac Morland wrote: > > > On Sat, 2023-07-29 at 12:44 -0400, Isaac Morland wrote: > > > > Essentially, "just" observe efficiently (somehow) that no > > > > change is > > > > needed, and skip changing it? ... > Speaking as someone who uses a lot of stored procedures, many of > which call one another, I definitely want this optimization. If we try to avoid the set_config_option() entirely, we'd have to introduce the invalidation logic into fmgr.c somehow, and there would be a performance cliff for users who change their session's search_path. Instead, in v4 (attached) I introduced a fast path (patch 0004, experimental) for setting search_path that uses the same low-level invalidation logic in namespace.c, but avoids most of the overhead of set_config_option(). (Aside: part of the reason set_config_option() is slow is because of the lookup in guc_hashtab. That's slower than some other hash lookups because it does case-folding, which needs to be done in both the hash function and also the match function. The hash lookups in SearchPathCache are significantly faster. I also have a patch to change guc_hashtab to simplehash, but I didn't see much difference.) New timings (with session's search_path set to a, b): inc() plain function: 4.1s inc_secdef() SECURITY DEFINER: 4.3s inc_wm() SET work_mem = '4GB': 6.3s inc_ab() SET search_path = a, b: 5.4s inc_bc() SET search_path = b, c: 5.6s I reported the numbers a bit differently here. All numbers are using v4 of the patch. The plain function is a baseline; SECURITY DEFINER is for measuring the overhead of the fmgr_security_definer wrapper; inc_ab() is for setting the search_path to the same value it's already set to; and inc_bc() is for setting the search_path to a new value. There's still a difference between inc() (with no proconfigs) and inc_ab(), so you can certainly argue that some or all of that can be avoided if the search_path is unchanged. For instance, adding the new GUC level causes AtEOXact_GUC to be run, and that does some work. Maybe it's even possible to avoid the fmgr_security_definer wrapper entirely (though it would be tricky to do so). But in general I'd prefer to optimize cases that are going to work nicely by default for a lot of users (especially switching to a safe search path), without the need for obscure knowledge about the performance implications of the session search_path. And to the extent that we do optimize for the pre-existing search_path, I'd like to understand the inherent overhead of changing the search path versus incidental overhead. -- Jeff Davis PostgreSQL Contributor Team - AWS
Вложения
В списке pgsql-hackers по дате отправления: