Skip to content

Commit 38bf1f3

Browse files
nataraj-hates-MS-for-stealing-githubCommitfest Bot
authored andcommitted
Add ternary reloption type
There is a tendency for boolean reloptions in PostgreSQL code, one with "on" and "off" values, to be replaced with options with "on", "off", "[use_global_settings]" behaviour. For `vacuum_index_cleanup" and gist's `buffering` reloption such behavior have been implemented as enum-tyoe option. For vacuum_truncate this behaviour have been umplemented by adding additional `is_set` flag to `bytea` representation of the reloptions. Both solutions looks like workaround hacks to implement option with three available states. This patch introduce "ternary" reloption type, that behave like bool option, but also has an additional "unset" state. This state may be reachable only by not setting or RESETting an option, like in `vacuum_truncate` option, or it may have some text alias that allow user to explicitly set it, like "auto" in `vacuum_index_cleanup` or gist's `buffering` `vacuum_truncate`, `vacuum_index_cleanup` and gist's `buffering` reloptions are reimplemented as ternary reloptions without significant behaviour changes.
1 parent 0a8a4be commit 38bf1f3

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/test/regress/expected/reloptions.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
9898
{fillfactor=13,autovacuum_enabled=false}
9999
(1 row)
100100

101+
-- Tests for future (FIXME) ternary options
102+
-- behave as boolean option: accept unassigned name and truncated value
103+
DROP TABLE reloptions_test;
104+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate);
105+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
106+
reloptions
107+
------------------------
108+
{vacuum_truncate=true}
109+
(1 row)
110+
111+
DROP TABLE reloptions_test;
112+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS);
113+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
114+
reloptions
115+
------------------------
116+
{vacuum_truncate=fals}
117+
(1 row)
118+
119+
-- preferred "true" alias is used when storing
120+
DROP TABLE reloptions_test;
121+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on);
122+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
123+
reloptions
124+
---------------------------
125+
{vacuum_index_cleanup=on}
126+
(1 row)
127+
128+
-- custom "third" value is available
129+
DROP TABLE reloptions_test;
130+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=auto);
131+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
132+
reloptions
133+
-----------------------------
134+
{vacuum_index_cleanup=auto}
135+
(1 row)
136+
101137
-- Test vacuum_truncate option
102138
DROP TABLE reloptions_test;
103139
CREATE TEMP TABLE reloptions_test(i INT NOT NULL, j text)

src/test/regress/sql/reloptions.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ UPDATE pg_class
5959
ALTER TABLE reloptions_test RESET (illegal_option);
6060
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
6161

62+
-- Tests for future (FIXME) ternary options
63+
64+
-- behave as boolean option: accept unassigned name and truncated value
65+
DROP TABLE reloptions_test;
66+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate);
67+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
68+
69+
DROP TABLE reloptions_test;
70+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS);
71+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
72+
73+
-- preferred "true" alias is used when storing
74+
DROP TABLE reloptions_test;
75+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on);
76+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
77+
78+
-- custom "third" value is available
79+
DROP TABLE reloptions_test;
80+
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=auto);
81+
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
82+
6283
-- Test vacuum_truncate option
6384
DROP TABLE reloptions_test;
6485

0 commit comments

Comments
 (0)