Re: user defined settings (aka user defined guc variables) - Mailing list pgsql-hackers

From Joe Conway
Subject Re: user defined settings (aka user defined guc variables)
Date
Msg-id 3E0128D0.40004@joeconway.com
Whole thread Raw
In response to Re: user defined settings (aka user defined guc variables)  (Gavin Sherry <swm@linuxworld.com.au>)
List pgsql-hackers
Gavin Sherry wrote:
> On Wed, 18 Dec 2002, Bruce Momjian wrote:
> 
> 
>>What exactly can you do with these variables other than SHOW/SET.  Seems
>>it would be nice if they could be used in queries, like in a special
>>table like sysvar:
>>
>>    SELECT sysvar.fsync;
> 
> 
> Isn't that just identical to having a table?

Well you can use it in a query:

regression=# select pg_create_user_setting('myvar',17,false); pg_create_user_setting
------------------------ 17
(1 row)

regression=# select typname from pg_type where oid = current_setting('myvar'); typname
--------- bytea
(1 row)

There are at least two differences to this approach vs a table:

1. Main reason is that if a user defined function/contrib module creates a 
table in my database I consider that too intrusive. I'd prefer not to have 
metadata tables in my database simply to support a loaded function.

2. It's faster. In some simple tests, I found that getting a setting value via 
current_setting('myvar') is about 40% faster than getting a value from a one 
row table, and about 100% faster than an indexed lookup in a larger table 
(after the table is cached, more than that on the first lookup).

Joe



pgsql-hackers by date:

Previous
From: Gavin Sherry
Date:
Subject: Re: user defined settings (aka user defined guc variables)
Next
From: "Christopher Kings-Lynne"
Date:
Subject: Fancy ADD COLUMN